B
Bryson
Hi,
I'm using Microsoft Excel 11.0 Object Library and repeatedly getting the
error listed in the title. I have gotten excel exports to work with other
(less complex) projects in the past using the 11.0 library. I don't know
what to do about the problem. My goal is to export to excel a selected list
of tables, with each table occupying a seperate tab in excel. I hope someone
can help. Code below.
private void excel_write(int [] TableList)
{
statusBar1.Text="Writing to Excel";
statusBar1.Show();
ApplicationClass excel = new ApplicationClass();
excel.Application.Workbooks.Add(true);
Worksheet wk;
int columnIndex=0;
int rowIndex=0;
try
{
for (int i=0;i<TableList.Length;i++)
{
int j = TableList;
wk = new WorksheetClass();
columnIndex=0;
rowIndex=0;
foreach (DataColumn dc in dataSet1.Tables[j].Columns)
{
columnIndex++;
excel.Cells[1,columnIndex]=dc.ColumnName;
}
foreach (DataRow dr in dataSet1.Tables[j].Rows)
{
rowIndex++;
for
(columnIndex=0;columnIndex<dataSet1.Tables[j].Columns.Count;columnIndex++)
{
excel.Cells[rowIndex+1,columnIndex]=dr.ItemArray.GetValue(columnIndex);
}
}
excel.Application.Workbooks.Add(wk);
GC.Collect();
}
excel.Visible=true;
Worksheet worksheet = (Worksheet)excel.ActiveSheet;
worksheet.Activate();
}
catch (Exception ex)
{MessageBox.Show(ex.Message);}
I'm using Microsoft Excel 11.0 Object Library and repeatedly getting the
error listed in the title. I have gotten excel exports to work with other
(less complex) projects in the past using the 11.0 library. I don't know
what to do about the problem. My goal is to export to excel a selected list
of tables, with each table occupying a seperate tab in excel. I hope someone
can help. Code below.
private void excel_write(int [] TableList)
{
statusBar1.Text="Writing to Excel";
statusBar1.Show();
ApplicationClass excel = new ApplicationClass();
excel.Application.Workbooks.Add(true);
Worksheet wk;
int columnIndex=0;
int rowIndex=0;
try
{
for (int i=0;i<TableList.Length;i++)
{
int j = TableList;
wk = new WorksheetClass();
columnIndex=0;
rowIndex=0;
foreach (DataColumn dc in dataSet1.Tables[j].Columns)
{
columnIndex++;
excel.Cells[1,columnIndex]=dc.ColumnName;
}
foreach (DataRow dr in dataSet1.Tables[j].Rows)
{
rowIndex++;
for
(columnIndex=0;columnIndex<dataSet1.Tables[j].Columns.Count;columnIndex++)
{
excel.Cells[rowIndex+1,columnIndex]=dr.ItemArray.GetValue(columnIndex);
}
}
excel.Application.Workbooks.Add(wk);
GC.Collect();
}
excel.Visible=true;
Worksheet worksheet = (Worksheet)excel.ActiveSheet;
worksheet.Activate();
}
catch (Exception ex)
{MessageBox.Show(ex.Message);}