Free Support Forum - aspose.com

Errors when creating workbook from external worksheets

Background:
I am trying to create a workbook from a set of templates. Each template will have one or more worksheets. At run time, depending on the user, I will copy the template worksheet into the workbook, fill in the data, and send it out.


The symptons I get are interesting (but wrong!). The first 2 sheets come across OK. The 3rd sheet and subsequent, all have the same word repeating in all cells.

I have tried to save the workbook in between adding new sheets, but this did not help.

The sheets I am importing are fairly complex and have formulas in the first 10 lines or so.

I have written a routine to do the sheet copying. Here is the code for that:

Public Function CreateNewSheetFromTemplate(ByVal oExcel As Aspose.Excel.Excel, _

ByVal ExternalWorkbook As String, _

ByVal WorkSheetName As String, _

ByVal NewWorkSheetName As String) As Aspose.Excel.Worksheet

Dim oSheet As Aspose.Excel.Worksheet

sheetNumber = oExcel.Worksheets.Add()

oSheet = oExcel.Worksheets(sheetNumber)

oExternalExcel = New Aspose.Excel.Excel

Call SetLicense()

Try

oExternalExcel.Open(ExternalWorkbook)

Catch ex As Exception

Throw New Exception("Could not open external worksheet " & WorkSheetName & " in workbook " & ExternalWorkbook & vbNewLine & ex.Message)

End Try

Dim oExtWs As Aspose.Excel.Worksheet

Dim bFoundSheet As Boolean = False

For Each oExtWs In oExternalExcel.Worksheets

If oExtWs.Name.ToUpper() = Trim(WorkSheetName).ToUpper() Then

bFoundSheet = True

Exit For

End If

Next

If bFoundSheet = False Then

Throw New Exception("Could not find sheeet " & WorkSheetName & " in workbook " & ExternalWorkbook & vbNewLine)

End If

oSheet.Copy(oExtWs)

oSheet.Name = NewWorkSheetName

oExtWs = Nothing

oExternalExcel = Nothing

Return oSheet

End Function


This is an important feature we need to support in the application.


Mitch Stephens
Janis Group

Hi Mitch,

Have you tried the latest version at http://www.aspose.com/Products/Aspose.Excel/Downloads.html? If the problem still occurs in the new version, please send me your templates. Thank you very much.

Lawrence,
that did it! The worksheets are being created correctly now with the latest build.

PS: We love this product!

Mitch