Saving multi worksheets


#1

I’m having problems saving multi work sheets… From what I can gell the sheets are getting generated… just not saved…

Dim excel As Excel = New Excel
Dim startRow As Integer = 0
Dim sheets As Worksheets = excel.Worksheets

Dim g As Integer = 0
For g = 0 To 5 Step 1
'Add a worksheet
sheets.Add()

sheets(g).Name = “section” & g
sheets.SetActiveSheet(g)

Dim cells As Cells = sheets(“section” & g).Cells
Next

While excel.Worksheets.Count > 1
excel.Worksheets.RemoveAt(excel.Worksheets.Count - 1)
End While
excel.Save(“c:” & “DSRD” & “.xls”, FileFormatType.Default) '


What I get is section0 and Sheet 8, sheet 8 is the eval notice… Am I missing something?


#2

Hi,

Please try to remove the following code and see the result:

While excel.Worksheets.Count > 1
excel.Worksheets.RemoveAt(excel.Worksheets.Count - 1)
End While


#3

I did… when I don’t have this code the program seems to hang when trying to save. I waited over an hour. When it didn’t work. I added the code back in. Just for the record. I am implementing this in a winform not an asp page.


#4

Hi.

I test your code in a winform app and get the expected multi worksheets.

Please try the new fix:

Fix 1.5.3

If you still have problem, please tell me.

Thanks.


#5

Yes… that helped…

also… your previous suggestion helped as well…

removing

While excel.Worksheets.Count > 1
excel.Worksheets.RemoveAt(excel.Worksheets.Count - 1)
End While


what I had done… and didn’t relize was…

While excel.Worksheets.Count > 1
'excel.Worksheets.RemoveAt(excel.Worksheets.Count - 1)
End While

so it was stuck in a loop… Thanks for the responce…