1

所以给定这段代码:

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)会被删除。这没有发生:

上述代码的结果

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

4

1 回答 1

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;

在此处输入图像描述

于 2017-03-20T17:22:32.950 回答