Browse Source

Optional param maxRows added

release2.5.6
SEGECO\pdar 4 years ago
committed by Tony Qu
parent
commit
d34349f6cf
  1. 6
      main/SS/Util/SheetUtil.cs

6
main/SS/Util/SheetUtil.cs

@ -411,13 +411,17 @@ namespace NPOI.SS.Util
* @param useMergedCells whether to use merged cells
* @param firstRow 0-based index of the first row to consider (inclusive)
* @param lastRow 0-based index of the last row to consider (inclusive)
* @param maxRows limit the scope to maxRows rows to speed up the function, or leave 0 (optional)
* @return the width in pixels or -1 if cell is empty
*/
public static double GetColumnWidth(ISheet sheet, int column, bool useMergedCells, int firstRow, int lastRow)
public static double GetColumnWidth(ISheet sheet, int column, bool useMergedCells, int firstRow, int lastRow, int maxRows=0)
{
DataFormatter formatter = new DataFormatter();
int defaultCharWidth = GetDefaultCharWidth(sheet.Workbook);
// No need to explore the whole sheet: explore only the first maxRows lines
if (maxRows > 0 && lastRow - firstRow > maxRows) lastRow = firstRow + maxRows;
double width = -1;
for (int rowIdx = firstRow; rowIdx <= lastRow; ++rowIdx)
{

Loading…
Cancel
Save