Address(NamedRange) Getting change in cell refernce when NamedRange is exists in Excel

Here is my code snippets

string[] blobPath = Directory.GetFiles(path1, docName);  // getting Old File before change
 Workbook wblob = new Workbook(blobPath[0]);
//Latest File bytes after changing in file in data.bytes
 using (MemoryStream ms = new MemoryStream(data.bytes))
 {
     ms.Position = 0;
     wtemp = new Workbook(ms);
 }
 Worksheet sheetTemp = wtemp.Worksheets[1];
 Worksheet sheetBlob = wblob.Worksheets[1];
 sheetBlob.Copy(sheetTemp);
 wblob.Save(Blob Path);

I am giving reference of one cell to other worksheet(that cell has NamedRange/DefineName). After using Copy function to copy individual worksheet my value is getting changed.
I describe the error in below images.
sourceData.png (28.5 KB)

ErrorDescription.png (53.8 KB)
error.png (38.7 KB)

Here I am Uploading My excel when you open it you can see same value as(400,600) after just edit(Press F2 then press enter) its getting change because of that changing in Named range . I am attaching that source file here.
source.zip (10.2 KB)
Sheet1 is protected For unprotecting Password is FSOlnZpoI6aa5OquJpgWET1jwknocj0kTQg2AU5kQjI=
My conclusion :- As per my observation when NamedRange(Define Name) is on sheet Level that time this issue is occurs if NamedRange(Define Name) scope is on Workbook level it’s working Properly.
Thanks.

@Jayshiv,

Thanks for the details and screenshots.

Probably, “source.xlsx” in your attached zipped archive is the final output Excel file. Please also zip and provide template blob and temporary workbooks (Excel files), so we could evaluate and test your issue precisely on our end.

I am copying a worksheet from a local path, and then utilizing the copy function to save only that specific worksheet to my blob path.
Note: Both files contain identical content.

So, you can just copy the same file for reference.

@Jayshiv
1,Please copy the worksheet to another workbook in MS Excel and compare it with the file generated by Cells. You will find external links are generated too in MS Excel. And if you removed the source file, the data of external links changed too.

2, If the dest workbook contains same worksheet and defined names, please try the following codes: CopyOptions options = new CopyOptions();
options.ReferToSheetWithSameName = true;
worksheet.Copy(worksheet, options).
And it’s better that you can upload blob file and excepted file too, so we can check them soon.

Hi @amjad.sahi and @simon.zhao thanks for quick response.

When working with Excel files stored on a blob server, we encounter issues related to named ranges (defined names) when using the copy function.

Here’s the scenario:

  1. We have an Excel file stored on a blob server.
  2. We retrieve the Excel file as binary data and load it into an Aspose workbook object.
  3. We want to save only a specific worksheet from this workbook back to the blob server.
  4. To achieve this, we use the Worksheets copy function to copy the desired worksheet.
  5. However, during the copy operation, we encounter issues related to named ranges (defined names).
    Here we are using Named Range on Sheet Level.

For more detail I have attached zip file which has below structure.

  1. source_old.xlsx which is behave as rendering file as I mention above( point no 2)
  2. source_new.xlsx which is behave as blob file.
  3. What exactly we want in source_new.xlsx file

Note: We have named range to each and every used cells(scope of range is on sheet level) .
source.zip (10.2 KB)

Thanks,

@Coder365,

Your attached zipped archive “source.zip” has only 1 file, i.e., “source.xlsx”. Probably you forgot to attach the relevant/correct zip file and re-attached the same archive, i.e., “source.zip” you attached in the first post of the thread. Please do attach the correct zipped archive containing your mentioned structure. We will check your issue soon.

@Coder365
Can you upload a complete console project with source files and expected files to reproduce your issue? Then we can locate your issue soon.

sorry my bad. please find correct zip here.
source_new.zip (21.4 KB)

@Jayshiv
By using sample files and code for testing, we can reproduce the issue. Failed to change cell references after copying worksheet. Please check the attachment. result.zip (93.3 KB)

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-55150

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thanks for the update. Is there any alternative approach to fix it?
and also may I know by when this issue will be fixed? So, that we can plan accordingly.

@Coder365
This is a bug and there is currently no alternative solution. Since your issue was logged today(just a few hours ago), please allow us some time to evaluate and analyze it in detail. If it is not complex, we should be able to fix it soon, and the fix may be included in our upcoming release (Aspose.Cells v24.3 - planned for publication in the second week of March next month). If the issue is complex, it may take a few more weeks or even a month to resolve.

Additionally, if you purchase paid support, we will prioritize your issue so that it can be resolved earlier.

@Coder365,

We are pleased to inform you that your issue (logged earlier as “CELLSNET-55150”) has been resolved now. The fix/enhancement will be included in the upcoming release (Aspose.Cells v24.3) that we plan to release in the second week of March (next month). You will be notified when the next version is released.

The issues you have found earlier (filed as CELLSNET-55150) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi

Hi team, I take temp License and 24.3.0.0 version dll to check.
I’m still facing this issue some time it’s working fine and sometime its showing wrong value(Reference getting changed).
Here I am Attaching my File in that I give reference in sheet5 which is taken from sheet 2 . I give some reference between this range (sheet2 A11:C30) from that some value retain same and other value get #REF. Sometime it’s show some other cell value also . I’m not able to replicate proper scenario for that but in property I can see IsRefere is getting true but RefersTo property refereeing wrong cell
Source.zip (16.2 KB)

here my File before before I add that reference in sheet5
SourceOld.zip (13.3 KB)

@Jayshiv
By using the following sample code for testing, we can obtain the correct results. Please refer to the attachment. out_net.zip (14.1 KB)

The sample code as follows:

var excelPath = filePath + @"Source.xlsx";
var excelpath1 = filePath + @"SourceOld.xlsx";

Workbook wblob = new Workbook(excelPath);
Workbook wtemp = new Workbook(excelpath1);
foreach (var item in wblob.Worksheets)
{
    foreach (var item1 in wtemp.Worksheets)
    {
        if (item.Name == item1.Name)
        {
            item1.Copy(item);
        }
    }
}

wtemp.Save(filePath + "out_net.xlsx");

If you still have any questions or confusion, please provide sample code and the expected result file. If you could take a screenshot and highlight it to indicate the issue, it would be very helpful for us to locate the issue.

1 Like

Byte[] bytes = File.ReadAllBytes(“C:\Users\jayshiv.patel\Desktop\source.xlsx”);
Byte[] bytes1 = File.ReadAllBytes(“C:\Users\jayshiv.patel\Desktop\CopyNew1.xlsx”);
Workbook wblob, wtemp;
using (MemoryStream ms = new MemoryStream(bytes))
{
ms.Position = 0;
wblob = new Workbook(ms);
}
using (MemoryStream ms = new MemoryStream(bytes1))
{
ms.Position = 0;
wtemp = new Workbook(ms);
}
foreach (var item in wblob.Worksheets)
{
foreach (var item2 in wtemp.Worksheets)
{
if (item.Name == item2.Name)
item2.Copy(item);
}
}
wtemp.Save(“C:\Users\jayshiv.patel\Desktop\CopyNew1.xlsx”)
here is my I’m using the samecode but it’s giving wrong output sometime.
It’s causing error(worng cell reference) randomly.

@Jayshiv
Would you like to share your output file and take screenshots to highlight the errors? We will check it soon.

@Jayshiv,

Also, you did not provide the “CopyNew1.xlsx” file, is it “SourceOld.xlsx” file or some different file. If it is a different file, kindly do provide the file as well.

Sorry for that .
It’s my naming mistake SourceOld.xlsx and CopyNew1.xlsx both are same.
I just give reference from sheet2 to sheet5 in source.xlsx file and for save that new changes I’m copying worksheet one by one in to SourceOld.xlsx.
Basically both source and SourceOld file are same only new changes is not there in sourceOld.xlsx after copy and save both file will be same.

@Jayshiv,

Alright. But as @John.He asked, kindly provide the following artifacts:

  1. Your current output Excel file by Aspose.Cells.
  2. Your expected Excel file, you may use MS Excel to create the desired Excel file.
  3. Some screenshots (you may capture in MS Excel) to highlight the problematic areas and other errors.

So, we could evaluate and check your issue precisely on our end.