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..bf815c4 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedCell.java @@ -0,0 +1,490 @@ +/* ==================================================================== + 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; + +/** + * 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(){ + + } + + /** + *
+ * Return cell value + *+ * 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; + } + + /** + *
+ * Returns the cell number + *+ * + * @return int, that represents cell number + */ + public int getCellNumber() { + return cellNumber; + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @param cellNumber + */ + public void setCellNumber(int cellNumber) { + this.cellNumber = cellNumber; + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public int getColumnIndex() { + throw new UnsupportedOperationException("Not implememted yet."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public int getRowIndex() { + throw new UnsupportedOperationException("Not implememted yet."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public Sheet getSheet() { + throw new UnsupportedOperationException("Not implememted yet."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public Row getRow() { + throw new UnsupportedOperationException("Not implememted yet."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @param cellType + * @exception UnsupportedOperationException + */ + public void setCellType(int cellType) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @param cellType + */ + public void setCellType(CellType cellType) { + this.cellType = cellType; + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public int getCellType() { + throw new UnsupportedOperationException("Not implememted yet."); + } + + /** + *
+ * Return the cell type. + *+ * + * @return CellType + */ + public CellType getCellTypeEnum() { + return cellType; + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public int getCachedFormulaResultType() { + throw new UnsupportedOperationException("Not implememted yet."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public CellType getCachedFormulaResultTypeEnum() { + throw new UnsupportedOperationException("Not implememted yet."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @param value + * @exception UnsupportedOperationException + */ + public void setCellValue(double value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @param value + * @exception UnsupportedOperationException + */ + public void setCellValue(Date value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ *@exception UnsupportedOperationException + */ + public void setCellValue(Calendar value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ *@exception UnsupportedOperationException + */ + public void setCellValue(RichTextString value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ *@exception UnsupportedOperationException + */ + public void setCellValue(String value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ *@exception UnsupportedOperationException + */ + public void setCellFormula(String formula) throws FormulaParseException { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory foot print. + *+ * @exception UnsupportedOperationException + */ + public String getCellFormula() { + throw new UnsupportedOperationException("Not implememted yet."); + } + + /** + *
+ * Not supported due to memory foot print. + *+ * @exception UnsupportedOperationException + */ + public double getNumericCellValue() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory foot print. + *+ * @exception UnsupportedOperationException + */ + public Date getDateCellValue() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public RichTextString getRichStringCellValue() { + throw new UnsupportedOperationException("Not implememted yet."); + } + + /** + *
+ * Returns the String value of cell content + *+ * @return String, representing the value of cell + */ + public String getStringCellValue() { + return value; + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ *@exception UnsupportedOperationException + * + */ + public void setCellValue(boolean value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setCellErrorValue(byte value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory foot print. + *+ * @exception UnsupportedOperationException + */ + public boolean getBooleanCellValue() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public byte getErrorCellValue() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setCellStyle(CellStyle style) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public CellStyle getCellStyle() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setAsActiveCell() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public CellAddress getAddress() { + throw new UnsupportedOperationException("Not implememted yet."); + } + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ *@exception UnsupportedOperationException + * + */ + public void setCellComment(Comment comment) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint + *+ * @exception UnsupportedOperationException + */ + public Comment getCellComment() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void removeCellComment() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public Hyperlink getHyperlink() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ *@exception UnsupportedOperationException + * + */ + public void setHyperlink(Hyperlink link) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void removeHyperlink() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public CellRangeAddress getArrayFormulaRange() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + 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..d3768b5 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedRow.java @@ -0,0 +1,384 @@ +/* ==================================================================== + 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; + + +/** + * Represents an excel row. + * Supports only minimal functionality in order to reduce memory consumption. + * + */ +public class StreamedRow implements Row{ + private List
+ * Used to get cells of a Row + *+ * @return Iterator
+ * Returns the row number + *+ * @return int + */ + public int getRowNum() { + return rowNumber; + } + + public void setRowNum(int rowNumber) { + this.rowNumber = rowNumber; + } + + /** + *
+ * Returns String representation of row. + * o/p format[Row Number:+ * @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; + } + }*/ + + /** + *-->
| |.....| ] + *
+ * Retuns the List of Cells contained in the row. + *+ * @return List
+ * Will not be supported. Use getCellIterator() instead + *+ * @exception UnsupportedOperationException + */ +public Iterator
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ +public Cell createCell(int column) { + throw new UnsupportedOperationException("Operation not supported."); +} + +/** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ +public Cell createCell(int column, int type) { + throw new UnsupportedOperationException("Operation not supported."); +} + +/** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ +public Cell createCell(int column, CellType type) { + throw new UnsupportedOperationException("Operation not supported."); +} + +/** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ +public void removeCell(Cell cell) { + throw new UnsupportedOperationException("Operation not supported."); +} + +/** + *
+ * Returns the cell on specified cell number + *+ * @return Cell + */ +public Cell getCell(int cellnum) { + StreamedCell cell = null; + + if(cells != null){ + cell = cells.get(cellnum); + } + + return cell; +} + +/** + *
+ * Will be supported in future. + *+ * @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."); +} + +/** + *
+ * Get the number of the first cell contained in this row. + *+ * + * @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; +} + +/** + *
+ * Gets the index of the last cell contained in this row PLUS ONE. + *+ * + * @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; +} + +/** + *
+ * 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. + *+ * @return int representing the number of defined cells in the row. + */ +public int getPhysicalNumberOfCells() { + if(cells != null)return cells.size(); + else return 0; +} + +/** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ +public void setHeight(short height) { + throw new UnsupportedOperationException("Operation not supported."); +} + +/** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ +public void setZeroHeight(boolean zHeight) { + throw new UnsupportedOperationException("Operation not supported."); +} + +/** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ +public boolean getZeroHeight() { + throw new UnsupportedOperationException("Not implememted yet."); +} + +/** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ +public void setHeightInPoints(float height) { + throw new UnsupportedOperationException("Operation not supported."); +} + +/** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ +public short getHeight() { + throw new UnsupportedOperationException("Not implememted yet."); +} + +/** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ +public float getHeightInPoints() { + throw new UnsupportedOperationException("Not implememted yet."); +} + +/** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ +public boolean isFormatted() { + throw new UnsupportedOperationException("Not implememted yet."); +} + +/** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ +public CellStyle getRowStyle() { + throw new UnsupportedOperationException("Not implememted yet."); +} + +/** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ +public void setRowStyle(CellStyle style) { + throw new UnsupportedOperationException("Operation not supported."); +} + +/** + *
+ * Not supported right now. Use getCellIterator instead + *+ * @exception UnsupportedOperationException + */ +public Iterator
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ +public Sheet getSheet() { + throw new UnsupportedOperationException("Operation not supported."); +} + +/** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ +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..c202714 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedSheet.java @@ -0,0 +1,1528 @@ +/* ==================================================================== + 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.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; + + /** + *
+ * Fetch all rows from the excel. + *+ * + * 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
+ * Used to fetch N number of rows. + *+ * + * 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. + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public Row createRow(int rownum) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void removeRow(Row row) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public Row getRow(int rownum) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public int getPhysicalNumberOfRows() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public int getFirstRowNum() { + throw new UnsupportedOperationException("Not yet implemented."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public int getLastRowNum() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void setColumnHidden(int columnIndex, boolean hidden) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean isColumnHidden(int columnIndex) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void setRightToLeft(boolean value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public boolean isRightToLeft() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setColumnWidth(int columnIndex, int width) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ */ + public int getColumnWidth(int columnIndex) { + throw new UnsupportedOperationException("Operation not supported."); + } + + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public float getColumnWidthInPixels(int columnIndex) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setDefaultColumnWidth(int width) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public int getDefaultColumnWidth() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public short getDefaultRowHeight() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public float getDefaultRowHeightInPoints() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void setDefaultRowHeight(short height) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void setDefaultRowHeightInPoints(float height) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public CellStyle getColumnStyle(int column) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public int addMergedRegion(CellRangeAddress region) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public int addMergedRegionUnsafe(CellRangeAddress region) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public void validateMergedRegions() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void setVerticallyCenter(boolean value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setHorizontallyCenter(boolean value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean getHorizontallyCenter() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean getVerticallyCenter() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void removeMergedRegion(int index) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void removeMergedRegions(Collection
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public int getNumMergedRegions() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public CellRangeAddress getMergedRegion(int index) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public List
+ * Not supported. Use getAllRows or getNRows + *+ * @exception UnsupportedOperationException + */ + public Iterator
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void setForceFormulaRecalculation(boolean value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean getForceFormulaRecalculation() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setAutobreaks(boolean value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setDisplayGuts(boolean value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setDisplayZeros(boolean value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean isDisplayZeros() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setFitToPage(boolean value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setRowSumsBelow(boolean value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setRowSumsRight(boolean value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean getAutobreaks() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint.. + *+ */ + public boolean getDisplayGuts() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean getFitToPage() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean getRowSumsBelow() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean getRowSumsRight() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean isPrintGridlines() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setPrintGridlines(boolean show) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean isPrintRowAndColumnHeadings() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void setPrintRowAndColumnHeadings(boolean show) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public PrintSetup getPrintSetup() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public Header getHeader() { + //
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public Footer getFooter() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setSelected(boolean value) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public double getMargin(short margin) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void setMargin(short margin, double size) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean getProtect() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void protectSheet(String password) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean getScenarioProtect() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void setZoom(int numerator, int denominator) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void setZoom(int scale) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public short getTopRow() { + //
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public short getLeftCol() { + //
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public void showInPane(int toprow, int leftcol) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void shiftRows(int startRow, int endRow, int n) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void shiftRows(int startRow, int endRow, int n, + boolean copyRowHeight, boolean resetOriginalRowHeight) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void createFreezePane(int colSplit, int rowSplit, + int leftmostColumn, int topRow) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void createFreezePane(int colSplit, int rowSplit) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void createSplitPane(int xSplitPos, int ySplitPos, + int leftmostColumn, int topRow, int activePane) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public PaneInformation getPaneInformation() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setDisplayGridlines(boolean show) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean isDisplayGridlines() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void setDisplayFormulas(boolean show) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean isDisplayFormulas() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setDisplayRowColHeadings(boolean show) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean isDisplayRowColHeadings() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setRowBreak(int row) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Will be supported in future. + *+ * @exception UnsupportedOperationException + */ + public boolean isRowBroken(int row) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void removeRowBreak(int row) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public int[] getRowBreaks() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public int[] getColumnBreaks() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setColumnBreak(int column) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean isColumnBroken(int column) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void removeColumnBreak(int column) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setColumnGroupCollapsed(int columnNumber, boolean collapsed) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void groupColumn(int fromColumn, int toColumn) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void ungroupColumn(int fromColumn, int toColumn) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void groupRow(int fromRow, int toRow) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void ungroupRow(int fromRow, int toRow) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setRowGroupCollapsed(int row, boolean collapse) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setDefaultColumnStyle(int column, CellStyle style) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void autoSizeColumn(int column) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void autoSizeColumn(int column, boolean useMergedCells) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public Comment getCellComment(int row, int column) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public Comment getCellComment(CellAddress ref) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * WNot supported due to memory footprint.. + *+ * @exception UnsupportedOperationException + */ + public Map
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public Drawing getDrawingPatriarch() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public Drawing createDrawingPatriarch() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Will not be supported due to memory constraints + *+ * @exception UnsupportedOperationException + */ + public Workbook getWorkbook() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Returns sheet name + *+ * @return String + */ + public String getSheetName() { + return sheetName; + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * + */ + public void setSheetName(String sheetName) { + //to avoid setting sheet name by user + if(this.sheetName == null)this.sheetName = sheetName; + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public boolean isSelected() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public CellRange extends Cell> setArrayFormula(String formula, + CellRangeAddress range) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public CellRange extends Cell> removeArrayFormula(Cell cell) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public DataValidationHelper getDataValidationHelper() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public List extends DataValidation> getDataValidations() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void addValidationData(DataValidation dataValidation) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public AutoFilter setAutoFilter(CellRangeAddress range) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public SheetConditionalFormatting getSheetConditionalFormatting() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public CellRangeAddress getRepeatingRows() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ */ + public CellRangeAddress getRepeatingColumns() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setRepeatingRows(CellRangeAddress rowRangeRef) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setRepeatingColumns(CellRangeAddress columnRangeRef) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public int getColumnOutlineLevel(int columnIndex) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public Hyperlink getHyperlink(int row, int column) { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public Hyperlink getHyperlink(CellAddress addr) { + throw new UnsupportedOperationException("Operation not supported."); + } + + + /** + *
+ * Will not be supported due to memory constraints + *+ * @exception UnsupportedOperationException + */ + public List extends Hyperlink> getHyperlinkList() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public CellAddress getActiveCell() { + throw new UnsupportedOperationException("Operation not supported."); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + 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
+ * Accepts the file path and return an instance of StreamedWorkBook + *+ * @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"); + } + } + + /** + *
+ * Fetch all sheets from given excel file + *+ * @return Iterator
+ * 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. + *+ * + * @return int + */ + public int getActiveSheetIndex() { + + return Integer.parseInt(getValuesFromWorkbookData(ACTIVE_SHEET_PATH)[0].toString()); + + } + + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * + * @exception UnsupportedOperationException + */ + public void setActiveSheet(int sheetIndex) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Returns the sheet number of the first visible sheet. + *+ * @return int + */ + public int getFirstVisibleTab() { + Object[] visibleTabs = getValuesFromWorkbookData(VISIBLE_SHEET_PATH); + + return (Integer.parseInt(visibleTabs[0].toString())-1); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void setFirstVisibleTab(int sheetIndex) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + * + */ + public void setSheetOrder(String sheetname, int pos) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + * + */ + public void setSelectedTab(int index) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public void setSheetName(int sheet, String name) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Returns the sheet name of specified index + *+ * @return String; + * + */ + public String getSheetName(int sheet) { + return getValuesFromWorkbookData(SHEET_NAME_PATH)[sheet].toString(); + } + + /** + *
+ * Returns the sheet index for the sheet name given + *+ * @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; + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + * + */ + public int getSheetIndex(Sheet sheet) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public Sheet createSheet() { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public Sheet createSheet(String sheetname) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + * + */ + public Sheet cloneSheet(int sheetNum) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Use Iterator+ * @exception UnsupportedOperationException + */ + public IteratorgetSheetIterator() instead. + *
+ * Returns the number of sheets, + *+ * @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; + } + + /** + *
+ * Returns sheet at specified index + *+ * @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; + } + + /** + *
+ * Returns the sheet with specified name + *+ * + */ + 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; + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void removeSheetAt(int index) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public Font createFont() { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + 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"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + 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"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public short getNumberOfFonts() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public Font getFontAt(short idx) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public CellStyle createCellStyle() { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public int getNumCellStyles() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Not Suppored due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public CellStyle getCellStyleAt(int idx) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void write(OutputStream stream) throws IOException { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Close the workbook + *+ * + */ + 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; + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public int getNumberOfNames() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public Name getName(String name) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public List extends Name> getNames(String name) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public List extends Name> getAllNames() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public Name getNameAt(int nameIndex) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public Name createName() { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public int getNameIndex(String name) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void removeName(int index) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void removeName(String name) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void removeName(Name name) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public int linkExternalWorkbook(String name, Workbook workbook) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * + */ + public void setPrintArea(int sheetIndex, String reference) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setPrintArea(int sheetIndex, int startColumn, int endColumn, + int startRow, int endRow) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public String getPrintArea(int sheetIndex) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void removePrintArea(int sheetIndex) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public MissingCellPolicy getMissingCellPolicy() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public DataFormat createDataFormat() { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public int addPicture(byte[] pictureData, int format) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported due to memory footprint. + *+ * @exception UnsupportedOperationException + */ + public List extends PictureData> getAllPictures() { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public CreationHelper getCreationHelper() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public boolean isHidden() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setHidden(boolean hiddenFlag) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Return true if the sheet with given index is hidden + *+ * @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; + } + + /** + *
+ * Return true if the sheet with given index is veryHidden + *+ * @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; + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setSheetHidden(int sheetIx, boolean hidden) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setSheetHidden(int sheetIx, int hidden) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void addToolPack(UDFFinder toopack) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setForceFormulaRecalculation(boolean value) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Will be supported in the future. + *+ * + */ + public boolean getForceFormulaRecalculation() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + *
+ * Will be supported in the future. + *+ * @exception UnsupportedOperationException + */ + public SpreadsheetVersion getSpreadsheetVersion() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + + /** + *
+ * Use Iterator+ * @exception UnsupportedOperationException + */ + public IteratorgetSheetIterator() instead. + *
+ * Returns the visibility of sheet for the given index. + *+ * @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; + } + + /** + * TO DO: Very Hidden + */ + + throw new IllegalArgumentException("Invalid sheet index"); + + + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + public void setSheetVisibility(int sheetIx, SheetVisibility visibility) { + throw new UnsupportedOperationException("Not supported due to memory footprint"); + } + + /** + *
+ * Not supported right now, as StreamedWorkbook + * supports only reading. + *+ * @exception UnsupportedOperationException + */ + 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