public void Test_WindowSizeEqualsOne_flushedRowHasMergedCell() { workbook = new SXSSFWorkbook(null, 1); // Window size 1 so only last row will be in memory sheet = workbook.CreateSheet() as SXSSFSheet; sheet.TrackAllColumnsForAutoSizing(); ICell a1 = CreateRowWithCellValues(sheet, 0, LONG_CELL_VALUE); assumeRequiredFontsAreInstalled(workbook, a1); sheet.AddMergedRegion(CellRangeAddress.ValueOf("A1:B1")); CreateRowWithCellValues(sheet, 1, SHORT_CELL_VALUE, SHORT_CELL_VALUE); /** * A B * 1 LONGMERGED * 2 SHORT SHORT */ sheet.AutoSizeColumn(0, useMergedCells); sheet.AutoSizeColumn(1, useMergedCells); if (useMergedCells) { // Excel and LibreOffice behavior: ignore merged cells for auto-sizing. // POI behavior: evenly distribute the column width among the merged columns. // each column must be auto-sized in order for the column widths // to add up to the best fit width. int colspan = 2; int expectedWidth = (10000 + 1000) / colspan; //average of 1_000 and 10_000 int minExpectedWidth = expectedWidth / 2; int maxExpectedWidth = expectedWidth * 3 / 2; assertColumnWidthStrictlyWithinRange(sheet.GetColumnWidth(0), minExpectedWidth, maxExpectedWidth); //short } else { assertColumnWidthStrictlyWithinRange(sheet.GetColumnWidth(0), COLUMN_WIDTH_THRESHOLD_BETWEEN_SHORT_AND_LONG, MAX_COLUMN_WIDTH); //long } assertColumnWidthStrictlyWithinRange(sheet.GetColumnWidth(1), 0, COLUMN_WIDTH_THRESHOLD_BETWEEN_SHORT_AND_LONG); //short }
public void Test_WindowSizeEqualsOne_lastRowIsWidest() { workbook = new SXSSFWorkbook(null, 1); // Window size 1 so only last row will be in memory sheet = workbook.CreateSheet() as SXSSFSheet; sheet.TrackAllColumnsForAutoSizing(); ICell cellRow0 = CreateRowWithCellValues(sheet, 0, SHORT_CELL_VALUE); assumeRequiredFontsAreInstalled(workbook, cellRow0); CreateRowWithCellValues(sheet, 1, LONG_CELL_VALUE); sheet.AutoSizeColumn(0, useMergedCells); assertColumnWidthStrictlyWithinRange(sheet.GetColumnWidth(0), COLUMN_WIDTH_THRESHOLD_BETWEEN_SHORT_AND_LONG, MAX_COLUMN_WIDTH); }
public void Test_WindowSizeDefault_AllRowsFitIntoWindowSize() { workbook = new SXSSFWorkbook(); sheet = workbook.CreateSheet() as SXSSFSheet; sheet.TrackAllColumnsForAutoSizing(); ICell cellRow0 = CreateRowWithCellValues(sheet, 0, LONG_CELL_VALUE); assumeRequiredFontsAreInstalled(workbook, cellRow0); CreateRowWithCellValues(sheet, 1, SHORT_CELL_VALUE); sheet.AutoSizeColumn(0, useMergedCells); assertColumnWidthStrictlyWithinRange(sheet.GetColumnWidth(0), COLUMN_WIDTH_THRESHOLD_BETWEEN_SHORT_AND_LONG, MAX_COLUMN_WIDTH); }