https://bz.apache.org/bugzilla/show_bug.cgi?id=57450
--- Comment #13 from Javen O'Neal <[email protected]> --- Created attachment 33307 --> https://bz.apache.org/bugzilla/attachment.cgi?id=33307&action=edit SXSSF Autosizing Fix, excludes tracking rows (In reply to Stefan Thurnherr from comment #9) > Attaching an updated patch file with a refactored solution (after discussion > on DEV mailing list). Main aspects: > * AutoSizeColumnTracker is now completely internal and "hidden" behind Sheet > API > * by default SXSSF auto-sizing behaviour is identical to Apache POI 3.13 > * to get the fixed SXSSF auto-sizing behaviour, one must explicitly call > ((SXSSFSheet)sheet).setAutoSizeTrackAllFlushedRows(true). This will track > all rows before they get flushed to disk > * Ability to manually add/remove rows to/from tracking is not implemented. > This should be handled in separate issue since it affects all types > (HSSF/XSSF/SXSSF) Stefan, I've been working on your patch, attachment 33277, removing the row-tracking code, adding more unit tests and java docs. The attached patch is what I've come up with. I wanted to minimize the amount of changes people will need to make to their SXSSFWorkbook code while still behaving consistently regardless of the number of rows in the random-access window. For example, if the random-access window is the first 5 rows, autoSizeColumn has all the information it needs in the window to compute the best-fit width without telling the AutoSizeColumnTracker the columns they wish to track. While I could allow that, as soon as the first row gets flushed, the user would need to track the columns of interest, though it's now too late. Additionally, this would look like a bug and would be difficult to track down because of the latent failure. It's better to have consistent behavior and fail early. In this patch, autoSizeColumn uses the AutoSizeColumnTracker to determine the best-fit width of all tracked flushed columns, then computes the best-fit column width in the active window, takes the maximum of the two values, and sets the column width to that value. The only change users will need to make to SXSSF code is to add sxSheet.trackAllColumnsForAutoSizing() or sxSheet.trackColumnForAutoSizing(column) (this is faster and uses less memory than tracking all columns) before calling autoSizeColumn. To have consistent behavior with H/XSSFSheet, tracking columns should occur immediately after the sheet is created and before the first row is created, though nothing stops it from occurring later (for example, if you want to exclude the first 3 rows from auto-sizing, you could wait to register the columns until after the first 3 rows have been flushed). Columns can be un-tracked as well, which is needed if user code auto-sizes several columns after writing just a few rows, and then doesn't auto-size anything else. Without the ability to untrack rows, computing the best-fit width for all the remaining rows would be wasted effort. # Scenario 1: Auto-size header row only > SXSSFWorkbook wb = new SXSSFWorkbook(); > SXSSFSheet sh = wb.createSheet(); > sh.trackAllColumnsForAutoSizing(); //do this immediately > Row header = sh.createRow(0); > // populate row with data > header.createCell(0).setCellValue("Some really long header"); > header.createCell(1).setCellValue("short"); > sh.autoSizeColumn(0); > sh.untrackAllColumns(); # Scenario 2: Exclude header row from auto-sizing > SXSSFWorkbook wb = new SXSSFWorkbook(); > SXSSFSheet sh = wb.createSheet(); > Row header = sh.createRow(0); > header.createCell(0).setCellValue("Some really long header"); > header.createCell(1).setCellValue("short"); > sh.flushRows(); > sh.trackAllColumnsForAutoSizing(); > for (int r=0; r<1000; r++) { > Row data = sh.createRow(r); > // populate row with data > data.createCell(0).setCellValue("Cell[r="+r + ",c=0]"); > } > sh.autoSizeColumn(0); Let me know if I need to make any changes before committing this new functionality. -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
