mirror of https://github.com/apache/poi.git
[bug-64327] bugfix in SXSSFSheet isColumnTrackedForAutoSizing for untracked. Thanks to Eugene Kortov. This closes #175
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876336 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
84ba670e27
commit
0ea6b0800d
|
@ -138,7 +138,8 @@ import org.apache.poi.util.Internal;
|
|||
* @since 3.14beta1
|
||||
*/
|
||||
public boolean isColumnTracked(int column) {
|
||||
return trackAllColumns || maxColumnWidths.containsKey(column);
|
||||
return (trackAllColumns && !untrackedColumns.contains(column))
|
||||
|| maxColumnWidths.containsKey(column);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -111,18 +111,7 @@ public class TestAutoSizeColumnTracker {
|
|||
|
||||
@Test
|
||||
public void trackAndUntrackAllColumns() {
|
||||
assumeTrue(tracker.getTrackedColumns().isEmpty());
|
||||
tracker.trackAllColumns();
|
||||
assertTrue(tracker.getTrackedColumns().isEmpty());
|
||||
|
||||
Row row = sheet.createRow(0);
|
||||
for (int column : columns) {
|
||||
row.createCell(column);
|
||||
}
|
||||
// implicitly track the columns
|
||||
tracker.updateColumnWidths(row);
|
||||
assertEquals(columns, tracker.getTrackedColumns());
|
||||
|
||||
createColumnsAndTrackThemAll();
|
||||
tracker.untrackAllColumns();
|
||||
assertTrue(tracker.getTrackedColumns().isEmpty());
|
||||
}
|
||||
|
@ -135,7 +124,19 @@ public class TestAutoSizeColumnTracker {
|
|||
tracker.untrackColumn(0);
|
||||
assertFalse(tracker.isColumnTracked(0));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void isColumnTrackedAndTrackAllColumns() {
|
||||
createColumnsAndTrackThemAll();
|
||||
tracker.untrackColumn(0);
|
||||
SortedSet<Integer> _newColumns = new TreeSet<>();
|
||||
_newColumns.add(1);
|
||||
_newColumns.add(3);
|
||||
SortedSet<Integer> newColumns = Collections.unmodifiableSortedSet(_newColumns);
|
||||
assertEquals(newColumns, tracker.getTrackedColumns());
|
||||
assertFalse(tracker.isColumnTracked(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTrackedColumns() {
|
||||
assumeTrue(tracker.getTrackedColumns().isEmpty());
|
||||
|
@ -214,4 +215,18 @@ public class TestAutoSizeColumnTracker {
|
|||
Assume.assumeTrue("Cannot verify autoSizeColumn() because the necessary Fonts are not installed on this machine: " + font,
|
||||
SheetUtil.canComputeColumnWidth(font));
|
||||
}
|
||||
|
||||
private void createColumnsAndTrackThemAll() {
|
||||
assumeTrue(tracker.getTrackedColumns().isEmpty());
|
||||
tracker.trackAllColumns();
|
||||
assertTrue(tracker.getTrackedColumns().isEmpty());
|
||||
|
||||
Row row = sheet.createRow(0);
|
||||
for (int column : columns) {
|
||||
row.createCell(column);
|
||||
}
|
||||
// implicitly track the columns
|
||||
tracker.updateColumnWidths(row);
|
||||
assertEquals(columns, tracker.getTrackedColumns());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -337,8 +337,9 @@ public class TestSXSSFSheetAutoSizeColumn {
|
|||
|
||||
sheet.trackColumnsForAutoSizing(columns);
|
||||
sheet.trackAllColumnsForAutoSizing();
|
||||
|
||||
sheet.untrackColumnForAutoSizing(0);
|
||||
|
||||
boolean untracked = sheet.untrackColumnForAutoSizing(0);
|
||||
assertTrue(untracked);
|
||||
try {
|
||||
sheet.autoSizeColumn(0, useMergedCells);
|
||||
fail("Should not be able to auto-size an explicitly untracked column");
|
||||
|
|
Loading…
Reference in New Issue