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
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
darma tejaPosted Apr 3, 2013, 3:24 PM
Imtiyaz AnsariPosted Apr 3, 2013, 2:42 PM
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........