We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Import template to a new sheet

I am having a problem adding a template to a new sheet. I have the following in the load of the form.

GridDesktop1.ImportExcelFile(Application.StartupPath & "\template\Library Template.xls", True)

GridDesktop1.RunAllFormulas()

On the context menu I have it add a new sheet. I would like this template be added to the new sheet. I have tried the copy and that is not working.

I am using the griddesktop on my form and need to add it to the grid on the form. I have it creating the on a new sheet by doing the following:

Dim newsheet As GridDesktop.Worksheet = GridDesktop1.Worksheets.Add()


This message was posted using Aspose.Live 2 Forum

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Your requested feature “To Import template file to a new worksheet” is not supported at the moment. We have added the feature in our internal issue tracking system with issue id: CELLSNET-15381. We will look into the feasibility of the feature and get back to you.

Thank You & Best Regards,

Is there a way to make this happen with the current product?

Attached is the template spreadsheet. The steps I need to make this work is in the Griddesktop is the ability to add this to a new sheet.

Step 1) Import the spreadsheet template

Step 2) If they add a new sheet, then the template will load in that new sheet.

Attached is the sample program

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the sample application.

We will look into it and get back to you soon.

Thank You & Best Regards,

Hi,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the sample application.

We have found your mentioned issue after an initial test. We will look into it and get back to you soon. Your issue has been registered in our internal issue tracking system with issue id: CELLSNET-15467.

Thank You & Best Regards,

Hi,

Please try the attached version. We provide an overloaded version of the method “ImportExcelFile” to support importing a worksheet from excel file in Aspose.Cells.GridDesktop v2.1.0.2003(attached). The second parameter of the method indicates index of sheet to be imported. Please try the following sample code:

Private Sub NewSheet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

GridDesktop1.ExportExcelFile(Application.StartupPath & "\LT.xls")

Dim newworkbook As New Workbook

newworkbook.Open(Application.StartupPath & "\LT.xls")

Dim templateWorkbook As New Workbook

templateWorkbook.Open(Application.StartupPath & "\template\Library Template.xls")

'Dim templatecells As Cells = templateWorkbook.Worksheets(0).Cells

newworkbook.Worksheets.Add()

newworkbook.Worksheets(1).Copy(templateWorkbook.Worksheets(0))

newworkbook.Save(Application.StartupPath & "\LT.xls")

'GridDesktop1.ImportExcelFile(Application.StartupPath & "\LT.xls")

GridDesktop1.ImportExcelFile(Application.StartupPath & "\LT.xls", 1)

If File.Exists(Application.StartupPath & "\LT.xls") Then

File.Delete(Application.StartupPath & "\LT.xls")

End If

End Sub

And, while importing if the worksheet’s name is same with that of GridDesktop control, the exception “Cannot set a sheet to the same name as another sheet” will be raised. GridDesktop control cannot contain two worksheets with same name. This behavior is right logically.

Thank you.

Ok. This works for adding one extra worksheet. It does not matter if you rename the sheet to something else or leave it alone. You still get the exception error. There are some places that there has to be atleast 4 or 5 sheets for the school.

Take the current application and try this with the new library.

1) run the program and in A2 type something in the field. It will then change the sheet tab name.

2) Then anywhere on the screen right click and select new sheet at the bottom of the menu.

3) On that sheet change the tab name by editing A2.

Jump back to #2 and repeat. You will get your exception error.

Thanks for your help.

Jim

Hi

Well, we think the exception is caused by the NewSheet_Click() event handler routine. You should change the sheet name when you save it with Aspose.Cells.

GridDesktop1.ExportExcelFile(Application.StartupPath & “\LT.xls”)

Every time when you export all the sheets by GridDesktop, the spreadsheet will be imported again, so, there will always be two sheets with same name and the exception would be raised.


Thanks for your understanding!

Nope that is not it. Here is what I did. This is under the newsheet click.

Dim RandomClass As New Random
Dim RandomNumber As Integer

RandomNumber = RandomClass.Next

GridDesktop1.ExportExcelFile(Application.StartupPath & "\" & RandomNumber.ToString & ".xls")

Dim newworkbook As New Workbook
newworkbook.Open(Application.StartupPath & "\" & RandomNumber.ToString & ".xls")

Dim templateWorkbook As New Workbook
templateWorkbook.Open(Application.StartupPath & "\template\Library Template.xls")
'Dim templatecells As Cells = templateWorkbook.Worksheets(0).Cells


newworkbook.Worksheets.Add()
newworkbook.Worksheets(1).Copy(templateWorkbook.Worksheets(0))

newworkbook.Save(Application.StartupPath & "\" & RandomNumber.ToString & ".xls")

GridDesktop1.ImportExcelFile(Application.StartupPath & "\" & RandomNumber.ToString & ".xls", 1)

If File.Exists(Application.StartupPath & "\" & RandomNumber.ToString & ".xls") Then
File.Delete(Application.StartupPath & "\" & RandomNumber.ToString & ".xls")
End If

I created a random number generator and I delete the file at the end. So there is still a problem.

Hi,


After seeing your code segment, I think you used RandomNumber to change excel file name but not sheet name e.g. “Sheet1”. We suggested you to change sheet name in my previous reply. Please check it out.


Thank you.

I told you before the "sheetname" was changed. Did you even try my steps? My steps inculded the fact that if you modify A2 it CHANGES the sheetname. What part did you not read. If you repeat it more than once you will see this happen. Try this and tell me what happens.

Hi,

We think there is some problem with your code/logic. We set a breakpoint at this line: GridDesktop1.ImportExcelFile(Application.StartupPath & "\" & RandomNumber.ToString & ".xls", 1).


And, we debugged your project with your updated code following your steps. Here are our test steps:


1) Input “step1” in A2, and create new sheet via your context menu item.

The debugger stopped at the breakpoint. A random excel file named 1855664241.xls was created, and it contains two sheets named “step1” and “Sheet2”.

When we continued the debug mode, GridDesktop control imported the second sheet named “Sheet2” invoking ImportExcelFile method with the second parameter set to 1.


2) Input “step2” in A2 of “Sheet2”, and create new sheet via your context menu item.

The debugger stopped at the breakpoint. Another random excel named 258134924.xls was created, and it contains 3 sheets named “step1”, “step2” and “Sheet3”.

When we continued with the debugging, GridDesktop control tried to import the second sheet named “step2” invoking ImportExcelFile method with the second parameter set to 1.


But, a sheet named “step2” already exists in GridDesktop control. So, the exception was raised.

Please check your code and update / modify it accordingly.


Thanks for your understanding!

The only reason I am doing this is the fact that you do not allow on a new sheet to import a template file. If you have that ability, then this would be corrected. If you look at the form load. I import a template file. When a new sheet is added, I need it to use the template file. Therefore this is just a work around. I have no other way of getting a template loaded into a new sheet. Do you have another means to do this?

Jim

Hi,

We have fixed the bug of ImportExcelFile method to avoid
importing duplicated sheet names. Please try the Aspose.Cells.GridDesktop v<st1:chsdate isrocdate=“False” islunardate=“False” day=“30” month=“12” year=“1899” w:st=“on”>2.2.0</st1:chsdate>.2003 (attached).


Thank you.

EXCELLENT. It works like it is suppose to. Thank you for your help.

The issues you have found earlier (filed as 15467) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan