2016-12-05 80 views
0

如何找到使用EPPlus分頁符的位置,因爲它是簡單地分頁符行號

int firstPagebreakRowNo = worksheet.HPageBreaks[1].Location.Row; 

在互操作方法(我放棄了這個,因爲它是如此之慢)?

回答

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"