views:

176

answers:

2

hi

How to run over DataSet and insert into Excel (not .csv file) ?

i work on C#, Visual-studio 2008, Excel 2007

thank's in advance

+1  A: 

Here is a useful article: Reading and Writing Excel Spreadsheets Using ADO.NET C# DbProviderFactory

Giorgi
+2  A: 

You need to look into the Office Interop Libraries, see this example take from here.

Microsoft.Office.Interop.Excel.Application xl = 
    new Microsoft.Office.Interop.Excel.Application();

xla.Visible = true;
Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;
int i = 1;
int j = 1;
foreach (ListViewItem comp in lvwResults.Items)
{
    ws.Cells[i, j] = comp.Text.ToString();
    //MessageBox.Show(comp.Text.ToString());
    foreach (ListViewItem.ListViewSubItem drv in comp.SubItems)
    {
        ws.Cells[i, j] = drv.Text.ToString();
        j++;
    }
    j = ;1;
    i++;
}

This of course requrires that you have Excel installed on the machine running the program.

Filip Ekberg
excellent !!!, but how to save this excell that i made ? (automatic using the C# code)
Gold
Check MSDN, there's a lot of information about using the interop api.
Filip Ekberg