Copy Sheet with formatting

Hello,

I have a problem when copying a worksheet to a new workbook. Some cell formatting does not apply. I use the Aspose.Cells 21.2.0.0

A decimal value of 0.3 becomes 0 after copying.

Example :

var sheet = Workbook.Worksheets[i - 1];
var sheetTemp = TmpWorkbook.Worksheets.Add(sheet.Name + j.ToString());

sheetTemp.Copy(sheet);

Initial value :
image.png (9.5 KB)

Value after copy :
2021-02-25 18_45_02.png (6.4 KB)

Do you have any idea ? Solution ?

Thank you

Florent

@FloMart,
We have tried this scenario using our own sample files but could not reproduce this issue here. Could you please share your sample files for our reference?

Workbook workbook = new Workbook("input.xlsx");
Cell cell = workbook.Worksheets[0].Cells["A1"];
//cell.Value = 0.29;
Console.WriteLine(cell.Value);
Console.WriteLine(cell.DisplayStringValue);
var sheet = workbook.Worksheets[0];
Workbook TmpWorkbook = new Workbook();
TmpWorkbook.Worksheets.RemoveAt(0);
var sheetTemp = TmpWorkbook.Worksheets.Add(sheet.Name);

sheetTemp.Copy(sheet);
TmpWorkbook.Save("output.xlsx");

Workbook workbook1 = new Workbook("output.xlsx");
Console.WriteLine(workbook1.Worksheets[0].Cells["A1"].DisplayStringValue);

Program Output
0.29
0.3
0.3

input.xlsx.zip (6.3 KB)
output.xlsx.zip (6.2 KB)

Hello,

The input file : Test.xlsm.zip (293.0 KB)

The output file : Test-2602-2.pdf.zip (90.6 KB)

The issue is on the table value.

My code is a litte bit different with an shapes update before the copy. I don’t know it could be an issue.

@FloMart,
I can not open the input file. Could you please create the Zip file with WinRar or any other application, instead of changing the file extension to Zip.

Input file : Test.zip (257.9 KB)
Output file : Test-2602-2.zip (78.1 KB)

@FloMart,
We have observed the issue and logged it in our database for further investigation. We will write back here once any update is ready for sharing.
This issue is logged as:
CELLSNET-47896 -Formatting lost while copying sheet from one workbook to other

Ok thank you @ahsaniqbalsidiqui.
For more details, a conditional formatting is set on the failed range.

@FloMart,
You are welcome and thank you for sharing additional information.

@FloMart,

  1. The formula value cached in the template file is wrong.
Workbook workbook = new Workbook(dir + "Test.xlsm");
Console.WriteLine(workbook.Worksheets["Granulométrie"].Cells["A47"].Value);            
workbook.CalculateFormula();            
Console.WriteLine(workbook.Worksheets["Granulométrie"].Cells["A47"].Value);
  1. This file is very strange. If you unhide Row 1 to Row 28 on the worksheet “TxSaisieGranulo”, you will find that the value of A37 is empty, and A47 is displayed as 0 in the worksheet “Granulométrie”.

We saw a special setting in the file: <xcalcf:feature name=“microsoft.com:CNMTM”/>, if we remove this, when the file is opened, A47 in the worksheet “Granulométrie” shows 0 .
What version of Excel are you using, and what type of license are you using? We found some information about CNMTM:

So please force all formulas to be recalculated in Excel or call workbook.CalculateFormula(); to recalculate formulas.

Thank you for your response.

I don’t know what is the office 365 version because the file is not managed by me.
Your idea to calculateformula on the new workbook cannot be worked on my case because the others worksheets used in the formulas are not copied but I succeed to find a solution without copying the worksheet but deleting all the unnecessary worksheets on the original file.

@FloMart,
We have noted your feedback and will share our comments after detailed analysis here.

@FloMart,

If you copy the worksheet to another workbook in MS Excel manually, you will get same results as Aspose.Cells produces. And, we cannot generate your excepted file for now, So, it’s better to remove other worksheets to get it now.

Yes but if I copy worksheet on another worbook I lose conditional formatting and others settings.

The goal is to understand why they are conflict when I update only one shape on others graphical aspects.
In my case, I update one shape and not only this shape is updated

When you copy a worksheet to another workbook in MS Excel manually, you will also loose the formatting, so Aspose.Cells behaves the same way as MS Excel does. Aspose.Cells follows MS Excel standards and specifications and mimics the same behavior while copying worksheets b/w workbooks.

Anyways we will further check and may give you more details on it.

Yes I am agree with your comment.

In fact, I remove the others worksheets from the original workbook.

I had a mistake with other current topics, in my previous response.

@FloMart,

It seems you have sorted it out now. In the event of further queries or other issue, feel free write us back.