分页行号

时间:2016-12-05 16:29:42

标签: c# epplus page-break

如何使用EPPlus找到分页符的位置,因为它只是

int firstPagebreakRowNo = worksheet.HPageBreaks[1].Location.Row;
Interop方法论中的

(我放弃了它,因为它太慢了)?

1 个答案:

答案 0 :(得分:0)

没有简单的方法我已经看到其他循环遍历行和列。您至少可以使用MaxRowsMaxColumns作为界限:

worksheet.Row(2).PageBreak = true;
worksheet.Row(3).PageBreak = true;

Console.Write("Row Breaks: ");
for (var i = 1; i <= ExcelPackage.MaxRows; i++)
    if (worksheet.Row(i).PageBreak)
        Console.Write($"{i} ");  // Writes: "Row Breaks: 2 3 "

worksheet.Column(4).PageBreak = true;
worksheet.Column(15).PageBreak = true;

Console.Write("Col Breaks: ");
for (var i = 1; i <= ExcelPackage.MaxColumns; i++)
    if (worksheet.Column(i).PageBreak)
        Console.Write($"{i} ");  // Writes: "Col Breaks: 4 15"