Free Support Forum - aspose.com

Range.Worksheet

Hi Laurence,

why is it not possible to SET the Worksheet property of the Range object. I can only GET it.

In MS Excel if you have a sheet with locally defined named ranges i.e. ‘Sheet1’!Range1 and you copy this sheet, the range will be also copied and the source will change to the actual sheet-name. If I use Apose.Excel AddCopy(i) method it creates a new sheet with a local range but the source still shows to the old sheet.

Is there any solution for this problem ?

Thanks in advance.

Boris

Hi Boris,

Yes. The source of copyed range still refers to the previous sheet. I will fix it.

Hi Laurence,

thanks a lot. I have now some more problems:

1. If you want to define a local named range i.e. 'Sheet1'!Range1 and the sheet name contains blanks, I recieve an error although I put the sheet name in single quotes.

2. I recieve an exception "Errors in Excel Save method" if I try to define a local range i.e. 'Sheet3'!Range1 with source on different sheet i.e. =Sheet1!$D$3EmbarrassedD$3. MS Excel doesn't have any problems with it.

Can you fix it please. Thanks in advance.

Boris

I will check these two issues.

Could you post your code about issue 1? Thanks.

1.
this.excel = new Aspose.Excel.Excel("Aspose.Excel.lic");

Aspose.Excel.Worksheets sheets = this.excel.Worksheets;
Aspose.Excel.Worksheet sheet;
Aspose.Excel.Range range;

sheets.Clear();
sheet = sheets[sheets.Add()];
sheet.Name = "New Test";
range = sheet.Cells.CreateRange(1, 6, false);
range.Name = "'New Test'!Range";

this.excel.Save(this.desktopPath+@"\result1.xls", Aspose.Excel.FileFormatType.Default);

2.
this.excel = new Aspose.Excel.Excel("Aspose.Excel.lic");

Aspose.Excel.Worksheets sheets = this.excel.Worksheets;
Aspose.Excel.Worksheet sheet;
Aspose.Excel.Range range;

sheets.Clear();
sheet = sheets[sheets.Add()];
sheet.Name = "Test1";
sheet = sheets[sheets.Add()];
sheet.Name = "Test2";
sheets.SetActiveSheet(sheets["Test2"].Index);
range = sheets["Test1"].Cells.CreateRange(1, 6, false);
range.Name = "Test2!Range1";

this.excel.Save(this.desktopPath+@"\result1.xls", Aspose.Excel.FileFormatType.Default);

Hi Boris,

I fixed it and will release the new hotfix at the start of next week.

Now you can download the hotfix and have a try.

Thank you. It works now Yes