Free Support Forum - aspose.com

Worksheet Name not being pulled from Excel File

Greetings,

When I load an Excel file into the Desktop Grid control, the names of the worksheets contained in the file are renamed. They appear on the WorkSheet tabs of the control as "Sheet1", "Sheet2", etc. I would very much like to keep the names of worksheets as they were originally in my Excel File.

Is this a bug, or have I not got something set correctly? I'm using the v1.7.0.0 version of the desktop grid control.

Thanks,

Chris Powell

Upon further investigation, I can say that it has to be a setting on the Grid control that I'm using on my form.

In a little test project that I wrote, I can load an excel file into the grid, and the names of the worksheets are correct. But when I load the file in the form in my actual project, they are changed.

I will continue to look into what property is creating this issue, but if you have any ideas, please let me know.

Thanks,

Chris Powell

Okay, I figured out what the problem was. And it wasn't exactly straight forward.

On my form, I added the desktop grid control when I was using v1.6.2.4. When I upgraded the app to use v1.7.0.0 today, I just changed the .dll. The first time the control actually ran, and the Protected property was set to true, the next time the control ran, I ran into the problem.

The solution was to deleted the grid control from the designer, save the form, then add the grid control back into the form, changing the name of the control to what it was before. Then the control behaves as expected.

Edit: Okay, after loading the form several times, it has gone back to losing the names of the worksheets again. The fix must be something other than replacing the control on the form. I'll continue to work on figuring out what's going on. Any information that you can supply will be greatly appreciated.

Thanks,

Chris Powell

Hi Chris,

I created a test project, and added the control(v1.7.0) in the form, in Form_Load() method, I wrote the code:

gridDesktop1.ImportExcelFile("c:\\1.xls");

I ran the project several times. But the problem was not found.

Could you please post the project and the excel files to me?

Thanks

Nick.Liu

Greetings Nick,



I can’t post the project files at the moment, as I’m
now at home and don’t have access to my files. This problem
occurs when you do the following…



Public Sub LoadTest()



gridDesktop1.ImportExcelFile(“c:\test.xls”)



gridDesktop1.GetActiveWorkSheet().Protect = True



End Sub



I found that if you do the .Protect assignment in a seperate method,
the problem wouldn’t occur. The problem doesn’t happen on the
first time running the project. Sometime it happens on the second
or third time of running the project. If I delete the control,
add it back in again, and remove the .Protect assignment, the control
works fine.



Hopefully this helps,



Chris Powell


Hi Chris,

I tried this many times, but the problem did not appear. Please post your project and excel files to me, when you can access.

Thanks,

Nick.Liu

Greetings,

I've attached a very simple project in which this problem is occuring. I'm using the v1.7.0.0 version of the control. There is a sample .XLS file in the zip file that the problem occurs with.

The only difference between the code I posted before, and the code in this project, is that in the SelectedSheetIndexChanged event handling code, I also put in a call to set the protected property for the active sheet to true. This is the bit that seems to be vital in reproducing the error, as if I only put the protected property change in the load function, the app works fine.

If the zip file doesn't make it through, please email me at ChrisP at Imaginets.com. (replace at with @)

Thanks,
Chris Powell

Greetings,

I thought of a different way of approching the problem. I commented out the Protected property assignment in the SelectedSheetIndexChanged event handler. In the method that loads the file, I did this,

Dim i As Integer
For i = 0 To GridDesktop.Worksheets.Count - 1
GridDesktop.Worksheets(i).Protected = True
Next

(I tried to do a For Each call on GridDesktop.Worksheets, but apparently the Worksheets property isn't an actual collection, even though its type name is WorkSheetsCollection.)

I do this after the ImportExcelFile call.

I would bet that you hadn't expected anyone to put a Worksheet.Protected assignment call into the SelectedSheetIndexChanged event handler. It probably isn't the best way of going about protecting the worksheets, but it does seem to cause an issue with the names of the worksheet.

Thanks,

Chris Powell

Hi Chris,

If Worksheet.Protected is true, Worksheet name can't be changed. And ImportExcelFile method will raise SelectedSheetIndexChanged event several times. So if you set Worksheet.Protected true in SelectedSheetIndexChanged event handler, the name of worksheet is initialized in ImportExcelFile method by index and can not be changed.

Thanks