Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply outline table border to a cell range using OpenXml?

I set border style for each cell. But if you look closely, you'll see the blue lines are not consecutive. There are some white hash marks across the vertical lines. Because inside the table, I set the top and bottom cell border as white. Anyone knows how to avoid this?

Table Cell

WorksheetPart v_worksheetPart = a_workbookPart.AddNewPart<WorksheetPart>();
v_worksheetPart.Worksheet = new Worksheet();
SheetData v_sheetData = new SheetData();
Row v_Row = new Row();
Cell v_Cell = new Cell();
...
v_Row.Append(v_Cell);
v_sheetData.Append(v_Row);
v_worksheetPart.Worksheet.AppendChild(v_sheetData);
...
like image 372
Joyin Avatar asked Mar 08 '23 02:03

Joyin


2 Answers

Just call

ws.Cells[row, col].Style.Border.BorderAround(ExcelBorderStyle.Thin);
like image 182
napi15 Avatar answered Mar 10 '23 16:03

napi15


Instead of drawing white borders to cover up the default grey grid lines, you should instead just hide the grid lines of your worksheet. To do this via code you would set the ShowGridLines property to False in the SheetView, like the code in this SO answer.

Then remove your code that added white borders to your solution and leave in the code for the blue borders. This will remove the white breaks in your blue border.

like image 34
Taterhead Avatar answered Mar 10 '23 15:03

Taterhead