I tried to write large data in Excel using c#.(rowcount is less than 65530)
And I use 64bit computer and microsoft office 2007.
When I use 32bit computer and microsoft office 2007, it wasn't problem.
But After I changed the computer, i have a error that is HRESULT: 0x800A03EC.
I tried to debug and found the problem that is
xlWorksheet.get_Range("A2", columns[dt.Columns.Count - 1] +
(dt.Rows.Count + 1).ToString()).Value = data;
How can I solve this problem?
This is my code..
try
{
xlApp = new Application();
xlWorkbook = xlApp.Workbooks.Add(true);
xlWorksheet = xlWorkbook.ActiveSheet;
xlApp.Visible = false;
xlApp.UserControl = false;
String[] headers = new String[dt.Columns.Count];
String[] columns = new String[dt.Columns.Count];
String[,] data = new String[dt.Rows.Count, dt.Columns.Count];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Columns.Count; i++)
{
headers[i] = dt.Columns[i].ColumnName;
columns[i] = ExcelColumnIndexToName(i);
}
for (int rowIndex = 0; rowIndex < dt.Rows.Count; rowIndex++)
{
for (int colIndex = 0; colIndex < dt.Columns.Count; colIndex++)
{
data[rowIndex, colIndex] = dt.Rows[rowIndex][colIndex].ToString();
}
}
}
xlWorksheet.Cells.NumberFormat = @"@";
xlWorksheet.Columns.ColumnWidth = 10;
xlWorksheet.Rows.RowHeight = 15;
xlWorksheet.get_Range("A1", columns[dt.Columns.Count - 1] + "1").Value2 = headers;
xlWorksheet.get_Range("A2", columns[dt.Columns.Count - 1] + (dt.Rows.Count + 1).ToString()).Value = data;
xlWorkbook.SaveAs(fileName);