Behavior changed and file corrupt when setting invalid number format

Hi,

In the previous versions when setting invalid number format the cell’s number format was switched back to General automatically. Now the number format is set incorrect and the file is reported as corrupt by Excel.
For reproducing the issue please use the attached file and the following code:

{
var workbook = new Workbook(“sample.xlsx”);

var currentWorksheet = workbook.Worksheets[0];
var formatCell = currentWorksheet.Cells[“A1”];
formatCell.PutValue(123);
SetCellCustomStyle(formatCell, “fff @ ggg”);

var formulaCell = currentWorksheet.Cells[“A10”];

workbook.CalculateFormula(false, null);

Console.WriteLine(“When using Aspose.Cells v.8.4.2.0 A10’s value was: “G””);
Console.WriteLine(“Now when using Aspose.Cells v.8.5.0.0 A10’s value is: “{0}””, formulaCell.Value);

Console.WriteLine(“Saving workbook… when opening it in Excel it’s reported as corrupt”);
Console.WriteLine(“and after repairing it A10’s value is: “G”.”);
workbook.Save(“output.xlsx”);
}

private static void SetCellCustomStyle(Cell cell, string customStyle)
{
Style cellStyle = cell.GetStyle();
cellStyle.Custom = customStyle;
cell.SetStyle(cellStyle);
}


Best regards,
Aurelian Iordache
Software Developer
IBM Romania

Hi,


Thanks for the template file.

When I open your tmeplate “sample.xlsx” into Ms Excel 2007/2010, I also got “Excel found unreadable content…” error, so your file is corrupt. Although I can trace the issue i.e., it prints as following using your sample line of code:
Now when using Aspose.Cells v.8.5.0.0 A10’s value is: “D3” //instead of “G”.

But since your template file is corrupted, so it is not reading the data/ contents fine. Could you provide your valid template file which should not be corrupt, we will further evaluate your issue on our end.

Thank you.

Hi Amjad,

I’m attaching the file here.

Best regards,
Aurelian Iordache
Software Developer
IBM Romania

Hi,


Thanks for providing us the valid template file.

I observed the issue as you mentioned with v8.5.0.x (latest version/fix). I found that the CELL formula is calculated wrongly by Workbook.CalculateFormula() method and the output file is corrupted as you pointed out. I used your newly attached template file with the following sample code:
e.g
Sample code:

var workbook = new Workbook(“e:\test2\Sample.xlsx”);

var currentWorksheet = workbook.Worksheets[0];
var formatCell = currentWorksheet.Cells[“A1”];
formatCell.PutValue(123);
SetCellCustomStyle(formatCell, “fff @ ggg”);

var formulaCell = currentWorksheet.Cells[“A10”];

workbook.CalculateFormula(false, null);

Console.WriteLine(“When using Aspose.Cells v.8.4.2.0 A10’s value was: “G””);
Console.WriteLine(“Now when using Aspose.Cells v.8.5.0.0 A10’s value is: “{0}””, formulaCell.Value);

Console.WriteLine(“Saving workbook… when opening it in Excel it’s reported as corrupt”);
Console.WriteLine(“and after repairing it A10’s value is: “G”.”);
workbook.Save(“e:\test2\out1.xlsx”);

Console Output:
When using Aspose.Cells v.8.4.2.0 A10’s value was: “G”
Now when using Aspose.Cells v.8.5.0.0 A10’s value is: “D3”
Saving workbook… when opening it in Excel it’s reported as corrupt
and after repairing it A10’s value is: “G”.

I have logged a ticket with an id “CELLSNET-43770” for your issue. We will look into it soon.

Once we have any update on it, we will let you know here.

Thank you.

Hi,


We have evaluated your issue further. Well, an error message box will be popped up if you try to input
“fff @ ggg” as a number format in MS Excel manually. This number format “fff @ ggg” has corrupted the
file. So, kindly enter valid number format.

Thank you.

Hi Amjad,

Yes that is correct but in Excel if this invalid number format is typed Excel is restoring the cell’s format to the previous format.
The same behavior was present in Aspose.Cells, if we tried to set this invalid number format to a cell having “General” format then the cell’s format was not set to the wrong format and the previous valid format of the cell was restored (in our example “General”).
That behavior was changed and now the wrong number format is set and the file become corrupted.
The previous behavior (cell restoring to the previous valid format) which we used in our project is much safer and is the same behavior like MS Excel.

Best regards,
Aurelian Iordache
Software Developer
IBM Romania

Hi,


We will check if we could implement your demand, i.e., when an invalid number formatting is set, it should not corrupt the file rather it should restore to previous valid format. I have logged your concerns against your issue into our database. The concerned developer from product team will evaluate it soon.

Once we have any update on it, we will let you know here.

Thank you.

Hi again,


This is to update you that the ticket logged earlier as CELLSNET-43770 has been marked resolved. We will shortly share the fix here for your testing.

The issues you have found earlier (filed as CELLSNET-43770) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.