2017-01-16 86 views
0

我有下面的代码添加边框行:为什么边框没有应用到我的首行(Aspose Cells)?

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

...但它不工作 - 无国界出现在该顶行(行“1”):

enter image description here

不为什么,以及如何我可以添加这些边界,因为它们是在表的其余部分做了什么?

下面的码作为顶行的一个片段,示出一个单元是如何加入:

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

回答

1

它看起来像你在混合的东西。好吧,如果你正在申请外框的范围:在你的代码放在第一位“A1 P1”,然后如果你再应用样式/打印格式的单元或范围(包括第一行指定轮廓边框以及),它肯定会覆盖您之前应用的现有格式。所以,请确保你已经编写好你的代码,并且这两个代码段都不会干扰其他人的格式。

我的工作是支持开发者/布道者的Aspose。

+0

我添加了“再次”的代码,因为第一是行不通的:不加粗,不左对齐,无背景颜色。但所有这些事情现在都在起作用。边界不是,但是...为什么不呢?之前的边界是为整张纸张完成的,直到我将第一行重新格式化为止,因为第一次尝试不起作用。 –

相关问题