1

So given this code:

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

I would expect that the left border arround notWorkingCell (C1) would be removed. This is not happening:

Result of above code

How can I partially change the border of a merged cell? With pure Excel it is possible.

kuujinbo
  • 9,272
  • 3
  • 44
  • 57
Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111

1 Answers1

1

Looks like the border styles need to be explicitly set on the cell address within the merged cell itself, not the 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

kuujinbo
  • 9,272
  • 3
  • 44
  • 57