I wanted to export data to excel.
here is the code that i wrote:
Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
Workbook vb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
var Worksheet = (Worksheet)xla.Worksheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
foreach (logic)
{
//logic to get data
// I put data to excel cells
example: Worksheet.Cells[i + 1, 1] = bla bla;
}
//logic to get data
// I put data to excel cells
example: Worksheet.Cells[i + 1, 1] = bla bla;
}
Worksheet ws = (Worksheet)xla.ActiveSheet;
ws.SaveAs(@"c:\Documents and Settings\Desktop\output1.xls");
Now my problem is: I dont want to save xls file in last step.
I want to save data in excel file in every loop. It means that If any exception comes at least I have data of the passed loops.
Many thanks,
Darma
Now my problem is: I dont want to save xls file in last step.
I want to save data in excel file in every loop. It means that If any exception comes at least I have data of the passed loops.
Many thanks,
Darma

Imtiyaz AnsariRank #1,031 · 1.9K reputationPosted Apr 3, 2013, 10:42 AM EDT
firstly folling refarence add
Microsoft.Office.Interop.Excel
Microsoft.Office.Interop.Word
this code are used gridview data create excel file
try
please Accept the Answer if slove youer problam........
darma tejaRank #3,199 · 449 reputationPosted Apr 3, 2013, 11:24 AM EDT