Exporting to an existing spreadsheet in excel

Asked By John Baldwin
27-Aug-10 09:25 AM
Earn up to 0 extra points for answering this tough question.
A new question for exporting to excel.

I am successfully able to export data from an sql table to excel by creating a new spreadsheet when executed. Is there any method by which I can export the data to an EXISTING spreadsheet with the same columns etc? So far I have not been able to figure it out.

Thanks

  re: Exporting to an existing spreadsheet in excel

Cika Pero replied to John Baldwin
02-Sep-10 04:41 AM
Hi,

you can do it easily with this Excel .NET component.

Here is an Excel C# sample code that exports DataTable to Excel with just one method call:
var ef = new ExcelFile();
ef.LoadXls("DataTable.xls");
 
// Find worksheet with same name as DataTable.
var ws = ef.Worksheets[dataTable.TableName];
 
// Append the data from DataTable to worksheet.
ws.InsertDataTable(dataTable, ws.GetUsedCellRange().Height, 0, false);
 
ef.SaveXls("DataTable.xls");
Create New Account