ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Add sheet to workbook (https://www.excelbanter.com/excel-programming/376354-add-sheet-workbook.html)

dorte

Add sheet to workbook
 
Hi,

In a .net console application in C#, I need to create excel files, workbooks
and add sheets to the workbook.
I have added a reference to Microsoft Excel 10.0 object library.

But I get a COM exception when I try to add a sheet to the workbook. Here is
my code:

Excel.Application ExcelApp = new Application();

// bug work around, due to local settings different than English version of
Excel
System.Threading.Thread.CurrentThread.CurrentCultu re = new
System.Globalization.CultureInfo("en-US");

Excel.Workbook book1 = ExcelApp.Workbooks.Add(XlWBATemplate.xlWBATWorkshe et);
book1.Sheets.Add(null, book1.Sheets[1], 1, XlSheetType.xlWorksheet);

The last line of code generates the following error:
Exception from HRESULT: 0x800A03EC
error code:-2146827284

Could anyone tell me how I can add sheets to the workbook without getting an
error?

Thanks,
Dorte



All times are GMT +1. The time now is 02:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com