Hi,
Dim oExcel As Microsoft.Office.Interop.Excel.Application
Dim oBook, oBook1 As Microsoft.Office.Interop.Excel.Workbook
Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet
'Start a new workbook in Excel.
oExcel = New Microsoft.Office.Interop.Excel.Application
oBook = oExcel.Workbooks.Add
oBook1 = oExcel.Workbooks.Add
'Add data to cells of the first worksheet in the new workbook.
oSheet = CType(oBook.Worksheets(1),
Microsoft.Office.Interop.Excel.Worksheet)
oSheet.Range("A1").Value = "Last Name"
oSheet.Range("B1").Value = "First Name"
oSheet.Range("C1").Value = "Price"
oSheet.Range("A1:B1").Font.Bold = True
oSheet.Range("A2").Value = "Doe"
oSheet.Range("B2").Value = "John"
oSheet.Range("C2").Value = 12345.456
oSheet.Range("C2").Cells.NumberFormat = "$0.00"
oSheet = CType(oBook.Worksheets(2),
Microsoft.Office.Interop.Excel.Worksheet)
oSheet.Range("A1").Value = "Last Name"
oSheet.Range("B1").Value = "First Name"
oSheet.Range("C1").Value = "Price"
oSheet.Range("A1:B1").Font.Bold = True
oSheet.Range("A2").Value = "Doe"
oSheet.Range("B2").Value = "John"
oSheet.Range("C2").Value = 12345.456
oSheet.Range("C2").Cells.NumberFormat = "$0.00"
'Save the Workbook and quit Excel.
oExcel.DisplayAlerts = False
oBook.SaveAs("c:\Book1.xls")
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
Ken
-------------------------------------
"KC" <yo*@dontneed.this> wrote in message
news:e2**************@TK2MSFTNGP11.phx.gbl...
Does anybody know how to add a specific number of worksheets to an Excel
spreadsheet through VB.net? I'm trying to export some datatables to an excel
file, but I only want as many sheets in the workbook as there are tables.
Right now the routine I'm tweaking from
http://support.microsoft.com/default...b;EN-US;306022
adds the default, (3).
At this stage I can export data fine, I just don't know how to control the
number sheets.
--
Ken