ASF Bugzilla – Attachment 34945 Details for
Bug 60707
[PATCH] Reading very large excel files using StAX made easier - StreamingWorkbook
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Version 4: Added @NotImplemented. Added feature getColumnIndex
StreamedWorkbookV4.patch (text/plain), 152.39 KB, created by
Renjith R
on 2017-04-24 04:25:56 UTC
(
hide
)
Description:
Version 4: Added @NotImplemented. Added feature getColumnIndex
Filename:
MIME Type:
Creator:
Renjith R
Created:
2017-04-24 04:25:56 UTC
Size:
152.39 KB
patch
obsolete
>diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedCell.java b/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedCell.java >new file mode 100644 >index 0000000..dd368d1 >--- /dev/null >+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedCell.java >@@ -0,0 +1,528 @@ >+/* ==================================================================== >+ Licensed to the Apache Software Foundation (ASF) under one or more >+ contributor license agreements. See the NOTICE file distributed with >+ this work for additional information regarding copyright ownership. >+ The ASF licenses this file to You under the Apache License, Version 2.0 >+ (the "License"); you may not use this file except in compliance with >+ the License. You may obtain a copy of the License at >+ >+ http://www.apache.org/licenses/LICENSE-2.0 >+ >+ Unless required by applicable law or agreed to in writing, software >+ distributed under the License is distributed on an "AS IS" BASIS, >+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ See the License for the specific language governing permissions and >+ limitations under the License. >+==================================================================== */ >+package org.apache.poi.xssf.streaming.reader; >+ >+import java.util.Calendar; >+import java.util.Date; >+ >+import org.apache.poi.ss.formula.FormulaParseException; >+import org.apache.poi.ss.usermodel.Cell; >+import org.apache.poi.ss.usermodel.CellStyle; >+import org.apache.poi.ss.usermodel.CellType; >+import org.apache.poi.ss.usermodel.Comment; >+import org.apache.poi.ss.usermodel.Hyperlink; >+import org.apache.poi.ss.usermodel.RichTextString; >+import org.apache.poi.ss.usermodel.Row; >+import org.apache.poi.ss.usermodel.Sheet; >+import org.apache.poi.ss.util.CellAddress; >+import org.apache.poi.ss.util.CellRangeAddress; >+import org.apache.poi.util.NotImplemented; >+ >+/** >+ * Represents cell in a row >+ * Value of cell is represented as a string. >+ * >+ */ >+public class StreamedCell implements Cell{ >+ private String value; >+ private int cellNumber; >+ private CellType cellType; >+ >+ public StreamedCell(){ >+ >+ } >+ >+ /** >+ * <pre> >+ * Return cell value >+ * </pre> >+ * Return the value of a cell in String format. >+ * Value will be same as how it is represented in excel. >+ * @return String >+ */ >+ public String getValue() { >+ return value; >+ } >+ >+ public void setValue(String value) { >+ this.value = value; >+ } >+ >+ public String toString(){ >+ return value; >+ } >+ >+ /** >+ * <pre> >+ * Returns the cell number >+ * </pre> >+ * >+ * @return int, that represents cell number >+ */ >+ public int getCellNumber() { >+ return cellNumber; >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ * @param cellNumber >+ */ >+ public void setCellNumber(int cellNumber) { >+ this.cellNumber = cellNumber; >+ } >+ >+ /** >+ * <pre> >+ * Returns the column index of the cell. >+ * </pre> >+ * @return int that represents cell number >+ */ >+ public int getColumnIndex() { >+ return this.cellNumber; >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int getRowIndex() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Sheet getSheet() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Row getRow() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ * @param cellType >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setCellType(int cellType) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ * @param cellType >+ */ >+ @NotImplemented >+ public void setCellType(CellType cellType) { >+ //to avoid setting this by user >+ if(this.cellType == null) >+ this.cellType = cellType; >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int getCellType() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+ } >+ >+ /** >+ * <pre> >+ * Return the cell type. >+ * </pre> >+ * >+ * @return CellType >+ */ >+ @NotImplemented >+ public CellType getCellTypeEnum() { >+ return cellType; >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int getCachedFormulaResultType() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public CellType getCachedFormulaResultTypeEnum() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ * @param value >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setCellValue(double value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ * @param value >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setCellValue(Date value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ *@exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setCellValue(Calendar value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ *@exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setCellValue(RichTextString value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ *@exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setCellValue(String value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ *@exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setCellFormula(String formula) throws FormulaParseException { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory foot print. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public String getCellFormula() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory foot print. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public double getNumericCellValue() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory foot print. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Date getDateCellValue() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public RichTextString getRichStringCellValue() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+ } >+ >+ /** >+ * <pre> >+ * Returns the String value of cell content >+ * </pre> >+ * @return String, representing the value of cell >+ */ >+ public String getStringCellValue() { >+ return value; >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ *@exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setCellValue(boolean value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setCellErrorValue(byte value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory foot print. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean getBooleanCellValue() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public byte getErrorCellValue() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setCellStyle(CellStyle style) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public CellStyle getCellStyle() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setAsActiveCell() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public CellAddress getAddress() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+ } >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ *@exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setCellComment(Comment comment) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Comment getCellComment() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void removeCellComment() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Hyperlink getHyperlink() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ *@exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setHyperlink(Hyperlink link) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ *</pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void removeHyperlink() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public CellRangeAddress getArrayFormulaRange() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean isPartOfArrayFormulaGroup() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /*@Override >+ protected void finalize() throws Throwable { >+ super.finalize(); >+ value = null; >+ }*/ >+ >+ >+ >+} >diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedRow.java b/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedRow.java >new file mode 100644 >index 0000000..443f56f >--- /dev/null >+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedRow.java >@@ -0,0 +1,402 @@ >+/* ==================================================================== >+ Licensed to the Apache Software Foundation (ASF) under one or more >+ contributor license agreements. See the NOTICE file distributed with >+ this work for additional information regarding copyright ownership. >+ The ASF licenses this file to You under the Apache License, Version 2.0 >+ (the "License"); you may not use this file except in compliance with >+ the License. You may obtain a copy of the License at >+ >+ http://www.apache.org/licenses/LICENSE-2.0 >+ >+ Unless required by applicable law or agreed to in writing, software >+ distributed under the License is distributed on an "AS IS" BASIS, >+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ See the License for the specific language governing permissions and >+ limitations under the License. >+==================================================================== */ >+package org.apache.poi.xssf.streaming.reader; >+ >+import java.util.ArrayList; >+import java.util.Iterator; >+import java.util.List; >+ >+import org.apache.poi.ss.usermodel.Cell; >+import org.apache.poi.ss.usermodel.CellStyle; >+import org.apache.poi.ss.usermodel.CellType; >+import org.apache.poi.ss.usermodel.Row; >+import org.apache.poi.ss.usermodel.Sheet; >+import org.apache.poi.util.NotImplemented; >+ >+ >+/** >+ * Represents an excel row. >+ * Supports only minimal functionality in order to reduce memory consumption. >+ * >+ */ >+public class StreamedRow implements Row{ >+ private List<StreamedCell> cells; >+ private int rowNumber; >+ >+ public StreamedRow(int rowNumber) { >+ this.rowNumber = rowNumber; >+ } >+ >+ /** >+ * <pre> >+ * Used to get cells of a Row >+ * </pre> >+ * @return Iterator<Cell> >+ */ >+ public Iterator<StreamedCell> getCellIterator() { >+ if (cells == null) { >+ cells = new ArrayList<StreamedCell>(); >+ } >+ return cells.iterator(); >+ } >+ >+ /** >+ * <pre> >+ * Returns the row number >+ * </pre> >+ * @return int >+ */ >+ public int getRowNum() { >+ return rowNumber; >+ } >+ >+ public void setRowNum(int rowNumber) { >+ this.rowNumber = rowNumber; >+ } >+ >+ /** >+ * <pre> >+ * Returns String representation of row. >+ * o/p format[Row Number:<row num> --> <col_1>|<col_2>|.....|<col_n>] >+ * </pre> >+ * @return String >+ */ >+ public String toString() { >+ StringBuffer sb = new StringBuffer(250); >+ sb.append("Row Number:").append(rowNumber); >+ sb.append(" --> "); >+ if (cells != null) { >+ for (StreamedCell cell : cells) { >+ sb.append(cell.toString()); >+ sb.append(" | "); >+ } >+ } >+ >+ return sb.toString(); >+ } >+ >+/* @Override >+ protected void finalize() throws Throwable { >+ super.finalize(); >+ if (cells != null) { >+ cells.clear(); >+ cells = null; >+ } >+ }*/ >+ >+ /** >+ * <pre> >+ * Retuns the List of Cells contained in the row. >+ * </pre> >+ * @return List<StreamedCell> >+ */ >+ public List<StreamedCell> getCells() { >+ if (cells == null) { >+ cells = new ArrayList<StreamedCell>(); >+ } >+ return cells; >+ } >+ >+/** >+ * <pre> >+ * Will not be supported. Use getCellIterator() instead >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public Iterator<Cell> iterator() { >+ throw new UnsupportedOperationException("Operation not supported. Use getCellIterator() instead."); >+} >+ >+/** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+@NotImplemented >+public Cell createCell(int column) { >+ throw new UnsupportedOperationException("Operation not supported."); >+} >+ >+/** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public Cell createCell(int column, int type) { >+ throw new UnsupportedOperationException("Operation not supported."); >+} >+ >+/** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public Cell createCell(int column, CellType type) { >+ throw new UnsupportedOperationException("Operation not supported."); >+} >+ >+/** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public void removeCell(Cell cell) { >+ throw new UnsupportedOperationException("Operation not supported."); >+} >+ >+/** >+ * <pre> >+ * Returns the cell on specified cell number >+ * </pre> >+ * @return Cell >+ */ >+public Cell getCell(int cellnum) { >+ StreamedCell cell = null; >+ >+ if(cells != null){ >+ cell = cells.get(cellnum); >+ } >+ >+ return cell; >+} >+ >+/** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+public Cell getCell(int cellnum, MissingCellPolicy policy) { >+/* StreamedCell cell = null; >+ >+ if(cells != null){ >+ cell = cells.get(cellnum); >+ } >+ >+ switch(policy){ >+ case RETURN_NULL_AND_BLANK: >+ return cell; >+ case RETURN_BLANK_AS_NULL: >+ boolean isBlank = (cell != null && cell.getCellTypeEnum() == CellType.BLANK); >+ return (isBlank) ? null : cell; >+ case CREATE_NULL_AS_BLANK: >+ return (cell == null) ? createCell(cellnum, CellType.BLANK) : cell; >+ default: >+ throw new IllegalArgumentException("Illegal policy " + policy + " (" + policy.id + ")"); >+ }*/ >+ throw new UnsupportedOperationException("Not implememted yet."); >+} >+ >+/** >+ * <pre> >+ * Get the number of the first cell contained in this row. >+ * </pre> >+ * >+ * @return short representing the first logical cell in the row, >+ * or -1 if the row does not contain any cells. >+ */ >+public short getFirstCellNum() { >+ short firstCellNumber = -1; >+ >+ if(cells != null && cells.size() > 0){ >+ firstCellNumber = (short)cells.get(0).getCellNumber(); >+ } >+ >+ return firstCellNumber; >+} >+ >+/** >+ * <pre> >+ * Gets the index of the last cell contained in this row <b>PLUS ONE</b>. >+ * </pre> >+ * >+ * @return short representing the last logical cell in the row, >+ * or -1 if the row does not contain any cells. >+ */ >+public short getLastCellNum() { >+ short lastCellNumber = -1; >+ >+ if(cells != null && cells.size() > 0){ >+ lastCellNumber = (short)(cells.get((cells.size()-1)).getCellNumber()+1); >+ } >+ >+ return lastCellNumber; >+} >+ >+/** >+ * <pre> >+ * Gets the number of defined cells (NOT number of cells in the actual row!). >+ * That is to say if only columns 0,4,5 have values then there would be 3. >+ * </pre> >+ * @return int representing the number of defined cells in the row. >+ */ >+public int getPhysicalNumberOfCells() { >+ if(cells != null)return cells.size(); >+ else return 0; >+} >+ >+/** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public void setHeight(short height) { >+ throw new UnsupportedOperationException("Operation not supported."); >+} >+ >+/** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public void setZeroHeight(boolean zHeight) { >+ throw new UnsupportedOperationException("Operation not supported."); >+} >+ >+/** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public boolean getZeroHeight() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+} >+ >+/** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public void setHeightInPoints(float height) { >+ throw new UnsupportedOperationException("Operation not supported."); >+} >+ >+/** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public short getHeight() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+} >+ >+/** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public float getHeightInPoints() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+} >+ >+/** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public boolean isFormatted() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+} >+ >+/** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public CellStyle getRowStyle() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+} >+ >+/** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public void setRowStyle(CellStyle style) { >+ throw new UnsupportedOperationException("Operation not supported."); >+} >+ >+/** >+ * <pre> >+ * Not supported right now. Use getCellIterator instead >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public Iterator<Cell> cellIterator() { >+ throw new UnsupportedOperationException("Operation not supported.Use getCellIterator instead."); >+} >+ >+/** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public Sheet getSheet() { >+ throw new UnsupportedOperationException("Operation not supported."); >+} >+ >+/** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+@NotImplemented >+public int getOutlineLevel() { >+ throw new UnsupportedOperationException("Not implememted yet."); >+} >+ >+ >+} >diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedSheet.java b/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedSheet.java >new file mode 100644 >index 0000000..f649ee5 >--- /dev/null >+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedSheet.java >@@ -0,0 +1,1645 @@ >+/* ==================================================================== >+ Licensed to the Apache Software Foundation (ASF) under one or more >+ contributor license agreements. See the NOTICE file distributed with >+ this work for additional information regarding copyright ownership. >+ The ASF licenses this file to You under the Apache License, Version 2.0 >+ (the "License"); you may not use this file except in compliance with >+ the License. You may obtain a copy of the License at >+ >+ http://www.apache.org/licenses/LICENSE-2.0 >+ >+ Unless required by applicable law or agreed to in writing, software >+ distributed under the License is distributed on an "AS IS" BASIS, >+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ See the License for the specific language governing permissions and >+ limitations under the License. >+==================================================================== */ >+package org.apache.poi.xssf.streaming.reader; >+ >+import java.util.ArrayList; >+import java.util.Collection; >+import java.util.Iterator; >+import java.util.List; >+import java.util.Map; >+ >+import javax.xml.stream.XMLEventReader; >+import javax.xml.stream.XMLStreamException; >+import javax.xml.stream.events.XMLEvent; >+ >+import org.apache.poi.ss.usermodel.AutoFilter; >+import org.apache.poi.ss.usermodel.Cell; >+import org.apache.poi.ss.usermodel.CellRange; >+import org.apache.poi.ss.usermodel.CellStyle; >+import org.apache.poi.ss.usermodel.Comment; >+import org.apache.poi.ss.usermodel.DataValidation; >+import org.apache.poi.ss.usermodel.DataValidationHelper; >+import org.apache.poi.ss.usermodel.Drawing; >+import org.apache.poi.ss.usermodel.Footer; >+import org.apache.poi.ss.usermodel.Header; >+import org.apache.poi.ss.usermodel.Hyperlink; >+import org.apache.poi.ss.usermodel.PrintSetup; >+import org.apache.poi.ss.usermodel.Row; >+import org.apache.poi.ss.usermodel.Sheet; >+import org.apache.poi.ss.usermodel.SheetConditionalFormatting; >+import org.apache.poi.ss.usermodel.Workbook; >+import org.apache.poi.ss.util.CellAddress; >+import org.apache.poi.ss.util.CellRangeAddress; >+import org.apache.poi.ss.util.PaneInformation; >+import org.apache.poi.util.NotImplemented; >+import org.apache.poi.xssf.model.SharedStringsTable; >+import org.apache.poi.xssf.model.StylesTable; >+ >+/** >+ * Represents an excel sheet. >+ * StreamedSheet currently supports only the minimal functionalities as >+ * additional features requires caching of sheet data, which consumes memory. >+ * >+ */ >+public class StreamedSheet implements Sheet{ >+ private XMLEventReader xmlParser; >+ private SharedStringsTable sharedStringsTable; >+ private StylesTable stylesTable; >+ private int numberOfColumns; >+ private int sheetNumber; >+ private String sheetName; >+ private StreamedSheetEventHandler eventHandler = null; >+ >+ /** >+ * <pre> >+ * Fetch all rows from the excel. >+ * </pre> >+ * >+ * This method consumes only less memory, but it is >+ * advisable to use it only for small excel files, since >+ * it will fetch all rows in a single call. >+ * >+ * @return Iterator<Row> >+ * @throws XMLStreamException >+ */ >+ public Iterator<StreamedRow> getAllRows() throws XMLStreamException{ >+ return getAllRows(this, sharedStringsTable, stylesTable); >+ } >+ >+ /** >+ * <pre> >+ * Used to fetch N number of rows. >+ * </pre> >+ * >+ * Recommended method to reduce memory utilization. >+ * It allows to read big excel files in batch. >+ * This gives control to the user to process the records already fetched, >+ * before fetching next set of records. >+ * After reading N records, invoke the same method with number of rows to be >+ * fetched to get the next set of rows. >+ * <br> >+ * >+ * *********************Usage**************************** >+ * Iterator<StreamedRow> rows = sheet.getNRows(1); >+ * <br> >+ * while(rows.hasNext()){ //read the first 1 row >+ * <br> >+ * StreamedRow row = rows.next(); >+ * <br> >+ * } >+ * <br> >+ * rows = sheet.getNRows(10); >+ * <br> >+ * while(rows.hasNext()){ //read the next 10 rows >+ * <br> >+ * StreamedRow row = rows.next(); >+ * <br> >+ * } >+ * >+ * @param numberOfRows >+ * @return Iterator<Row> >+ * @throws XMLStreamException >+ */ >+ public Iterator<StreamedRow> getNRows(int numberOfRows) throws XMLStreamException{ >+ return getNRows(this, eventHandler, numberOfRows); >+ } >+ >+ public boolean hasMoreRows(){ >+ return xmlParser.hasNext(); >+ } >+ >+ >+ public XMLEventReader getXmlParser() { >+ return xmlParser; >+ } >+ >+ public void setXmlParser(XMLEventReader xmlParser) { >+ this.xmlParser = xmlParser; >+ } >+ >+ public void setSharedStringsTable(SharedStringsTable sharedStringsTable) { >+ this.sharedStringsTable = sharedStringsTable; >+ } >+ >+ public void setStylesTable(StylesTable stylesTable) { >+ this.stylesTable = stylesTable; >+ } >+ >+ public void createEventHandler(){ >+ eventHandler = new StreamedSheetEventHandler(sharedStringsTable, stylesTable); >+ } >+ >+ >+ public int getNumberOfColumns() { >+ return numberOfColumns; >+ } >+ >+ >+ public void setNumberOfColumns(int numberOfColumns) { >+ this.numberOfColumns = numberOfColumns; >+ } >+ >+ >+ public int getSheetNumber() { >+ return sheetNumber; >+ } >+ >+ >+ public void setSheetNumber(int sheetNumber) { >+ this.sheetNumber = sheetNumber; >+ } >+ >+/* @Override >+ protected void finalize() throws Throwable { >+ super.finalize(); >+ >+ xmlParser = null; >+ sharedStringsTable = null; >+ stylesTable = null; >+ eventHandler = null; >+ >+ }*/ >+ >+ /** >+ * reads all data from sheet >+ * @param xmlParser >+ * @param sharedStringsTable >+ * @param stylesTable >+ * @return >+ * @throws XMLStreamException >+ */ >+ private Iterator<StreamedRow> getAllRows(StreamedSheet sheet, >+ SharedStringsTable sharedStringsTable, StylesTable stylesTable) throws XMLStreamException { >+ List<StreamedRow> dataList = new ArrayList<StreamedRow>(); >+ StreamedSheetEventHandler eventHandler = new StreamedSheetEventHandler(sharedStringsTable, stylesTable); >+ while(sheet.getXmlParser().hasNext()){ >+ XMLEvent event = sheet.getXmlParser().nextEvent(); >+ eventHandler.handleEvent(event); >+ if(eventHandler.isEndOfRow()){ >+ dataList.add(eventHandler.getRow()); >+ eventHandler.setEndOfRow(false); >+ } >+ sheet.setNumberOfColumns(eventHandler.getNumberOfColumns()); >+ } >+ >+ return dataList.iterator(); >+ } >+ >+ /** >+ * Reads N Rows from excel >+ * @param sheet >+ * @param sharedStringsTable >+ * @param stylesTable >+ * @param numberOFRows >+ * @return >+ * @throws XMLStreamException >+ */ >+ private Iterator<StreamedRow> getNRows(StreamedSheet sheet, StreamedSheetEventHandler eventHandler, int numberOfRows) >+ throws XMLStreamException { >+ List<StreamedRow> dataList = new ArrayList<StreamedRow>(); >+ while(sheet.getXmlParser().hasNext()){ >+ XMLEvent event = sheet.getXmlParser().nextEvent(); >+ eventHandler.handleEvent(event); >+ if(eventHandler.isEndOfRow()){ >+ dataList.add(eventHandler.getRow()); >+ eventHandler.setEndOfRow(false); >+ } >+ sheet.setNumberOfColumns(eventHandler.getNumberOfColumns()); >+ if(dataList.size() == numberOfRows){ >+ break; >+ } >+ } >+ >+ return dataList.iterator(); >+ } >+ >+ /** >+ * Not supported. Refer getAllRows or getNRows >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Iterator<Row> iterator() { >+ throw new UnsupportedOperationException("Not supported. Refer getAllRows or getNRows"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Row createRow(int rownum) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void removeRow(Row row) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Row getRow(int rownum) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int getPhysicalNumberOfRows() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int getFirstRowNum() { >+ throw new UnsupportedOperationException("Not yet implemented."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int getLastRowNum() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setColumnHidden(int columnIndex, boolean hidden) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean isColumnHidden(int columnIndex) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setRightToLeft(boolean value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean isRightToLeft() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setColumnWidth(int columnIndex, int width) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ */ >+ @NotImplemented >+ public int getColumnWidth(int columnIndex) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public float getColumnWidthInPixels(int columnIndex) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setDefaultColumnWidth(int width) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int getDefaultColumnWidth() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public short getDefaultRowHeight() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public float getDefaultRowHeightInPoints() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setDefaultRowHeight(short height) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ public void setDefaultRowHeightInPoints(float height) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public CellStyle getColumnStyle(int column) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public int addMergedRegion(CellRangeAddress region) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public int addMergedRegionUnsafe(CellRangeAddress region) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void validateMergedRegions() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setVerticallyCenter(boolean value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setHorizontallyCenter(boolean value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean getHorizontallyCenter() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean getVerticallyCenter() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void removeMergedRegion(int index) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void removeMergedRegions(Collection<Integer> indices) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int getNumMergedRegions() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ public CellRangeAddress getMergedRegion(int index) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public List<CellRangeAddress> getMergedRegions() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported. Use getAllRows or getNRows >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Iterator<Row> rowIterator() { >+ throw new UnsupportedOperationException("Operation not supported.Use getAllRows or getNRows."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ public void setForceFormulaRecalculation(boolean value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean getForceFormulaRecalculation() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setAutobreaks(boolean value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setDisplayGuts(boolean value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setDisplayZeros(boolean value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean isDisplayZeros() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setFitToPage(boolean value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setRowSumsBelow(boolean value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setRowSumsRight(boolean value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean getAutobreaks() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint.. >+ * </pre> >+ */ >+ @NotImplemented >+ public boolean getDisplayGuts() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean getFitToPage() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean getRowSumsBelow() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean getRowSumsRight() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean isPrintGridlines() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setPrintGridlines(boolean show) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean isPrintRowAndColumnHeadings() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setPrintRowAndColumnHeadings(boolean show) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public PrintSetup getPrintSetup() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Header getHeader() { >+ // <TO DO> >+ throw new UnsupportedOperationException("Not implemented yet."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Footer getFooter() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setSelected(boolean value) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public double getMargin(short margin) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setMargin(short margin, double size) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean getProtect() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void protectSheet(String password) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean getScenarioProtect() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setZoom(int numerator, int denominator) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setZoom(int scale) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public short getTopRow() { >+ //<TO DO> >+ throw new UnsupportedOperationException("Not implemented yet."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ public short getLeftCol() { >+ //<TO DO> >+ throw new UnsupportedOperationException("Not implemented yet."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void showInPane(int toprow, int leftcol) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void shiftRows(int startRow, int endRow, int n) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void shiftRows(int startRow, int endRow, int n, >+ boolean copyRowHeight, boolean resetOriginalRowHeight) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void createFreezePane(int colSplit, int rowSplit, >+ int leftmostColumn, int topRow) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void createFreezePane(int colSplit, int rowSplit) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void createSplitPane(int xSplitPos, int ySplitPos, >+ int leftmostColumn, int topRow, int activePane) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public PaneInformation getPaneInformation() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setDisplayGridlines(boolean show) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean isDisplayGridlines() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setDisplayFormulas(boolean show) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean isDisplayFormulas() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setDisplayRowColHeadings(boolean show) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean isDisplayRowColHeadings() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setRowBreak(int row) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean isRowBroken(int row) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void removeRowBreak(int row) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int[] getRowBreaks() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int[] getColumnBreaks() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setColumnBreak(int column) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean isColumnBroken(int column) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void removeColumnBreak(int column) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setColumnGroupCollapsed(int columnNumber, boolean collapsed) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void groupColumn(int fromColumn, int toColumn) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void ungroupColumn(int fromColumn, int toColumn) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void groupRow(int fromRow, int toRow) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void ungroupRow(int fromRow, int toRow) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setRowGroupCollapsed(int row, boolean collapse) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setDefaultColumnStyle(int column, CellStyle style) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void autoSizeColumn(int column) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void autoSizeColumn(int column, boolean useMergedCells) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Comment getCellComment(int row, int column) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Comment getCellComment(CellAddress ref) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * WNot supported due to memory footprint.. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Map<CellAddress, ? extends Comment> getCellComments() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Drawing getDrawingPatriarch() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Drawing createDrawingPatriarch() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Will not be supported due to memory constraints >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Workbook getWorkbook() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Returns sheet name >+ * </pre> >+ * @return String >+ */ >+ public String getSheetName() { >+ return sheetName; >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * >+ */ >+ @NotImplemented >+ public void setSheetName(String sheetName) { >+ //to avoid setting sheet name by user >+ if(this.sheetName == null)this.sheetName = sheetName; >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean isSelected() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public CellRange<? extends Cell> setArrayFormula(String formula, >+ CellRangeAddress range) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public CellRange<? extends Cell> removeArrayFormula(Cell cell) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public DataValidationHelper getDataValidationHelper() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public List<? extends DataValidation> getDataValidations() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void addValidationData(DataValidation dataValidation) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public AutoFilter setAutoFilter(CellRangeAddress range) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public SheetConditionalFormatting getSheetConditionalFormatting() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public CellRangeAddress getRepeatingRows() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ */ >+ @NotImplemented >+ public CellRangeAddress getRepeatingColumns() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setRepeatingRows(CellRangeAddress rowRangeRef) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setRepeatingColumns(CellRangeAddress columnRangeRef) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int getColumnOutlineLevel(int columnIndex) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Hyperlink getHyperlink(int row, int column) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Hyperlink getHyperlink(CellAddress addr) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ >+ /** >+ * <pre> >+ * Will not be supported due to memory constraints >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public List<? extends Hyperlink> getHyperlinkList() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public CellAddress getActiveCell() { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setActiveCell(CellAddress address) { >+ throw new UnsupportedOperationException("Operation not supported."); >+ } >+ >+ >+ >+ >+ >+ >+} >diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedSheetEventHandler.java b/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedSheetEventHandler.java >new file mode 100644 >index 0000000..86bec07 >--- /dev/null >+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedSheetEventHandler.java >@@ -0,0 +1,447 @@ >+/* ==================================================================== >+ Licensed to the Apache Software Foundation (ASF) under one or more >+ contributor license agreements. See the NOTICE file distributed with >+ this work for additional information regarding copyright ownership. >+ The ASF licenses this file to You under the Apache License, Version 2.0 >+ (the "License"); you may not use this file except in compliance with >+ the License. You may obtain a copy of the License at >+ >+ http://www.apache.org/licenses/LICENSE-2.0 >+ >+ Unless required by applicable law or agreed to in writing, software >+ distributed under the License is distributed on an "AS IS" BASIS, >+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ See the License for the specific language governing permissions and >+ limitations under the License. >+==================================================================== */ >+package org.apache.poi.xssf.streaming.reader; >+ >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.List; >+import java.util.Map; >+import java.util.Properties; >+ >+import javax.xml.namespace.QName; >+import javax.xml.stream.events.Attribute; >+import javax.xml.stream.events.Characters; >+import javax.xml.stream.events.EndElement; >+import javax.xml.stream.events.StartElement; >+import javax.xml.stream.events.XMLEvent; >+ >+import org.apache.poi.ss.usermodel.Cell; >+import org.apache.poi.ss.usermodel.CellType; >+import org.apache.poi.ss.usermodel.DataFormatter; >+import org.apache.poi.xssf.model.SharedStringsTable; >+import org.apache.poi.xssf.model.StylesTable; >+import org.apache.poi.xssf.usermodel.XSSFCellStyle; >+import org.apache.poi.xssf.usermodel.XSSFRichTextString; >+ >+/** >+ * Handler class that handles the event generated by StAX parser >+ * >+ */ >+public class StreamedSheetEventHandler { >+ >+ private boolean isEndOfRow = false; >+ private boolean isRow = false; >+ //private boolean mergeCell = false; >+ >+ private String formatString = null; >+ private int formatIndex = 0; >+ private String cellContentType; >+ private int rowNumber = 0; >+ private int numberOfColumns = 0; >+ private List<String> cellPositions = null; >+ private String currentCellPosition = null; >+ private int previousCellIndex = -1; >+ //private List<String> mergeList = null; //merge cell not supported right now. Complexity involved if multiple rows are merged. >+ >+ private SharedStringsTable sharedStringsTable; >+ private StylesTable stylesTable; >+ >+ private DataFormatter formatter = new DataFormatter(); >+ private Properties properties = new Properties(); >+ private Map<String, String> attributes = new HashMap<String, String>(); >+ private StringBuffer sb = new StringBuffer(250); >+ private List<String> dateFormatsAry = new ArrayList<String>(); >+ >+ private StreamedRow row; >+ private StreamedCell cell; >+ >+ private final String dateFormat = "m/d/yy|DD/MM/YY|[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy|m/d;@|m/d/yy;@|mm/dd/yy;@|" >+ + "[$-409]d\\-mmm;@|[$-409]d\\-mmm\\-yy;@|[$-409]dd\\-mmm\\-yy;@|[$-409]mmm\\-yy;@|[$-409]mmmm\\-yy;@|" >+ + "[$-409]mmmm\\ d\\,\\ yyyy;@|[$-409]m/d/yy\\ h:mm\\ AM/PM;@|m/d/yy\\ h:mm;@|[$-409]mmmmm;@|" >+ + "[$-409]mmmmm\\-yy;@|m/d/yyyy;@|[$-409]d\\-mmm\\-yyyy;@|[$-F400]h:mm:ss\\ AM/PM|" >+ + "h:mm;@|[$-409]h:mm\\ AM/PM;@|h:mm:ss;@|[$-409]h:mm:ss\\ AM/PM;@|mm:ss.0;@|[h]:mm:ss;@|" >+ + "[$-409]m/d/yy\\ h:mm\\ AM/PM;@|DD/MM/YYYY"; >+ >+ public static final String DEFAULT_CELL_TYPE = "DEFAULT"; >+ public static final String STRING_CELL_TYPE = "STRING"; >+ public static final String BOOLEAN_CELL_TYPE = "BOOLEAN"; >+ public static final String DATE_CELL_TYPE = "DATE"; >+ public static final String FORMULA_CELL_TYPE = "FORMULA"; >+ public static final String NUMERIC_CELL_TYPE = "NUMERIC"; >+ >+ >+ /** >+ * Constructor >+ * @param sharedStringsTable >+ * @param stylesTable >+ */ >+ public StreamedSheetEventHandler(SharedStringsTable sharedStringsTable, StylesTable stylesTable){ >+ this.sharedStringsTable = sharedStringsTable; >+ this.stylesTable = stylesTable; >+ /*try{ >+ properties.load(getClass().getClassLoader().getResourceAsStream("excelreader.properties")); >+ }catch(Exception e){ >+ e.printStackTrace(); >+ }*/ >+ >+ /*if(properties.get("date.formatStrings") != null){ >+ dateFormat = properties.get("date.formatStrings").toString(); >+ }*/ >+ >+ dateFormatsAry.addAll(Arrays.asList(dateFormat.split("\\|"))); >+ >+ } >+ >+ /** >+ * Handler method for handling the event generated for StAX parser. >+ * For each XML event(Start Tag, End Tag & Characters), StAX parser will >+ * generate event. This event will be handled by this method. >+ * Attributes of each element are put in a map with key as attribute >+ * and value as attribute value. >+ * @param event >+ */ >+ public void handleEvent(XMLEvent event){ >+ switch(event.getEventType()){ >+ case XMLEvent.START_ELEMENT: >+ StartElement startElemet = event.asStartElement(); >+ QName startName = startElemet.getName(); >+ String name = startName.getLocalPart(); >+ Iterator<Attribute> iterator = startElemet.getAttributes(); >+ while(iterator.hasNext()){ >+ Attribute attribute = iterator.next(); >+ attributes.put(attribute.getName().getLocalPart(), attribute.getValue()); >+ } >+ if((name.trim().equals("row")) && (attributes.size() > 0)){ >+ isRow = true; >+ } >+ >+ /*else if(name.trim().equals("mergeCell")){ >+ mergeCell = true; >+ } >+ >+ if(isRow || mergeCell){ >+ startElement(name); >+ }*/ >+ >+ if(isRow){ >+ startElement(name); >+ } >+ break; >+ case XMLEvent.CHARACTERS: >+ Characters chars = event.asCharacters(); >+ if(isRow){ >+ characters(chars.getData()); >+ } >+ break; >+ case XMLEvent.END_ELEMENT: >+ EndElement endElement = event.asEndElement(); >+ QName endName = endElement.getName(); >+ String endTageName = endName.getLocalPart(); >+ endElement(endTageName); >+ attributes.clear(); >+ break; >+ } >+ } >+ >+ /** >+ * All the start element events are handled here. >+ * It identifies the things like rowNumber, cell content type etc >+ * @param name >+ */ >+ private void startElement(String name) { >+ if(name.equals("row")) { >+ previousCellIndex = -1; >+ isEndOfRow = false; >+ rowNumber = (Integer.parseInt(attributes.get("r")) - 1); >+ row = new StreamedRow(rowNumber); >+ if(rowNumber == 0){ >+ cellPositions = new ArrayList<String>(); >+ } >+ }else if(name.equals("c")){ >+ String cellPosition = attributes.get("r").toUpperCase(); >+ cellPosition = cellPosition.replaceAll(String.valueOf(rowNumber+1), "").trim(); >+ currentCellPosition = cellPosition; >+ if(rowNumber == 0){ >+ numberOfColumns ++; >+ cellPositions.add(cellPosition); >+ } >+ >+ cellContentType = getCellContentType(); >+ }else if(name.equals("f")){ >+ cellContentType = FORMULA_CELL_TYPE; >+ } >+ >+ /*else if(name.equals("mergeCell")){ >+ if(mergeList == null){ >+ mergeList = >+ } >+ }*/ >+ } >+ >+ >+ /** >+ * This method is invoked on end element event. >+ * Mostly used for setting the default values before handling >+ * next start element. >+ * All data captured in characters event are stored here. >+ * Data will be stored only on reaching the end element. >+ * @param name >+ */ >+ private void endElement(String name) { >+ if(name.equals("c")){ >+ if(isRow){ >+ storeData(sb.toString()); >+ } >+ cellContentType = DEFAULT_CELL_TYPE; >+ formatString = null; >+ formatIndex = 0; >+ currentCellPosition = null; >+ previousCellIndex++; >+ sb.delete(0, sb.length()); >+ }else if(name.equals("row")){ >+ isEndOfRow = true; >+ isRow = false; >+ }else if(name.equals("f")){ >+ cellContentType = DEFAULT_CELL_TYPE; >+ } >+ >+ /*else if(name.equals("mergeCell")){ >+ mergeCell = false; >+ }*/ >+ } >+ >+ /** >+ * Captures the data >+ * @param data >+ */ >+ private void characters(String data) { >+ if(!(cellContentType.equals(FORMULA_CELL_TYPE))){ >+ sb.append(data); >+ } >+ } >+ >+ /** >+ * Creates cells and store data >+ * @param data >+ */ >+ private void storeData(String data){ >+ if (!(cellContentType.equals(FORMULA_CELL_TYPE))) { >+ if(cellContentType.equals(STRING_CELL_TYPE)){ >+ data = getStringData(data); >+ }else if(cellContentType.equals(DATE_CELL_TYPE)){ >+ data = getDateAsString(data); >+ }else if(cellContentType.equals(BOOLEAN_CELL_TYPE)){ >+ if(data.trim().equals("1")){ >+ data = "TRUE"; >+ }else if(data.trim().equals("0")){ >+ data = "FALSE"; >+ }else if(data.trim().equals("")){ >+ data = null; >+ }else{ >+ try{ >+ int value = Integer.parseInt(data); >+ if(value > 0){ >+ data = "TRUE"; >+ } >+ }catch(Exception e){ >+ data = null; >+ } >+ } >+ } >+ >+ if(cellPositions != null){ >+ fillEmptyCells(); >+ } >+ >+ cell = new StreamedCell(); >+ cell.setValue(data); >+ cell.setCellNumber(previousCellIndex+1); >+ setCellType(cell, cellContentType, data); >+ row.getCells().add(cell); >+ >+ } >+ } >+ >+ /** >+ * Set the content type of cell. >+ * >+ * >+ * @param cell >+ * @param contentType >+ * @param data >+ */ >+ private void setCellType(Cell cell, String contentType, String data){ >+ >+ if(contentType.equals(BOOLEAN_CELL_TYPE)){ >+ cell.setCellType(CellType.BOOLEAN); >+ } >+ else if(contentType.equals(STRING_CELL_TYPE)){ >+ if(data != null && data.trim().isEmpty()){ >+ cell.setCellType(CellType.BLANK); >+ }else{ >+ cell.setCellType(CellType.STRING); >+ } >+ }else if(contentType.equals(FORMULA_CELL_TYPE)) { >+ cell.setCellType(CellType.FORMULA); >+ } >+ >+ } >+ >+ >+ /** >+ * Identifies the cell content type >+ * @return >+ */ >+ private String getCellContentType(){ >+ String cellConentType = DEFAULT_CELL_TYPE; >+ String cellType = attributes.get("t"); >+ if((null != cellType) && (cellType.equals("s"))){ >+ cellConentType = STRING_CELL_TYPE; >+ }else if((null != cellType) && (equals("b"))){ >+ cellConentType = BOOLEAN_CELL_TYPE; >+ }else{ >+ >+ if(checkForDate()){ >+ cellConentType = DATE_CELL_TYPE; >+ }else if(checkForBoolean()){ >+ cellConentType = BOOLEAN_CELL_TYPE; >+ } >+ } >+ return cellConentType; >+ } >+ >+ >+ >+ /** >+ * Identifies if the given cell is a boolean or not >+ * @return >+ */ >+ private boolean checkForBoolean(){ >+ String cellStyleType = attributes.get("s"); >+ if(cellStyleType != null){ >+ int styleIndex = Integer.parseInt(cellStyleType); >+ XSSFCellStyle style = stylesTable.getStyleAt(styleIndex); >+ formatIndex = style.getDataFormat(); >+ formatString = style.getDataFormatString(); >+ if(formatString.contains("TRUE")){ >+ return true; >+ }else{ >+ return false; >+ } >+ }else{ >+ return false; >+ } >+ } >+ >+ /** >+ * identifies if the given cell is a Date cell or not >+ * @return >+ */ >+ private boolean checkForDate(){ >+ boolean isDate = false; >+ String cellStyleType = attributes.get("s"); >+ if(cellStyleType != null){ >+ int styleIndex = Integer.parseInt(cellStyleType); >+ XSSFCellStyle style = stylesTable.getStyleAt(styleIndex); >+ formatIndex = style.getDataFormat(); >+ formatString = style.getDataFormatString(); >+ if(dateFormatsAry.contains(formatString.trim())){ >+ isDate = true; >+ } >+ } >+ >+ return isDate; >+ } >+ >+ >+ /** >+ * fetches the String data from SharedStringsTable.xml >+ * @param data >+ * @return >+ */ >+ private String getStringData(String data){ >+ int index = Integer.parseInt(data); >+ return new XSSFRichTextString(sharedStringsTable.getEntryAt(index)).toString().trim(); >+ } >+ >+ /** >+ * check the styles applied to the cell and fetches the exact content of date cell >+ * @param data >+ * @return >+ */ >+ private String getDateAsString(String data) { >+ if ((data != null) && (!(data.trim().equals("")))) { >+ /*return formatter.formatRawCellContents(Double.parseDouble(data), >+ formatIndex, formatString);*/ >+ >+ /* >+ * All dates are formatted with 'DD/MM/YYYY', this is to avoid confusion between >+ * 10/12/2017 & 10/12/1917. Otherwise both will be read as 10/12/17 if the format >+ * is DD/MM/YY >+ */ >+ return formatter.formatRawCellContents(Double.parseDouble(data), >+ formatIndex, "DD/MM/YYYY"); >+ } else { >+ return null; >+ } >+ } >+ >+ >+ /** >+ * Used to fill empty cells as null >+ */ >+ private void fillEmptyCells() { >+ int currentCellIndex = cellPositions.indexOf(currentCellPosition); >+ if ((currentCellIndex - previousCellIndex) > 1) { >+ for (int i = (previousCellIndex + 1); i < currentCellIndex; i++) { >+ cell = new StreamedCell(); >+ cell.setValue(null); >+ row.getCells().add(cell); >+ } >+ >+ previousCellIndex = currentCellIndex; >+ } >+ } >+ >+ public boolean isEndOfRow() { >+ return isEndOfRow; >+ } >+ >+ public void setEndOfRow(boolean isEndOfRow) { >+ this.isEndOfRow = isEndOfRow; >+ } >+ >+ public int getRowNumber() { >+ return rowNumber; >+ } >+ >+ public int getNumberOfColumns() { >+ return numberOfColumns; >+ } >+ >+ public List<String> getCellPositions() { >+ return cellPositions; >+ } >+ >+ public StreamedRow getRow() { >+ return row; >+ } >+ >+ >+} >diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedWorkbook.java >new file mode 100644 >index 0000000..8d07281 >--- /dev/null >+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedWorkbook.java >@@ -0,0 +1,1070 @@ >+/* ==================================================================== >+ Licensed to the Apache Software Foundation (ASF) under one or more >+ contributor license agreements. See the NOTICE file distributed with >+ this work for additional information regarding copyright ownership. >+ The ASF licenses this file to You under the Apache License, Version 2.0 >+ (the "License"); you may not use this file except in compliance with >+ the License. You may obtain a copy of the License at >+ >+ http://www.apache.org/licenses/LICENSE-2.0 >+ >+ Unless required by applicable law or agreed to in writing, software >+ distributed under the License is distributed on an "AS IS" BASIS, >+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ See the License for the specific language governing permissions and >+ limitations under the License. >+==================================================================== */ >+package org.apache.poi.xssf.streaming.reader; >+ >+import java.io.File; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.OutputStream; >+import java.util.ArrayList; >+import java.util.Iterator; >+import java.util.List; >+ >+import javax.xml.parsers.DocumentBuilder; >+import javax.xml.parsers.DocumentBuilderFactory; >+import javax.xml.stream.XMLEventReader; >+import javax.xml.stream.XMLInputFactory; >+import javax.xml.stream.XMLStreamException; >+import javax.xml.xpath.XPath; >+import javax.xml.xpath.XPathConstants; >+import javax.xml.xpath.XPathExpression; >+import javax.xml.xpath.XPathFactory; >+ >+import org.apache.poi.openxml4j.opc.OPCPackage; >+import org.apache.poi.ss.SpreadsheetVersion; >+import org.apache.poi.ss.formula.udf.UDFFinder; >+import org.apache.poi.ss.usermodel.CellStyle; >+import org.apache.poi.ss.usermodel.CreationHelper; >+import org.apache.poi.ss.usermodel.DataFormat; >+import org.apache.poi.ss.usermodel.Font; >+import org.apache.poi.ss.usermodel.Name; >+import org.apache.poi.ss.usermodel.PictureData; >+import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; >+import org.apache.poi.ss.usermodel.Sheet; >+import org.apache.poi.ss.usermodel.SheetVisibility; >+import org.apache.poi.ss.usermodel.Workbook; >+import org.apache.poi.util.NotImplemented; >+import org.apache.poi.util.POILogFactory; >+import org.apache.poi.util.POILogger; >+import org.apache.poi.xssf.eventusermodel.XSSFReader; >+import org.apache.poi.xssf.model.SharedStringsTable; >+import org.apache.poi.xssf.model.StylesTable; >+import org.w3c.dom.Document; >+import org.w3c.dom.NodeList; >+ >+/** >+ * Represents the excel workbook. >+ * This version of Workbook is used fore reading very large excel files >+ * with a less memory footprint. It does not support creation of a workbook. >+ * It uses StAX(Streaming API for XML) to stream the spreadsheet. >+ * In order to reduce the memory footprint, only minimal functionalities are >+ * supported. >+ * >+ */ >+public class StreamedWorkbook implements Workbook{ >+ >+ private static final POILogger logger = POILogFactory.getLogger(StreamedWorkbook.class); >+ >+ private File inputFile; >+ >+ private Iterator<InputStream> sheetIterator; >+ private SharedStringsTable sharedStringsTable; >+ private StylesTable stylesTable; >+ private XSSFReader globalReader; >+ private List<StreamedSheet> sheetList = null; >+ private boolean isClosed; >+ >+ private static final String ACTIVE_SHEET_PATH = "//workbookView/@activeTab"; >+ private static final String SHEET_NAME_PATH = "//sheets/sheet/@name"; >+ private static final String VISIBLE_SHEET_PATH = "//sheets/sheet[@state='visible']/@sheetId"; >+ private static final String HIDDEN_SHEET_PATH = "//sheets/sheet[@state='hidden']/@sheetId"; >+ private static final String VERY_HIDDEN_SHEET_PATH = "//sheets/sheet[@state='veryHidden']/@sheetId"; >+ >+ /** >+ * <pre> >+ * Accepts the file path and return an instance of StreamedWorkBook >+ *</pre> >+ * @param filePath >+ * @throws Exception >+ */ >+ public StreamedWorkbook(String filePath) throws Exception{ >+ if((filePath != null) && !(filePath.trim().isEmpty())){ >+ inputFile = new File(filePath); >+ >+ if(inputFile != null){ >+ XSSFReader reader = getExcelReader(inputFile); >+ if(reader != null){ >+ this.sheetIterator = reader.getSheetsData(); >+ this.sharedStringsTable = reader.getSharedStringsTable(); >+ this.stylesTable = reader.getStylesTable(); >+ this.globalReader = reader; >+ } >+ } >+ >+ }else{ >+ throw new Exception("No sheets found"); >+ } >+ } >+ >+ /** >+ * <pre> >+ * Fetch all sheets from given excel file >+ * </pre> >+ * @return Iterator<StreamedSheet> >+ * @throws Exception >+ */ >+ public Iterator<StreamedSheet> getSheetIterator() throws Exception{ >+ >+ return getAllSheets(); >+ } >+ >+ >+ /** >+ * Returns the list of sheets for the given excel file >+ * @param file >+ * @return Iterator<StreamedSheet> >+ */ >+ private Iterator<StreamedSheet> getAllSheets(){ >+ >+ return getStreamedSheetIterator(); >+ } >+ >+ private Iterator<StreamedSheet> getStreamedSheetIterator(){ >+ XMLInputFactory factory = null; >+ >+ if(sheetIterator != null){ >+ factory = XMLInputFactory.newInstance(); >+ sheetList = new ArrayList<StreamedSheet>(); >+ int sheetNumber = 0; >+ Object[] sheetNames = getValuesFromWorkbookData(SHEET_NAME_PATH); >+ while(sheetIterator.hasNext()){ >+ InputStream sheetInputStream = sheetIterator.next(); >+ StreamedSheet sheet = null; >+ try { >+ sheet = createStreamedSheet(factory.createXMLEventReader(sheetInputStream), sheetNumber, sheetNames[sheetNumber].toString()); >+ sheetList.add(sheet); >+ sheetNumber++; >+ } catch (XMLStreamException e) { >+ logger.log(POILogger.ERROR, "Exception while reading the workbook. "+e.getMessage()); >+ } >+ } >+ }else{ >+ throw new RuntimeException("Workbook already closed"); >+ } >+ >+ return sheetList.iterator(); >+ >+ } >+ >+ >+ /** >+ * Creates and returns the instance of StreamedSheet >+ * >+ * @param parser >+ * @param sheetNumber >+ * @param sheetName >+ * @return StreamedSheet >+ */ >+ private StreamedSheet createStreamedSheet(XMLEventReader parser,int sheetNumber, String sheetName){ >+ StreamedSheet sheet = new StreamedSheet(); >+ sheet.setXmlParser(parser); >+ sheet.setSharedStringsTable(sharedStringsTable); >+ sheet.setStylesTable(stylesTable); >+ sheet.setSheetNumber(sheetNumber); >+ sheet.setSheetName(sheetName); >+ sheet.createEventHandler(); >+ >+ return sheet; >+ } >+ >+ >+ >+ /** >+ * Receives the excel file and returns the file excel file reader >+ * @param inputStream >+ * @return >+ * @throws Exception >+ */ >+ private XSSFReader getExcelReader(File file) throws Exception{ >+ XSSFReader reader = null; >+ OPCPackage pkg = null; >+ pkg = OPCPackage.open(file); >+ reader = new XSSFReader(pkg); >+ return reader; >+ } >+ >+ >+ >+ /** >+ * <pre> >+ * Convenience method to get the active sheet. The active sheet is is the sheet >+ * which is currently displayed when the workbook is viewed in Excel. >+ * 'Selected' sheet(s) is a distinct concept. >+ * </pre> >+ * >+ * @return int >+ */ >+ public int getActiveSheetIndex() { >+ >+ return Integer.parseInt(getValuesFromWorkbookData(ACTIVE_SHEET_PATH)[0].toString()); >+ >+ } >+ >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setActiveSheet(int sheetIndex) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Returns the sheet number of the first visible sheet. >+ * </pre> >+ * @return int >+ */ >+ public int getFirstVisibleTab() { >+ Object[] visibleTabs = getValuesFromWorkbookData(VISIBLE_SHEET_PATH); >+ >+ return (Integer.parseInt(visibleTabs[0].toString())-1); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setFirstVisibleTab(int sheetIndex) { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setSheetOrder(String sheetname, int pos) { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setSelectedTab(int index) { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public void setSheetName(int sheet, String name) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Returns the sheet name of specified index >+ * </pre> >+ * @return String; >+ * >+ */ >+ public String getSheetName(int sheet) { >+ return getValuesFromWorkbookData(SHEET_NAME_PATH)[sheet].toString(); >+ } >+ >+ /** >+ * <pre> >+ * Returns the sheet index for the sheet name given >+ * </pre> >+ * @return int >+ * >+ */ >+ public int getSheetIndex(String name) { >+ int index = 0; >+ for(Object sheetName: getValuesFromWorkbookData(SHEET_NAME_PATH)){ >+ if(sheetName.toString().equals(name)){ >+ return index; >+ } >+ index++; >+ } >+ >+ return -1; >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public int getSheetIndex(Sheet sheet) { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public Sheet createSheet() { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ * >+ */ >+ @NotImplemented >+ public Sheet createSheet(String sheetname) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ * >+ */ >+ @NotImplemented >+ public Sheet cloneSheet(int sheetNum) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Use Iterator<StreamedSheet> getSheetIterator() instead. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Iterator<Sheet> sheetIterator() { >+ throw new UnsupportedOperationException("Not implemented yet. Use getSheetIterator()"); >+ } >+ >+ /** >+ * <pre> >+ * Returns the number of sheets, >+ * </pre> >+ * @return int representing the number of sheets in workbook >+ */ >+ public int getNumberOfSheets() { >+ int sheetCount = 0; >+ >+ if(this.sheetIterator != null){ >+ while(sheetIterator.hasNext()){ >+ sheetIterator.next(); >+ sheetCount++; >+ } >+ }else{ >+ logger.log(POILogger.ERROR, "Workbook already closed"); >+ } >+ >+ >+ return sheetCount; >+ } >+ >+ /** >+ * <pre> >+ * Returns sheet at specified index >+ * </pre> >+ * @return Sheet for the specified index >+ */ >+ public Sheet getSheetAt(int index) { >+ if(sheetList == null && !isClosed){ >+ getAllSheets(); >+ } >+ >+ if(sheetList != null){ >+ for(StreamedSheet sheet: sheetList){ >+ if(sheet.getSheetNumber() == index)return sheet; >+ } >+ } >+ >+ return null; >+ } >+ >+ /** >+ * <pre> >+ * Returns the sheet with specified name >+ * </pre> >+ * >+ */ >+ public Sheet getSheet(String name) { >+ >+ if(sheetList == null && !isClosed){ >+ getAllSheets(); >+ } >+ >+ if(sheetList != null){ >+ for(StreamedSheet sheet: sheetList){ >+ if(sheet.getSheetName().equals(name))return sheet; >+ } >+ } >+ >+ return null; >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void removeSheetAt(int index) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Font createFont() { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Font findFont(short boldWeight, short color, short fontHeight, >+ String name, boolean italic, boolean strikeout, short typeOffset, >+ byte underline) { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Font findFont(boolean bold, short color, short fontHeight, >+ String name, boolean italic, boolean strikeout, short typeOffset, >+ byte underline) { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public short getNumberOfFonts() { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Font getFontAt(short idx) { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ public CellStyle createCellStyle() { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int getNumCellStyles() { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Not Suppored due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public CellStyle getCellStyleAt(int idx) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void write(OutputStream stream) throws IOException { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Close the workbook >+ * </pre> >+ * >+ */ >+ public void close() throws IOException { >+ if(sheetIterator != null){ >+ while(sheetIterator.hasNext()){ >+ sheetIterator.next().close(); >+ } >+ sheetIterator = null; >+ } >+ >+ if(sheetList != null){ >+ sheetList.clear(); >+ sheetList = null; >+ } >+ >+ isClosed = true; >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int getNumberOfNames() { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Name getName(String name) { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public List<? extends Name> getNames(String name) { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public List<? extends Name> getAllNames() { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Name getNameAt(int nameIndex) { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Name createName() { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int getNameIndex(String name) { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void removeName(int index) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void removeName(String name) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void removeName(Name name) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int linkExternalWorkbook(String name, Workbook workbook) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * >+ */ >+ @NotImplemented >+ public void setPrintArea(int sheetIndex, String reference) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setPrintArea(int sheetIndex, int startColumn, int endColumn, >+ int startRow, int endRow) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public String getPrintArea(int sheetIndex) { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void removePrintArea(int sheetIndex) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public MissingCellPolicy getMissingCellPolicy() { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public DataFormat createDataFormat() { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int addPicture(byte[] pictureData, int format) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported due to memory footprint. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ public List<? extends PictureData> getAllPictures() { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public CreationHelper getCreationHelper() { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public boolean isHidden() { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setHidden(boolean hiddenFlag) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Return true if the sheet with given index is hidden >+ * </pre> >+ * @return boolean >+ */ >+ public boolean isSheetHidden(int sheetIx) { >+ //throw new UnsupportedOperationException("Not implemented yet"); >+ >+ Object[] hiddenSheetIdxAry = getValuesFromWorkbookData(HIDDEN_SHEET_PATH); >+ >+ for(Object o: hiddenSheetIdxAry){ >+ int index = (Integer.parseInt(o.toString())-1); >+ if(index == sheetIx)return true; >+ } >+ >+ return false; >+ } >+ >+ /** >+ * <pre> >+ * Return true if the sheet with given index is veryHidden >+ * </pre> >+ * @return boolean >+ */ >+ public boolean isSheetVeryHidden(int sheetIx) { >+ Object[] veryHiddedSheetIdxAry = getValuesFromWorkbookData(VERY_HIDDEN_SHEET_PATH); >+ >+ for(Object o: veryHiddedSheetIdxAry){ >+ int index = (Integer.parseInt(o.toString())-1); >+ if(index == sheetIx)return true; >+ } >+ >+ >+ return false; >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setSheetHidden(int sheetIx, boolean hidden) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setSheetHidden(int sheetIx, int hidden) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void addToolPack(UDFFinder toopack) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setForceFormulaRecalculation(boolean value) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * >+ */ >+ @NotImplemented >+ public boolean getForceFormulaRecalculation() { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ /** >+ * <pre> >+ * Will be supported in the future. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public SpreadsheetVersion getSpreadsheetVersion() { >+ throw new UnsupportedOperationException("Not implemented yet"); >+ } >+ >+ >+ /** >+ * <pre> >+ * Use Iterator<StreamedSheet> getSheetIterator() instead. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public Iterator<Sheet> iterator() { >+ throw new UnsupportedOperationException("Not implemented yet. Use getSheetIterator()"); >+ } >+ >+ /** >+ * <pre> >+ * Returns the visibility of sheet for the given index. >+ * </pre> >+ * @return SheetVisibility[Hidden/Visible/VeryHidden] >+ */ >+ public SheetVisibility getSheetVisibility(int sheetIx) { >+ Object[] hiddenSheetIdxAry = getValuesFromWorkbookData(HIDDEN_SHEET_PATH); >+ >+ for(Object o: hiddenSheetIdxAry){ >+ int index = (Integer.parseInt(o.toString())-1); >+ if(index == sheetIx)return SheetVisibility.HIDDEN; >+ } >+ >+ Object[] visibleSheetIdxAry = getValuesFromWorkbookData(VISIBLE_SHEET_PATH); >+ >+ for(Object o: visibleSheetIdxAry){ >+ int index = (Integer.parseInt(o.toString())-1); >+ if(index == sheetIx)return SheetVisibility.VISIBLE; >+ } >+ >+ Object[] veryHiddedSheetIdxAry = getValuesFromWorkbookData(VERY_HIDDEN_SHEET_PATH); >+ >+ for(Object o: veryHiddedSheetIdxAry){ >+ int index = (Integer.parseInt(o.toString())-1); >+ if(index == sheetIx)return SheetVisibility.VERY_HIDDEN; >+ } >+ >+ throw new IllegalArgumentException("Invalid sheet index"); >+ >+ >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public void setSheetVisibility(int sheetIx, SheetVisibility visibility) { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * <pre> >+ * Not supported right now, as StreamedWorkbook >+ * supports only reading. >+ * </pre> >+ * @exception UnsupportedOperationException >+ */ >+ @NotImplemented >+ public int addOlePackage(byte[] oleData, String label, String fileName, >+ String command) throws IOException { >+ throw new UnsupportedOperationException("Not supported due to memory footprint"); >+ } >+ >+ /** >+ * Strictly for reading any specific value from any node in workbook.xml >+ * DOM Parser is used here assuming that workbook.xml will never contribute >+ * towards the size of excel file. >+ * >+ * @param xml >+ * @param xpathQuery >+ * @return Object[] >+ * @throws Exception >+ */ >+ private Object[] getValuesFromWorkbookData(String xpathQuery){ >+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); >+ List<String> valueAry = new ArrayList<String>(); >+ DocumentBuilder builder; >+ Document doc = null; >+ NodeList nodeList = null; >+ try{ >+ builder = factory.newDocumentBuilder(); >+ doc = builder.parse(globalReader.getWorkbookData()); >+ XPathFactory xPathfactory = XPathFactory.newInstance(); >+ XPath xpath = xPathfactory.newXPath(); >+ doc.normalize(); >+ >+ >+ XPathExpression xPathExpr = xpath.compile(xpathQuery); >+ nodeList = (NodeList)xPathExpr.evaluate(doc, XPathConstants.NODESET); >+ >+ for(int i=0; i<nodeList.getLength(); i++){ >+ valueAry.add(nodeList.item(i).getNodeValue()); >+ } >+ }catch(Exception e){ >+ logger.log(POILogger.ERROR, "Exception while reading the workbook."); >+ } >+ >+ return valueAry.toArray(); >+ } >+} >diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/reader/TestStreamedWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/reader/TestStreamedWorkbook.java >new file mode 100644 >index 0000000..f914489 >--- /dev/null >+++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/reader/TestStreamedWorkbook.java >@@ -0,0 +1,895 @@ >+/* >+ * ==================================================================== >+ * Licensed to the Apache Software Foundation (ASF) under one or more >+ * contributor license agreements. See the NOTICE file distributed with >+ * this work for additional information regarding copyright ownership. >+ * The ASF licenses this file to You under the Apache License, Version 2.0 >+ * (the "License"); you may not use this file except in compliance with >+ * the License. You may obtain a copy of the License at >+ * >+ * http://www.apache.org/licenses/LICENSE-2.0 >+ * >+ * Unless required by applicable law or agreed to in writing, software >+ * distributed under the License is distributed on an "AS IS" BASIS, >+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ * See the License for the specific language governing permissions and >+ * limitations under the License. >+ * ==================================================================== >+ */ >+package org.apache.poi.xssf.streaming.reader; >+ >+import static org.junit.Assert.assertEquals; >+import static org.junit.Assert.fail; >+ >+import java.io.File; >+import java.util.ArrayList; >+import java.util.Iterator; >+import java.util.List; >+ >+import org.apache.poi.POIDataSamples; >+import org.apache.poi.ss.usermodel.Cell; >+import org.apache.poi.ss.usermodel.Row; >+import org.apache.poi.ss.usermodel.Sheet; >+import org.apache.poi.ss.usermodel.Workbook; >+import org.apache.poi.xssf.usermodel.XSSFWorkbook; >+import org.junit.Test; >+ >+ >+public class TestStreamedWorkbook{ >+ >+ >+ @Test >+ public void testInvalidFilePath() throws Exception{ >+ StreamedWorkbook workbook = null; >+ try { >+ workbook = new StreamedWorkbook(null); >+ fail("expected exception"); >+ } catch (Exception e) { >+ assertEquals("No sheets found", e.getMessage()); >+ } >+ >+ if(workbook != null)workbook.close(); >+ >+ } >+ >+ @Test >+ public void testInvalidFile() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("InvalidFile.txt"); >+ StreamedWorkbook workbook = null; >+ try { >+ >+ workbook = new StreamedWorkbook(f.getAbsolutePath()); >+ workbook.getSheetIterator(); >+ } catch (Exception e) { >+ assertEquals("No valid entries or contents found, this is not a valid OOXML (Office Open XML) file", e.getMessage()); >+ } >+ >+ if(workbook != null)workbook.close(); >+ } >+ >+ >+ @Test >+ public void testSheetCount() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ Workbook workbook = new XSSFWorkbook(f); >+ int streamedSheetcount = 0; >+ int count=0; >+ >+ try { >+ Iterator<StreamedSheet> streamedSheetIterator = streamedWorkbook.getSheetIterator(); >+ >+ while(streamedSheetIterator.hasNext()){ >+ streamedSheetIterator.next(); >+ streamedSheetcount++; >+ } >+ >+ Iterator<Sheet> sheetIterator = workbook.sheetIterator(); >+ >+ while(sheetIterator.hasNext()){ >+ sheetIterator.next(); >+ count++; >+ } >+ >+ assertEquals(count, streamedSheetcount); >+ } catch (Exception e) { >+ >+ } >+ >+ streamedWorkbook.close(); >+ workbook.close(); >+ >+ } >+ >+ @Test >+ public void testTotalNumberOfSheets() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ try { >+ int sheetCount = workbook.getNumberOfSheets(); >+ int streamedSheetCount = streamedWorkbook.getNumberOfSheets(); >+ >+ assertEquals(sheetCount, streamedSheetCount); >+ } catch (Exception e) { >+ } >+ >+ workbook.close(); >+ streamedWorkbook.close(); >+ } >+ >+ @Test >+ public void testTotalRowCount() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ Workbook workbook = new XSSFWorkbook(f); >+ int streamedSheetCount = 0; >+ >+ long streamedRowCount = 0; >+ >+ Iterator<StreamedSheet> streamedSheetIterator = streamedWorkbook.getSheetIterator(); >+ >+ while((streamedSheetIterator.hasNext()) && (streamedSheetCount == 0)){ >+ StreamedSheet sheet = streamedSheetIterator.next(); >+ >+ Iterator<StreamedRow> rows = sheet.getAllRows(); >+ >+ while(rows.hasNext()){ >+ rows.next(); >+ streamedRowCount++; >+ } >+ >+ streamedSheetCount++; >+ } >+ >+ int sheetCount= 0; >+ int rowCount = 0; >+ Iterator<Sheet> sheetIterator = workbook.sheetIterator(); >+ while(sheetIterator.hasNext() && sheetCount ==0){ >+ Sheet sheet = sheetIterator.next(); >+ Iterator<Row> rowIterator = sheet.iterator(); >+ >+ while(rowIterator.hasNext()){ >+ rowIterator.next(); >+ rowCount++; >+ } >+ >+ sheetCount++; >+ } >+ >+ assertEquals(rowCount, streamedRowCount); >+ >+ streamedWorkbook.close(); >+ workbook.close(); >+ } >+ >+ @Test >+ public void testNRowCount() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook workbook = new StreamedWorkbook(f.getAbsolutePath()); >+ >+ long count = 0; >+ int sheetCount = 0; >+ >+ Iterator<StreamedSheet> sheetIterator = workbook.getSheetIterator(); >+ >+ while((sheetIterator.hasNext()) && (sheetCount == 0)){ >+ StreamedSheet sheet = sheetIterator.next(); >+ >+ Iterator<StreamedRow> rows = sheet.getNRows(4); >+ >+ while(rows.hasNext()){ >+ rows.next(); >+ count++; >+ } >+ >+ assertEquals(4, count); >+ sheetCount++; >+ } >+ >+ workbook.close(); >+ } >+ >+ @Test >+ public void testTotalCellCount() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ Workbook workbook = new XSSFWorkbook(f); >+ int streamedSheetCount = 0; >+ long streamedCellCount = 0; >+ long cellCount = 0; >+ >+ Iterator<StreamedSheet> streamedSheetIterator = streamedWorkbook.getSheetIterator(); >+ >+ while((streamedSheetIterator.hasNext()) && (streamedSheetCount == 0)){ >+ StreamedSheet streamedSheet = streamedSheetIterator.next(); >+ >+ Iterator<StreamedRow> streamedRows = streamedSheet.getAllRows(); >+ >+ while(streamedRows.hasNext()){ >+ StreamedRow streamedRow = streamedRows.next(); >+ >+ Iterator<StreamedCell> streamedCellIterator = streamedRow.getCellIterator(); >+ >+ while(streamedCellIterator.hasNext()){ >+ streamedCellIterator.next(); >+ streamedCellCount++; >+ } >+ >+ } >+ >+ streamedSheetCount++; >+ } >+ >+ int sheetCount = 0; >+ Iterator<Sheet> sheetIterator = workbook.sheetIterator(); >+ >+ while((sheetIterator.hasNext()) && (sheetCount == 0)){ >+ Sheet sheet = sheetIterator.next(); >+ >+ Iterator<Row> rowIterator = sheet.iterator(); >+ while(rowIterator.hasNext()){ >+ Row row = rowIterator.next(); >+ >+ Iterator<Cell> cellIterator = row.cellIterator(); >+ >+ while(cellIterator.hasNext()){ >+ cellIterator.next(); >+ cellCount++; >+ } >+ } >+ >+ sheetCount++; >+ } >+ >+ assertEquals(cellCount, streamedCellCount); >+ >+ streamedWorkbook.close(); >+ workbook.close(); >+ } >+ >+ >+ @Test >+ public void testStartingRowAndCellNumber() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ List<Short> workbookStartingCellNumbers = new ArrayList<Short>(); >+ List<Short> streamedWorkbookStartingCellNumbers = new ArrayList<Short>(); >+ >+ int workbookStartingRowNum = 0; >+ int streamedWorkbookStartingRowNumber = 0; >+ >+ Sheet sheet = workbook.getSheetAt(0); >+ Iterator<Row> rowIterator = sheet.iterator(); >+ >+ int workbookRowCount = 0; >+ >+ while(rowIterator.hasNext()){ >+ Row row = rowIterator.next(); >+ if(workbookRowCount == 0){ >+ workbookStartingRowNum = row.getRowNum(); >+ workbookRowCount++; >+ } >+ >+ if(row != null) >+ workbookStartingCellNumbers.add(row.getFirstCellNum()); >+ >+ } >+ >+ StreamedSheet streamedSheet = (StreamedSheet)streamedWorkbook.getSheetAt(0); >+ Iterator<StreamedRow> streamedRowIterator = streamedSheet.getAllRows(); >+ int streamedWorkbookRowCount = 0; >+ >+ while(streamedRowIterator.hasNext()){ >+ StreamedRow row = streamedRowIterator.next(); >+ if(streamedWorkbookRowCount == 0){ >+ streamedWorkbookStartingRowNumber = row.getRowNum(); >+ streamedWorkbookRowCount++; >+ } >+ >+ if(row != null) >+ streamedWorkbookStartingCellNumbers.add(row.getFirstCellNum()); >+ } >+ >+ assertEquals(workbookStartingRowNum, streamedWorkbookStartingRowNumber); >+ assertEquals(workbookStartingCellNumbers, streamedWorkbookStartingCellNumbers); >+ >+ workbook.close(); >+ streamedWorkbook.close(); >+ } >+ >+ @Test >+ public void testSheetData() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook workbook = new StreamedWorkbook(f.getAbsolutePath()); >+ int sheetCount = 0; >+ >+ >+ Iterator<StreamedSheet> sheetIterator = workbook.getSheetIterator(); >+ >+ while((sheetIterator.hasNext()) && (sheetCount == 0)){ >+ int rowCount = 0; >+ >+ StreamedSheet sheet = sheetIterator.next(); >+ >+ Iterator<StreamedRow> rows = sheet.getAllRows(); >+ >+ while(rows.hasNext()){ >+ >+ StreamedRow row = rows.next(); >+ >+ int cellCount = 0; >+ >+ Iterator<StreamedCell> cellIterator = row.getCellIterator(); >+ >+ while(cellIterator.hasNext()){ >+ StreamedCell cell = cellIterator.next(); >+ if(rowCount == 1){ >+ >+ if(cellCount == 0){ >+ assertEquals("1", cell.getValue()); >+ }else if(cellCount == 1){ >+ assertEquals("Item1", cell.getValue()); >+ }else if(cellCount == 2){ >+ assertEquals("201", cell.getValue()); >+ }else if(cellCount == 3){ >+ assertEquals("100.11", cell.getValue()); >+ }else if(cellCount == 4){ >+ assertEquals("TRUE", cell.getValue()); >+ }else if(cellCount == 5){ >+ assertEquals("04/02/1917", cell.getValue()); >+ }else if(cellCount == 6){ >+ assertEquals("90.11", cell.getValue()); >+ } >+ }else if(rowCount == 3){ >+ if(cellCount == 4){ >+ assertEquals(null, cell.getValue()); >+ } >+ } >+ >+ cellCount++; >+ >+ } >+ >+ >+ rowCount++; >+ >+ } >+ >+ sheetCount++; >+ } >+ >+ workbook.close(); >+ } >+ >+ @Test >+ public void testBatchData() throws Exception{ >+ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook workbook = new StreamedWorkbook(f.getAbsolutePath()); >+ int sheetCount = 0; >+ >+ >+ Iterator<StreamedSheet> sheetIterator = workbook.getSheetIterator(); >+ >+ while(sheetIterator.hasNext()){ >+ >+ StreamedSheet sheet = sheetIterator.next(); >+ >+ if(sheetCount == 1){ >+ Iterator<StreamedRow> rows = sheet.getNRows(1); >+ >+ while(rows.hasNext()){ >+ StreamedRow row = rows.next(); >+ assertEquals("Row Number:0 --> Item | item description | Strore | Price | Promotion applied | MFD | Discount rate |", row.toString().trim()); >+ } >+ >+ >+ rows = sheet.getNRows(4); >+ >+ while(rows.hasNext()){ >+ StreamedRow row = rows.next(); >+ assertEquals("Row Number:1 --> 1 | Item1 | 201 | 100.11 | TRUE | 04/02/1917 | 90.11 |", row.toString().trim()); >+ row = rows.next(); >+ assertEquals("Row Number:2 --> 2 | Item2 | 202 | 101.11 | TRUE | 05/02/1917 | 91.11 |", row.toString().trim()); >+ row = rows.next(); >+ assertEquals("Row Number:3 --> 3 | Item3 | 203 | 102.11 | TRUE | 06/02/1917 | 92.11 |", row.toString().trim()); >+ row = rows.next(); >+ assertEquals("Row Number:4 --> 4 | Item4 | 204 | 103.11 | TRUE | 07/02/1917 | 93.11 |", row.toString().trim()); >+ } >+ >+ >+ >+ rows = sheet.getNRows(4); >+ >+ while(rows.hasNext()){ >+ StreamedRow row = rows.next(); >+ assertEquals("Row Number:5 --> 5 | Item5 | 205 | 104.11 | TRUE | 08/02/1917 | 94.11 |", row.toString().trim()); >+ row = rows.next(); >+ assertEquals("Row Number:6 --> 6 | Item6 | 206 | 105.11 | TRUE | 09/02/1917 | 95.11 |", row.toString().trim()); >+ row = rows.next(); >+ assertEquals("Row Number:7 --> 7 | Item7 | 207 | 106.11 | TRUE | 10/02/1917 | 96.11 |", row.toString().trim()); >+ row = rows.next(); >+ assertEquals("Row Number:8 --> 8 | Item8 | 208 | 107.11 | FALSE | 11/02/1917 | 97.11 |", row.toString().trim()); >+ } >+ >+ } >+ >+ >+ sheetCount++; >+ >+ } >+ >+ workbook.close(); >+ >+ } >+ >+ >+ @Test >+ public void testGetCell() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook workbook = new StreamedWorkbook(f.getAbsolutePath()); >+ int sheetCount = 0; >+ >+ >+ Iterator<StreamedSheet> sheetIterator = workbook.getSheetIterator(); >+ >+ while((sheetIterator.hasNext()) && (sheetCount == 0)){ >+ >+ StreamedSheet sheet = sheetIterator.next(); >+ >+ Iterator<StreamedRow> rows = sheet.getAllRows(); >+ >+ while(rows.hasNext()){ >+ >+ StreamedRow row = rows.next(); >+ >+ if(row.getRowNum() == 3){ >+ StreamedCell cell = (StreamedCell)row.getCell(5); >+ assertEquals("06/02/1917", cell.getValue()); >+ >+ try{ >+ cell = (StreamedCell)row.getCell(10); >+ }catch(Exception exception){ >+ assertEquals(true, exception instanceof IndexOutOfBoundsException); >+ } >+ } >+ >+ >+ } >+ >+ sheetCount++; >+ } >+ >+ workbook.close(); >+ } >+ >+ >+ @Test >+ public void testGetFirstAndLastCellNum() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook workbook = new StreamedWorkbook(f.getAbsolutePath()); >+ int sheetCount = 0; >+ >+ >+ Iterator<StreamedSheet> sheetIterator = workbook.getSheetIterator(); >+ >+ while((sheetIterator.hasNext()) && (sheetCount == 0)){ >+ >+ StreamedSheet sheet = sheetIterator.next(); >+ >+ Iterator<StreamedRow> rows = sheet.getAllRows(); >+ >+ while(rows.hasNext()){ >+ >+ StreamedRow row = rows.next(); >+ >+ if(row.getRowNum() == 3){ >+ StreamedCell cell = (StreamedCell)row.getCell(row.getFirstCellNum()); >+ assertEquals("3", cell.getValue()); >+ assertEquals("3", cell.getStringCellValue()); >+ >+ cell = (StreamedCell)row.getCell(row.getLastCellNum()-1); >+ assertEquals("92.11", cell.getValue()); >+ assertEquals("92.11", cell.getStringCellValue()); >+ } >+ } >+ >+ sheetCount++; >+ } >+ >+ workbook.close(); >+ } >+ >+ @Test >+ public void testReopenClosedWorkbook(){ >+ >+ try{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook workbook = new StreamedWorkbook(f.getAbsolutePath()); >+ >+ workbook.close(); >+ >+ Iterator<StreamedSheet> sheetIterator = workbook.getSheetIterator(); >+ }catch(Exception e){ >+ assertEquals("Workbook already closed", e.getMessage()); >+ } >+ >+ >+ } >+ >+ @Test >+ public void testGetActiveSheetIndex() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ assertEquals(workbook.getActiveSheetIndex(), streamedWorkbook.getActiveSheetIndex()); >+ streamedWorkbook.close(); >+ workbook.close(); >+ } >+ >+ @Test >+ public void testGetSheetNameWithSheetIndex() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ assertEquals(workbook.getSheetName(1), streamedWorkbook.getSheetName(1)); >+ streamedWorkbook.close(); >+ workbook.close(); >+ } >+ >+ @Test >+ public void testGetSheetIndex() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ assertEquals(workbook.getSheetIndex("Sheet3"), streamedWorkbook.getSheetIndex("Sheet3")); >+ streamedWorkbook.close(); >+ workbook.close(); >+ } >+ >+ @Test >+ public void testGetFirstVisibleTab() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ assertEquals(workbook.getFirstVisibleTab(), streamedWorkbook.getFirstVisibleTab()); >+ streamedWorkbook.close(); >+ workbook.close(); >+ } >+ >+ @Test >+ public void testGetSheetName() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ >+ List<String> workbookSheetNames = new ArrayList<String>(); >+ List<String> streamedWorkbookSheetNames = new ArrayList<String>(); >+ >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ Iterator<Sheet> sheetIterator = workbook.sheetIterator(); >+ >+ while(sheetIterator.hasNext()){ >+ workbookSheetNames.add(sheetIterator.next().getSheetName()); >+ } >+ >+ >+ >+ Iterator<StreamedSheet> streamedSheetIterator = streamedWorkbook.getSheetIterator(); >+ >+ while(streamedSheetIterator.hasNext()){ >+ streamedWorkbookSheetNames.add(streamedSheetIterator.next().getSheetName()); >+ } >+ >+ >+ assertEquals(workbookSheetNames, streamedWorkbookSheetNames); >+ >+ streamedWorkbook.close(); >+ workbook.close(); >+ } >+ >+ @Test >+ public void testIsSheetHidden() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ >+ assertEquals(workbook.isSheetHidden(2), streamedWorkbook.isSheetHidden(2)); >+ assertEquals(workbook.isSheetHidden(1), streamedWorkbook.isSheetHidden(1)); >+ >+ streamedWorkbook.close(); >+ workbook.close(); >+ >+ } >+ >+ @Test >+ public void testGetSheetVisibility() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ >+ assertEquals(workbook.getSheetVisibility(2), streamedWorkbook.getSheetVisibility(2)); >+ assertEquals(workbook.getSheetVisibility(1), streamedWorkbook.getSheetVisibility(1)); >+ >+ streamedWorkbook.close(); >+ workbook.close(); >+ >+ } >+ >+ @Test >+ public void testGetSheet() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ Sheet sheet = workbook.getSheet("Sheet2"); >+ Sheet streamedSheet = streamedWorkbook.getSheet("Sheet2"); >+ >+ assertEquals(sheet.getSheetName(), streamedSheet.getSheetName()); >+ >+ streamedWorkbook.close(); >+ workbook.close(); >+ >+ } >+ >+ @Test(expected=NullPointerException.class) >+ public void testGetSheetAfterClose() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ streamedWorkbook.close(); >+ Sheet streamedSheet = streamedWorkbook.getSheet("Sheet2"); >+ System.out.println(streamedSheet.getSheetName()); >+ } >+ >+ @Test >+ public void testGetSheetAt() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ Sheet sheet = workbook.getSheetAt(0); >+ Sheet streamedSheet = streamedWorkbook.getSheetAt(0); >+ >+ assertEquals(sheet.getSheetName(), streamedSheet.getSheetName()); >+ >+ streamedWorkbook.close(); >+ workbook.close(); >+ >+ } >+ >+ @Test(expected=NullPointerException.class) >+ public void testGetSheetAtAfterClose() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ streamedWorkbook.close(); >+ >+ Sheet streamedSheet = streamedWorkbook.getSheetAt(0); >+ System.out.println(streamedSheet.getSheetName()); >+ >+ } >+ >+ >+ @Test(expected=NullPointerException.class) >+ public void testGetSheetException() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ >+ Sheet sheet = streamedWorkbook.getSheet("Sheet200"); >+ >+ sheet.getSheetName(); >+ >+ streamedWorkbook.close(); >+ >+ } >+ >+ @Test >+ public void testGetFirstCellNumber() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ List<Short> workbookFirstCellNumList = new ArrayList<Short>(); >+ List<Short> sworkbookFirstCellNumList = new ArrayList<Short>(); >+ >+ Iterator<Sheet> workbookSheetIterator = workbook.iterator(); >+ while(workbookSheetIterator.hasNext()){ >+ Sheet sheet = workbookSheetIterator.next(); >+ Iterator<Row> rowIterator = sheet.iterator(); >+ while(rowIterator.hasNext()){ >+ Row row = rowIterator.next(); >+ workbookFirstCellNumList.add(row.getFirstCellNum()); >+ } >+ } >+ >+ >+ Iterator<StreamedSheet> sworkbookSheetIterator = streamedWorkbook.getSheetIterator(); >+ while(sworkbookSheetIterator.hasNext()){ >+ StreamedSheet sheet = sworkbookSheetIterator.next(); >+ Iterator<StreamedRow> rowIterator = sheet.getAllRows(); >+ while(rowIterator.hasNext()){ >+ Row row = rowIterator.next(); >+ sworkbookFirstCellNumList.add(row.getFirstCellNum()); >+ } >+ } >+ >+ >+ assertEquals(workbookFirstCellNumList, sworkbookFirstCellNumList); >+ >+ streamedWorkbook.close(); >+ workbook.close(); >+ >+ } >+ >+ @Test >+ public void testGetLastCellNumber() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ List<Short> workbookLastCellNumList = new ArrayList<Short>(); >+ List<Short> sworkbookLastCellNumList = new ArrayList<Short>(); >+ >+ Iterator<Sheet> workbookSheetIterator = workbook.iterator(); >+ while(workbookSheetIterator.hasNext()){ >+ Sheet sheet = workbookSheetIterator.next(); >+ Iterator<Row> rowIterator = sheet.iterator(); >+ while(rowIterator.hasNext()){ >+ Row row = rowIterator.next(); >+ workbookLastCellNumList.add(row.getLastCellNum()); >+ } >+ } >+ >+ >+ Iterator<StreamedSheet> sworkbookSheetIterator = streamedWorkbook.getSheetIterator(); >+ while(sworkbookSheetIterator.hasNext()){ >+ StreamedSheet sheet = sworkbookSheetIterator.next(); >+ Iterator<StreamedRow> rowIterator = sheet.getAllRows(); >+ while(rowIterator.hasNext()){ >+ Row row = rowIterator.next(); >+ sworkbookLastCellNumList.add(row.getLastCellNum()); >+ } >+ } >+ >+ >+ assertEquals(workbookLastCellNumList, sworkbookLastCellNumList); >+ >+ streamedWorkbook.close(); >+ workbook.close(); >+ >+ } >+ >+ @Test >+ public void testGetPhysicalNumOfCells() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ List<Integer> workbookPhysicalCellNums = new ArrayList<Integer>(); >+ List<Integer> sworkbookPhysicalCellNums = new ArrayList<Integer>(); >+ >+ Iterator<Sheet> workbookSheetIterator = workbook.iterator(); >+ while(workbookSheetIterator.hasNext()){ >+ Sheet sheet = workbookSheetIterator.next(); >+ Iterator<Row> rowIterator = sheet.iterator(); >+ while(rowIterator.hasNext()){ >+ Row row = rowIterator.next(); >+ workbookPhysicalCellNums.add(row.getPhysicalNumberOfCells()); >+ } >+ } >+ >+ >+ Iterator<StreamedSheet> sworkbookSheetIterator = streamedWorkbook.getSheetIterator(); >+ while(sworkbookSheetIterator.hasNext()){ >+ StreamedSheet sheet = sworkbookSheetIterator.next(); >+ Iterator<StreamedRow> rowIterator = sheet.getAllRows(); >+ while(rowIterator.hasNext()){ >+ Row row = rowIterator.next(); >+ sworkbookPhysicalCellNums.add(row.getPhysicalNumberOfCells()); >+ } >+ } >+ >+ >+ assertEquals(workbookPhysicalCellNums, sworkbookPhysicalCellNums); >+ >+ streamedWorkbook.close(); >+ workbook.close(); >+ >+ } >+ >+ >+ @Test >+ public void testGetColumnIndex() throws Exception{ >+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); >+ File f= files.getFile("SpreadSheetSample04022017.xlsx"); >+ StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath()); >+ Workbook workbook = new XSSFWorkbook(f); >+ >+ List<Integer> workbookColIndexList = new ArrayList<Integer>(); >+ List<Integer> sworkbookColIndexList = new ArrayList<Integer>(); >+ >+ >+ >+ Iterator<Sheet> workbookSheetIterator = workbook.iterator(); >+ while(workbookSheetIterator.hasNext()){ >+ Sheet sheet = workbookSheetIterator.next(); >+ Iterator<Row> rowIterator = sheet.iterator(); >+ while(rowIterator.hasNext()){ >+ Row row = rowIterator.next(); >+ >+ Iterator<Cell> cellIterator = row.cellIterator(); >+ while(cellIterator.hasNext()){ >+ Cell cell = cellIterator.next(); >+ workbookColIndexList.add(cell.getColumnIndex()); >+ } >+ } >+ } >+ >+ >+ >+ Iterator<StreamedSheet> sworkbookSheetIterator = streamedWorkbook.getSheetIterator(); >+ while(sworkbookSheetIterator.hasNext()){ >+ StreamedSheet sheet = sworkbookSheetIterator.next(); >+ Iterator<StreamedRow> rowIterator = sheet.getAllRows(); >+ while(rowIterator.hasNext()){ >+ StreamedRow row = rowIterator.next(); >+ >+ Iterator<StreamedCell> cellIterator = row.getCellIterator(); >+ while(cellIterator.hasNext()){ >+ Cell cell = cellIterator.next(); >+ sworkbookColIndexList.add(cell.getColumnIndex()); >+ } >+ } >+ } >+ >+ >+ assertEquals(workbookColIndexList, sworkbookColIndexList); >+ >+ streamedWorkbook.close(); >+ workbook.close(); >+ >+ } >+ >+ >+ >+} >diff --git a/test-data/spreadsheet/InvalidFile.txt b/test-data/spreadsheet/InvalidFile.txt >new file mode 100644 >index 0000000..e69de29 >diff --git a/test-data/spreadsheet/SpreadSheetSample04022017.xlsx b/test-data/spreadsheet/SpreadSheetSample04022017.xlsx >new file mode 100644 >index 0000000..a397cee >Binary files /dev/null and b/test-data/spreadsheet/SpreadSheetSample04022017.xlsx differ >diff --git a/test-data/spreadsheet/logoKarmokar4.png b/test-data/spreadsheet/logoKarmokar4.png >deleted file mode 100644 >index 90a915a..0000000 >Binary files a/test-data/spreadsheet/logoKarmokar4.png and /dev/null differ
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 60707
:
34731
|
34757
|
34943
| 34945