为什么边框没有被应用到我的顶行(Aspose Cells)?

我有以下代码来添加边框到一行:

Range _range; _range = customerWorksheet.Cells.CreateRange("A1", "P1"); _range.SetOutlineBorders(CellBorderType.Hair, Color.Black); 

…但它不起作用 – 第一行(第一行)没有出现边框:

在这里输入图像说明

为什么不,我怎样才能添加这些边界,因为他们已经完成了工作表的其余部分?

下面是最上面一行的代码片断,展示了如何添加一个单元格:

 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); } 

看起来你正在混合的东西。 那么,如果您在代码中首先将轮廓边框应用于代码范围“A1:P1”,那么如果您再次将样式/格式应用于单元格或指定范围的轮廓边框(包括第一行),它肯定会覆盖您之前应用的现有格式。 所以,请确保你已经写好了你的代码,并且这两个代码段不会干扰其他的格式。

我在Aspose担任Support developer / Evangelist。