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,
Hi Amjad,
I’m attaching the file here.
Best regards,
Aurelian Iordache
Software Developer
IBM Romania
Hi,
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”.
Hi,
“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.
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,
Hi again,
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.