I can create a workbook with multiple sheets if I use a template xls file just fine using the following code:
Dim
oExcel As New Excel.ApplicationDim oBook As Excel.Workbook = oExcel.Workbooks.Open("C:\reports\templates\templates.xls") Dim oSheet1, oSheet2, oSheet3 As New Excel.Worksheet
oSheet1 = oBook.Worksheets(1)
oSheet2 = oBook.Worksheets(2)
oSheet3 = oBook.Worksheets(3)
oSheet1.Range(
"A" & "1").Value = "test"
oSheet2.Range(
"B" & "2").Value = "test"
oSheet3.Range(
"C" & "3").Value = "test"
oBook.SaveAs(
"c:\test2.xls")
I can also create a workbook with 1 sheet from scratch with this code:
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("sHEET1")
'xlWorkSheet.Name = "tEST RUN"
'xlWorkSheet.Cells(1, 1) = "test4"
'xlWorkBook.SaveAs("C:\test3.xlsx")
But I can't create a workbook with more than 1 sheet? can anyone help? I can't find an example anywhere. Any help would be greatly appreciated.
Thanks.