create a new excel workbook and add x number of worksheets using c#
Posted on 2013-07-01
using c# in vs2010. I need to create a new excel workbook with an unknown number of worksheets. This is what I'm currently doing:
Application xls = new Microsoft.Office.Interop.Excel.Application();
Workbook wb = xls.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet ws = (Worksheet)wb.Worksheets;
I actually need to be able to create, say 10, worksheets and then cycle among them.
Each worksheet is a single record from a dataset, hence the number of worksheets depends on the number of records.