0

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);
SuYeon Choi
  • 67
  • 1
  • 8
  • Possible duplicate of [HRESULT: 0x800A03EC on Worksheet.range](https://stackoverflow.com/questions/7099770/hresult-0x800a03ec-on-worksheet-range) – TheGeneral Apr 06 '18 at 00:53

1 Answers1

0

I had the problem when the Workbook was 'Protected'

Workbook wb = excel.Workbooks.Open(fileFullPath);
wb.Unprotect("xxx");

All I did was unprotect it and the error went away

glenn garson
  • 416
  • 4
  • 7