如何部分更改合并单元格的边框?

时间:2017-03-20 03:33:39

标签: c# epplus epplus-4

所以给出了这段代码:

var mergeCells = worksheet.Cells["A1:B5"];
mergeCells.Merge = true;
mergeCells.Style.Border.BorderAround(ExcelBorderStyle.Medium);

var notWorkingCell = worksheet.Cells["C1"];
notWorkingCell.Style.Border.Right.Style = ExcelBorderStyle.Medium;
notWorkingCell.Style.Border.Left.Style = ExcelBorderStyle.None; // <--This does not happen

我希望左侧边界notWorkingCell (C1)将被删除。这种情况没有发生:

documentation

如何部分更改合并单元格的边框?使用纯Excel可以实现。

1 个答案:

答案 0 :(得分:1)

看起来边框样式需要在合并单元格中的单元格地址上显式设置,而不是ExcelRange

var mergeCells = worksheet.Cells["A1:B5"];
mergeCells.Merge = true;
mergeCells.Style.Border.BorderAround(ExcelBorderStyle.Medium);

var notWorkingCell = worksheet.Cells["C1"];
notWorkingCell.Style.Border.Right.Style = ExcelBorderStyle.Medium;

var cellToLeft = notWorkingCell.Start;
worksheet.Cells[cellToLeft.Row, cellToLeft.Column - 1]
    .Style.Border.Right.Style = ExcelBorderStyle.None;

enter image description here