我有以下代码为行添加边框:
Range _range;
_range = customerWorksheet.Cells.CreateRange("A1", "P1");
_range.SetOutlineBorders(CellBorderType.Hair, Color.Black);
...但它不起作用 - 顶行(行“1”)上没有边框:
为什么不,以及如何添加这些边框,因为它们是为表格的其余部分完成的?
以下是该顶行的代码片段,显示了如何添加一个单元格:
Cell PAItemCell = customerWorksheet.Cells[rowToPopulate, PAITEMCODE_COL];
PAItemCell.PutValue(frbdbc.PAItemCode, true);
var paiStyle = PAItemCell.GetStyle();
paiStyle.Font.Name = fontForSheets;
paiStyle.IsTextWrapped = false;
PAItemCell.SetStyle(paiStyle);
以下是如何将边框添加到工作表的数据部分(理论上,它也适用于顶行,而不需要上述尝试):
private void BorderizeDataPortionOfCustomerSheet()
{
int rowsUsed = customerWorksheet.Cells.Rows.Count;
int colsUsed = SHIPVARIANCE_COL;
string bottomRightRange = string.Format("P{0}", rowsUsed);
var range = customerWorksheet.Cells.CreateRange("A1", bottomRightRange);
//Setting border for each cell in the range
var style = workBook.CreateStyle();
style.SetBorder(BorderType.BottomBorder, CellBorderType.Thin, Color.Black);
style.SetBorder(BorderType.LeftBorder, CellBorderType.Thin, Color.Black);
style.SetBorder(BorderType.RightBorder, CellBorderType.Thin, Color.Black);
style.SetBorder(BorderType.TopBorder, CellBorderType.Thin, Color.Black);
for (int r = range.FirstRow; r < range.RowCount; r++)
{
for (int c = range.FirstColumn; c < range.ColumnCount; c++)
{
Cell cell = customerWorksheet.Cells[r, c];
cell.SetStyle(style, new StyleFlag()
{
TopBorder = true,
BottomBorder = true,
LeftBorder = true,
RightBorder = true
});
}
}
//Setting outline border to range
range.SetOutlineBorder(BorderType.TopBorder, CellBorderType.Thin, Color.Black);
range.SetOutlineBorder(BorderType.BottomBorder, CellBorderType.Thin, Color.Black);
range.SetOutlineBorder(BorderType.LeftBorder, CellBorderType.Thin, Color.Black);
range.SetOutlineBorder(BorderType.RightBorder, CellBorderType.Thin, Color.Black);
customerWorksheet.FreezePanes(FIRST_DATA_ROW, SHORTNAME_COL, rowsUsed, colsUsed);
}
答案 0 :(得分:1)
看起来你正在混合这些东西。好吧,如果你将轮廓边界应用到一个范围&#34; A1:P1&#34;在您的代码中,如果您再次将样式/格式应用于单元格或指定范围的轮廓边框(包括第一行),它肯定会覆盖您之前应用的现有格式。所以,请确保您已编写好您的代码,并且两个代码段都不会互相干扰&#39;打印格式。
我是Aspose的支持开发人员/传播者。