简体   繁体   English

为什么我范围的子部分无法添加边框(Aspose Cells)?

[英]Why is a subsection of my range failing to add borders (Aspose Cells)?

Based on code from here , I added the following: 根据此处的代码,我添加了以下内容:

string bottomRightRange = string.Format("F{0}", rowsUsed);
var range = locationWorksheet.Cells.CreateRange("A8", 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 = locationWorksheet.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);

That worked well - for the most part - but notice this: 效果很好-在大多数情况下-但请注意以下几点:

在此处输入图片说明

The last seven rows at the end (except for bottom border on the last row, and the right border for all of them) are not borderized. 末尾的最后七行(最后一行的底部边框和所有边框的右边框除外)没有边框。 Why not? 为什么不?

NOTE: bottomRightRange equates to "F94" in this case. 注意:在这种情况下, bottomRightRange等于“ F94”。

Why would a big chunk work right, then a small portion at the end not work as it should? 为什么一大块工作正常,而最后一小部分却无法正常工作?

The problem was (not obvious from the code above) that the sheet has a few preliminary rows used as header information. 问题是(从上面的代码中不明显)该工作表具有一些用作标题信息的初步行。 These have to be taken into account when looping. 循环时必须考虑这些因素。 So this: 所以这:

for (int r = range.FirstRow; r < range.RowCount; r++)

...needs to become this: ...需要成为这样:

for (int r = range.FirstRow; r < range.RowCount + FUDGE_FACTOR; r++`)

FUDGE_FACTOR is the number of rows used before the "real" data commences. FUDGE_FACTOR是“实际”数据开始之前使用的行数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM