Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Excel XP Interop: How to add worksheet to a workbook using c#???

0 views
Skip to first unread message

katzky

unread,
Apr 7, 2006, 4:28:02 PM4/7/06
to
I am trying to add a worksheet to a workbook. The following code produces an
error at the last line:

Excel.Application theApp = new Excel.ApplicationClass();
Excel.Workbook theBook = theApp.Workbooks.Add
Excel.XlWBATemplate.xlWBATWorksheet);

Excel.Worksheet theSheet= (Excel.Worksheet) theBook.Worksheets[1];

theSheet= (Excel.Worksheet) theBook.Worksheets.Add(null, null,1,
Excel.XlSheetType.xlWorksheet);

Any help is greatly appreciated!

katzky

unread,
Apr 7, 2006, 5:19:02 PM4/7/06
to
Uggh.... Never mind... After hours of searching I finally foung the missing
golden nugget. Missing = Type.Missing --> this code works:

theSheet = (Excel.Worksheet) theBook.Worksheets.Add(Type.Missing,
Type.Missing, Type.Missing, Type.Missing);

0 new messages