Click here to Skip to main content
12,751,848 members (27,435 online)

Excel Sheet save automatically when storing our datas listview to excel

vasanthkumarmk asked:

Open original thread
I am using windows Forms using C# Language,

I have listview, it contains some items when i click the save button the listview items will saves to Excel File. Below is my code of save listview details to Excel.
Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
            xla.Visible = true;
            Microsoft.Office.Interop.Excel.Workbook wb = xla.Workbooks.Add(Microsoft.Office.Interop.Excel.XlSheetType.xlWorksheet);
            Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)xla.ActiveSheet;

            int i = 1;
            int j = 1;
            foreach (ListViewItem comp in listView_playlist.Items)
                ws.Cells[i, j] = comp.Text.ToString();         

                foreach (ListViewItem.ListViewSubItem drv in comp.SubItems)
                    ws.Cells[i, j] = drv.Text.ToString();
                j = 1;

My problem :
Here what my problem is, When i Click the Save button the listview details comes on the Excel page, The Excel page is open stage. I need to click save button in the excel page. Then only it will saved.

But I need to save default when i click the Save button. Just we need to enter the file name of save file dialogue box, it will save our local host. without visible the Excel sheet. How can i do this.

Tags: C# (C#3.0, C#4.0)


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100