diff --git a/.gitignore b/.gitignore index 0a69847dcbf..9771aa78cb0 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,9 @@ lib/ # Compiled module-info class-files /poi*/src/*/java9/*.class + +.DS_Store + +.project + +.classpath diff --git a/poi-ooxml-lite-agent/bin/.gitignore b/poi-ooxml-lite-agent/bin/.gitignore new file mode 100644 index 00000000000..ddf9c65631a --- /dev/null +++ b/poi-ooxml-lite-agent/bin/.gitignore @@ -0,0 +1 @@ +/main/ diff --git a/poi-ooxml/.gitignore b/poi-ooxml/.gitignore new file mode 100644 index 00000000000..ae3c1726048 --- /dev/null +++ b/poi-ooxml/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFEvaluationSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFEvaluationSheet.java index 3f19893da84..93530de5071 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFEvaluationSheet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFEvaluationSheet.java @@ -51,14 +51,14 @@ public int getLastRowNum() { */ @Override public boolean isRowHidden(int rowIndex) { - SXSSFRow row = _xs.getRow(rowIndex); + SXSSFRow row = (SXSSFRow) _xs.getRow(rowIndex); if (row == null) return false; return row.getZeroHeight(); } @Override public EvaluationCell getCell(int rowIndex, int columnIndex) { - SXSSFRow row = _xs.getRow(rowIndex); + SXSSFRow row = (SXSSFRow) _xs.getRow(rowIndex); if (row == null) { if (rowIndex <= _xs.getLastFlushedRowNum()) { throw new SXSSFFormulaEvaluator.RowFlushedException(rowIndex, _xs.getLastFlushedRowNum()); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFSheet.java index 73d05fa187a..42ddd9111ce 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFSheet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFSheet.java @@ -51,6 +51,7 @@ public class SXSSFSheet implements Sheet, OoxmlSheetExtensions { protected SheetDataWriter _writer; private int _randomAccessWindowSize = SXSSFWorkbook.DEFAULT_WINDOW_SIZE; protected AutoSizeColumnTracker _autoSizeColumnTracker; + private int outlineLevelRow; private int lastFlushedRowNumber = -1; private boolean allFlushed; private int leftMostColumn = SpreadsheetVersion.EXCEL2007.getLastColumnIndex(); @@ -210,13 +211,32 @@ public void removeRow(Row row) { /** * Returns the logical row (not physical) 0-based. If you ask for a row that is not * defined you get a null. This is to say row 4 represents the fifth row on a sheet. + * If the row is not created in this streaming sheet, instead is part of the XSSFSheet + * then this method takes the row from the XSSFSheet. * * @param rownum row to get (0-based) * @return Row representing the rownumber or null if its not defined on the sheet */ @Override - public SXSSFRow getRow(int rownum) { - return _rows.get(rownum); + public Row getRow(int rownum) { + Row row = _rows.get(rownum); + // BugZilla 67646: allow reading all the content also from template sheet + if (row == null) { + row = _sh.getRow(rownum); + } + return row; + } + + /** + * Returns the logical row (not physical) 0-based. If you ask for a row that is not + * defined you get a null. This is to say row 4 represents the fifth row on a sheet. + * + * @param rownum row to get (0-based) + * @return Row representing the rownumber or null if its not defined on the sheet + */ + private SXSSFRow getSXSSFRow(int rownum) { + SXSSFRow row = _rows.get(rownum); + return row; } /** @@ -249,7 +269,8 @@ public int getFirstRowNum() { */ @Override public int getLastRowNum() { - return _rows.isEmpty() ? -1 : _rows.lastKey(); + // BugZilla 67646 allow append + return _rows.isEmpty() ? _sh.getLastRowNum() : _rows.lastKey(); } /** @@ -1264,7 +1285,7 @@ public void setColumnGroupCollapsed(int columnNumber, boolean collapsed) { */ @Override public void groupColumn(int fromColumn, int toColumn) { - _sh.groupColumn(fromColumn, toColumn); + _sh.groupColumn(fromColumn,toColumn); } /** @@ -1317,14 +1338,16 @@ public void ungroupColumn(int fromColumn, int toColumn) { */ @Override public void groupRow(int fromRow, int toRow) { - int maxLevelRow = -1; for(SXSSFRow row : _rows.subMap(fromRow, toRow + 1).values()){ - final int level = row.getOutlineLevel() + 1; + int level = row.getOutlineLevel() + 1; row.setOutlineLevel(level); - maxLevelRow = Math.max(maxLevelRow, level); + + if(level > outlineLevelRow) { + outlineLevelRow = level; + } } - setWorksheetOutlineLevelRowIfNecessary((short) Math.min(Short.MAX_VALUE, maxLevelRow)); + setWorksheetOutlineLevelRow(); } /** @@ -1344,16 +1367,19 @@ public void groupRow(int fromRow, int toRow) { public void setRowOutlineLevel(int rownum, int level) { SXSSFRow row = _rows.get(rownum); row.setOutlineLevel(level); - setWorksheetOutlineLevelRowIfNecessary((short) Math.min(Short.MAX_VALUE, level)); + if(level > 0 && level > outlineLevelRow) { + outlineLevelRow = level; + setWorksheetOutlineLevelRow(); + } } - private void setWorksheetOutlineLevelRowIfNecessary(final short levelRow) { + private void setWorksheetOutlineLevelRow() { CTWorksheet ct = _sh.getCTWorksheet(); CTSheetFormatPr pr = ct.isSetSheetFormatPr() ? ct.getSheetFormatPr() : ct.addNewSheetFormatPr(); - if(levelRow > _sh.getSheetFormatPrOutlineLevelRow()) { - pr.setOutlineLevelRow(levelRow); + if(outlineLevelRow > 0) { + pr.setOutlineLevelRow((short)outlineLevelRow); } } @@ -1391,7 +1417,7 @@ public void setRowGroupCollapsed(int row, boolean collapse) { * @param rowIndex the zero based row index to collapse */ private void collapseRow(int rowIndex) { - SXSSFRow row = getRow(rowIndex); + SXSSFRow row = getSXSSFRow(rowIndex); if(row == null) { throw new IllegalArgumentException("Invalid row number("+ rowIndex + "). Row does not exist."); } else { @@ -1399,11 +1425,11 @@ private void collapseRow(int rowIndex) { // Hide all the columns until the end of the group int lastRow = writeHidden(row, startRow); - SXSSFRow lastRowObj = getRow(lastRow); + SXSSFRow lastRowObj = getSXSSFRow(lastRow); if (lastRowObj != null) { lastRowObj.setCollapsed(true); } else { - SXSSFRow newRow = createRow(lastRow); + SXSSFRow newRow = createRow(lastRow); newRow.setCollapsed(true); } } @@ -1429,14 +1455,13 @@ private int findStartOfRowOutlineGroup(int rowIndex) { return currentRow + 1; } - private int writeHidden(SXSSFRow xRow, int rowIndex) { + private int writeHidden(Row xRow, int rowIndex) { int level = xRow.getOutlineLevel(); - SXSSFRow currRow = getRow(rowIndex); - + SXSSFRow currRow = getSXSSFRow(rowIndex); while (currRow != null && currRow.getOutlineLevel() >= level) { currRow.setHidden(true); rowIndex++; - currRow = getRow(rowIndex); + currRow = getSXSSFRow(rowIndex); } return rowIndex; } @@ -2172,6 +2197,11 @@ public void setTabColor(int colorIndex){ pr.setTabColor(color); } + /** + * This method is not yet supported. + * + * @throws UnsupportedOperationException this method is not yet supported + */ @NotImplemented @Override public void shiftColumns(int startColumn, int endColumn, int n){ diff --git a/poi-scratchpad/bin/.gitignore b/poi-scratchpad/bin/.gitignore new file mode 100644 index 00000000000..7eed456bec8 --- /dev/null +++ b/poi-scratchpad/bin/.gitignore @@ -0,0 +1,2 @@ +/main/ +/test/ diff --git a/poi/.gitignore b/poi/.gitignore new file mode 100644 index 00000000000..ae3c1726048 --- /dev/null +++ b/poi/.gitignore @@ -0,0 +1 @@ +/bin/