Removing border of a cell in aspose

Hi everyone. I am facing a issue. I want to remove border bottom of a cell but I have no idea how to do it. I searched on the net. It only tells about adding the different types of border. Can anybody help ??

Hi,

Thanks for your query.

Please see the following sample code for your reference:
e.g.
Sample code:

Workbook workbook1 = new Workbook(“Book1.xlsx”);
Worksheet worksheet1 = workbook1.Worksheets[0];
Cells cells = worksheet1.Cells;
Style style = workbook1.CreateStyle();
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.None;
cells["A1"].SetStyle(style);
workbook1.Save(“e:\test\out1.xlsx”);

Hope, this helps a bit.

Thank you.

Hi Amjad.


Thanks for replying.

I think I replied on another post.

I do not think that the solution worked. I am attaching a excel template. You can see the cells E11, G11, J11, K11, D14. I want to remove the black bottom border. When I try to remove the bottom border in excel only a new thick line appears (which I think is outline or it might be some other thing). I have the requirement that the cells mentioned above should be same as cell E15 with no bottom border and no outline. The problem is I am not able to understand what thick lines comes even after removing the border bottom .

Can you help ??

Hi,

Thanks for the template file and details.

We did evaluate your issue in details using your template file and found the cause of this issue. But, I am afraid there is no simple way for you to get the expected results in your template file. We think your file might be generated by some other tool other than MS Excel. In fact, there is no bottom border set for the style of the cell, e.g E11. The border was set on the style of E12 for its top border. For performance consideration when using Aspose.Cells component to set styles, there is no guarantee that all adjacent borders will be kept consistent for all adjacent cells. We think, for this kind of situation, you should remove the top border for E12 cell (next cell in that column) too (on a safer side) when removing the bottom border for E11 cell. Please do the same for other cells on which you want to remove bottom borders. See the sample code that works fine for your reference:
e.g.
Sample code:

//Open an Excel file.
Workbook workbook = new Workbook("Apple+(3).xlsx");
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
Cell cell = cells.get("E11");
Style style = cell.getStyle();
style.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.NONE, Color.getEmpty());
// Saving the modified style to the E11 cell with removed bottom border (it it has)
cell.setStyle(style);
//Get the cell after E11 in the column, i.e., E12 cell.
cell = cells.get("E12");
style = cell.getStyle();
// Saving the modified style to the "E12" cell with removed top border.
style.setBorder(BorderType.TOP_BORDER, CellBorderType.NONE, Color.getEmpty());
cell.setStyle(style);
// Saving the Excel file
workbook.save(“out1.xlsx”);

Hope, this helps a bit.

Thank you.