Style artifacts appearing when using DeleteRegion

Hello,

While working with aspose.excel.dll version 3.6.2.0, I’ve run into a problem which may be a side effect when using the [] operator with the Cells object. I have a fragment of a boundary box which appears in a deleted cell, and which is not generated by the code I’ve written.

I’ve attached a zip file which demonstrates the issue. It contains a C# module, an excel workbook, and an aspx page associated with the C# module.

I’ve created two nearly identical methods which identify a cell which sits directly beneath a set of merged cells. Both functions delete the identified cell and shorten the merged region under which the cell sits.

The first method, named RemoveRegionByName(), is designed to look “down” within the column of the identified cell, find the end of a region, and delete the entire region. To do this search, it uses a function named FindLastCell(), which I have written.

The second method, named RemoveAtCoordinates(), removes the same region as the other method, but the region is hard coded to demonstrate results which are clean and correct.

The demo I’ve included will modify a workbook with two sheets, named Example1 and Example2. Example1 becomes “broken”, and relies on RemoveRegionByName. Example2 is clean, and relies on RemoveAtCoordinates. Refer to cell Q5 on both worksheets, to see the difference.

The key difference between the methods is the use of the function FindLastCell. Isolated within that function is the cause of the artifact you will find on worksheet Example1. Unfortunately I cannot determine what is wrong, since FindLastCell actually does what it’s written to do, and nothing more.

I’m hoping my demo will provide you with insight into the source of the side effect.

-John Hartman
jhartman@shepsys.com

Here is the zip file I mentioned in the original post.

Hi John,

This is caused by you access the style of adjacent cells' style.

With the following code the border will be removed:

Excel excel = new Excel();
excel.Open("d:\\test\\book1.xls");
excel.Worksheets[0].Cells.DeleteRange(3, 16, 4, 16, ShiftType.Left);
excel.Save("d:\\test\\book1.xls");

With the following code the border will not be removed:

Excel excel = new Excel();
excel.Open("d:\\test\\book1.xls");
Cell cell = excel.Worksheets[0].Cells["Q6"];
Style style = cell.Style;
excel.Worksheets[0].Cells.DeleteRange(3, 16, 4, 16, ShiftType.Left);
excel.Save("d:\\test\\book1.xls");

When you access the adjacent cells' style, it's border is also set. You can try above workaround or use ShiftType.None option then set the style as your wish.