We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Changing Cells number formatting unexpectedly adds borders

Hi,

When I tried to change the number formatting of cells and copy/paste the range afterwards, I noticed borders of the cells were also changed unexpectedly.

Code:

        var workbook = new Workbook(@".\test.xlsx");
        var fromRange = workbook.Worksheets[0].Cells.CreateRange(1, 0, 5, 1).EntireRow; // copy rows 1 - 10
        var toRange = workbook.Worksheets[1].Cells.CreateRange(11, 0, 1, 1);

        toRange.Copy(fromRange); // copy the data from the range
        workbook.Save(@".\out-before-number-format-change.xlsx");
        foreach (var cell in fromRange.GetCells())
        {
            var style = cell.GetStyle();
            style.Custom = "0.000";

            var styleFlag = new StyleFlag();
            styleFlag.NumberFormat = true; // only number format should be changed
            cell.SetStyle(style, styleFlag); 
        }
        toRange.Copy(fromRange); // copy the data from the range
        workbook.Save(@".\out-after-number-format-change.xlsx");

Supposedly, the difference between the two output xlsx files should only be the number formatting, but there were extra borders added in some cells.

I also tried to do it in Excel and did not see this issue after I re-applied number formats manually.

I’ve attached the test files and a screenshot for your reference. Could you please help me take a look?

test.zip (60.9 KB)
image.png (62.1 KB)

Thanks,

@ServerSide527,
We have reproduced this issue here and have logged it for further investigation as follows:

CELLSNET-47431 - Changing Cells number formatting unexpectedly adds borders

@ServerSide527,
This is to inform you that we have fixed your issue (logged earlier as “CELLSNET-47431”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

@ServerSide527,
Please try the latest fix 20.6.2 with the following codes:

var style = cell.GetStyle(false);
style.Custom = "0.000";

Aspose.Cells20.6.2 For .Net2_AuthenticodeSigned.Zip (5.4 MB)
Aspose.Cells20.6.2 For .Net4.0.Zip (5.4 MB)

Let us know your feedback.

The issues you have found earlier (filed as CELLSNET-47431) have been fixed in Aspose.Cells for .NET v20.7. This message was posted using Bugs notification tool by ahsaniqbalsidiqui