Hi all,
Just Install O2003PIA and
after installing o2003PIA browse and add this dll as reference
Microsoft.Office.Interop.Excel.dll
add these namespaces
using Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Diagnostics;
and code
oleda1.Fill(ds);
Microsoft.Office.Interop.Excel.Application oAppln;
Microsoft.Office.Interop.Excel.Workbook oWorkBook;
Microsoft.Office.Interop.Excel.Worksheet oWorkSheet;
oAppln = new Microsoft.Office.Interop.Excel.Application();
oWorkBook = (Microsoft.Office.Interop.Excel.Workbook)(oAppln.Workbooks.Add(true));
int i2 = 0;
foreach (DataTable table in ds.Tables)
{
oWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)(oWorkBook.Worksheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing));
if (i2 == 0)
{
oWorkSheet.Name = "first";
}
else
{
oWorkSheet.Name = "second";
}
oWorkSheet.Activate();
int ColumnIndex = 0;
foreach (DataColumn col in table.Columns)
{
ColumnIndex++;
oWorkSheet.Cells[1, ColumnIndex] = col.ColumnName;
}
int rowIndex = 0;
foreach (DataRow row in table.Rows)
{
rowIndex++;
ColumnIndex = 0;
foreach (DataColumn col in table.Columns)
{
ColumnIndex++;
oWorkSheet.Cells[rowIndex + 1, ColumnIndex] = row[col.ColumnName].ToString();
}
}
i2++;
}
if u get ContextSwitchDeadlock warning message
Just click ctrl+alt+E in your project and select Managed Debugging assistance..
in that uncheck ContextSwitchDeadlock n OK
http://www.rocha.org/2010/05/contextswitchdeadlock-was-detected.html[
^]
its working thanks for all your help.....