Copying sheets across workbooks doesn't preserve CodeName

Hi,

We're using CodeNames to uniquely identify sheets within workbook no matter what is actual sheet name localized to.

So, we have a template file where we define CodeName directly in Excel (ALT+F11 -> Properties -> (Name)) and then use it. That all works good if we use 1 workbook only.

The problem is that we need to use 2 workbook templates and copy sheets from 1st one to 2nd one. As soon as we do that with code snippet below, all CodeNames from 1st workbook are gone and all copied sheets get CodeNames "Sheet1, Sheet2...". That doesn't work as our unique identifier got lost.

We tried it both with 5.5 and latest 7.0 version - same result.

Any ideas?

Thanks,

Martin

Code sample...

Workbook dataTemplate = new Workbook(@"C:\book1.xlsx");
Workbook textTemplate = new Workbook(@"C:\book2.xlsx");

if (dataTemplate!=null && textTemplate != null)
{
//use data template as base and copy all sheets from other ones
foreach (Worksheet worksheet in textTemplate.Worksheets)
{
//create new worksheet in datatemplate
Worksheet newWorksheet = dataTemplate.Worksheets.Add(worksheet.CodeName);
newWorksheet.Copy(newWorksheet);
}
}

Hi,

Please provide your both xlsx files with code name set. We will look into issue by executing your code.

Please also try the latest version:
Aspose.Cells for .NET v7.0.1.1

Here you go...

Source files - book1.xlsx, book2.xlsx

Result file - result.xlsx.

Book2.xlsx sheets have TEXT_1 and TEXT_2 codenames.

After copying them to Book1.xlsx, code names get changed to "Sheet1" and "Sheet2".

Hi,

I was able to reproduce the problem. Below is my code and you can see the screenshot for illustration.

This issue has been logged as CELLSNET-30752.

C#


string path1 = @“F:\Shak-Data-RW\Downloads\Book1.xlsx”;

string path2 = @“F:\Shak-Data-RW\Downloads\Book2.xlsx”;

string path3 = @“F:\Shak-Data-RW\Downloads\Result.xlsx”;


Workbook dataTemplate = new Workbook(path1);

Workbook textTemplate = new Workbook(path2);


if (dataTemplate != null && textTemplate != null)

{

//use data template as base and copy all sheets from other ones

foreach (Worksheet worksheet in textTemplate.Worksheets)

{

//create new worksheet in datatemplate

Worksheet newWorksheet = dataTemplate.Worksheets.Add(worksheet.CodeName);

newWorksheet.Copy(newWorksheet);

}

}


dataTemplate.Save(path3, SaveFormat.Xlsx);

Screenshot:

Hi,

Could you please tell us about the progress status of CELLSNET-30752?

Thanks.

Martin

Hi,

I am afraid, your issue is still unresolved. I have added your comment in our database. Hopefully, it will be fixed soon.

Please also try the latest version:
Aspose.Cells for .NET 7.0.3 and provide me your feedback.

Hi,


Please try the attached version/fix v7.0.3.1, we have fixed your issue now.

Thank you.

Thanks,

7.0.3.1 fixed it - it works as expected now.

Cheers,

Martin