org.apache.poi.xssf.model.StylesTable Java Examples
The following examples show how to use
org.apache.poi.xssf.model.StylesTable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StaxPoiSheetTest.java From hop with Apache License 2.0 | 6 votes |
@Test public void testInlineString() throws Exception { final String sheetId = "1"; final String sheetName = "Sheet 1"; XSSFReader reader = mockXSSFReader( sheetId, SHEET_INLINE_STRINGS, mock( SharedStringsTable.class ), mock( StylesTable.class ) ); StaxPoiSheet spSheet = new StaxPoiSheet( reader, sheetName, sheetId ); KCell[] rowCells = spSheet.getRow( 0 ); assertEquals( "Test1", rowCells[ 0 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() ); assertEquals( "Test2", rowCells[ 1 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() ); rowCells = spSheet.getRow( 1 ); assertEquals( "value 1 1", rowCells[ 0 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() ); assertEquals( "value 2 1", rowCells[ 1 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() ); rowCells = spSheet.getRow( 2 ); assertEquals( "value 1 2", rowCells[ 0 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() ); assertEquals( "value 2 2", rowCells[ 1 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() ); }
Example #2
Source File: StaxPoiSheetTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void testInlineString() throws Exception { final String sheetId = "1"; final String sheetName = "Sheet 1"; XSSFReader reader = mockXSSFReader( sheetId, SHEET_INLINE_STRINGS, mock( SharedStringsTable.class ), mock( StylesTable.class ) ); StaxPoiSheet spSheet = new StaxPoiSheet( reader, sheetName, sheetId ); KCell[] rowCells = spSheet.getRow( 0 ); assertEquals( "Test1", rowCells[ 0 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() ); assertEquals( "Test2", rowCells[ 1 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() ); rowCells = spSheet.getRow( 1 ); assertEquals( "value 1 1", rowCells[ 0 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() ); assertEquals( "value 2 1", rowCells[ 1 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() ); rowCells = spSheet.getRow( 2 ); assertEquals( "value 1 2", rowCells[ 0 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() ); assertEquals( "value 2 2", rowCells[ 1 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() ); }
Example #3
Source File: XLSX2CSV.java From bdf3 with Apache License 2.0 | 6 votes |
public void process() throws IOException, OpenXML4JException, ParserConfigurationException, SAXException { ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable( this.xlsxPackage); XSSFReader xssfReader = new XSSFReader(this.xlsxPackage); StylesTable styles = xssfReader.getStylesTable(); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader .getSheetsData(); int index = 0; while (iter.hasNext()) { InputStream stream = iter.next(); String sheetName = iter.getSheetName(); this.output.println(); this.output.println(sheetName + " [index=" + index + "]:"); processSheet(styles, strings, stream); stream.close(); ++index; } close(); }
Example #4
Source File: XLSX2CSV.java From jeesuite-libs with Apache License 2.0 | 6 votes |
/** * Initiates the processing of the XLS workbook file to CSV. * * @throws IOException * @throws OpenXML4JException * @throws ParserConfigurationException * @throws SAXException */ public List<String> process() throws IOException, OpenXML4JException, ParserConfigurationException, SAXException { ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(this.xlsxPackage); XSSFReader xssfReader = new XSSFReader(this.xlsxPackage); StylesTable styles = xssfReader.getStylesTable(); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData(); int index = 0; while (iter.hasNext()) { if(blankRowNum == 10)break; InputStream stream = iter.next(); String sheetName = iter.getSheetName(); results.add(ExcelValidator.SHEET_NAME_PREFIX + sheetName); processSheet(styles, strings, new SheetToCSV(), stream); stream.close(); ++index; } return results; }
Example #5
Source File: StaxPoiSheetTest.java From hop with Apache License 2.0 | 6 votes |
@Test public void testInlineString() throws Exception { final String sheetId = "1"; final String sheetName = "Sheet 1"; XSSFReader reader = mockXSSFReader( sheetId, SHEET_INLINE_STRINGS, mock( SharedStringsTable.class ), mock( StylesTable.class ) ); StaxPoiSheet spSheet = new StaxPoiSheet( reader, sheetName, sheetId ); IKCell[] rowCells = spSheet.getRow( 0 ); assertEquals( "Test1", rowCells[ 0 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() ); assertEquals( "Test2", rowCells[ 1 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() ); rowCells = spSheet.getRow( 1 ); assertEquals( "value 1 1", rowCells[ 0 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() ); assertEquals( "value 2 1", rowCells[ 1 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() ); rowCells = spSheet.getRow( 2 ); assertEquals( "value 1 2", rowCells[ 0 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() ); assertEquals( "value 2 2", rowCells[ 1 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() ); }
Example #6
Source File: StreamingWorkbookReader.java From excel-streaming-reader with Apache License 2.0 | 6 votes |
void loadSheets(XSSFReader reader, SharedStringsTable sst, StylesTable stylesTable, int rowCacheSize) throws IOException, InvalidFormatException, XMLStreamException { lookupSheetNames(reader); //Some workbooks have multiple references to the same sheet. Need to filter //them out before creating the XMLEventReader by keeping track of their URIs. //The sheets are listed in order, so we must keep track of insertion order. SheetIterator iter = (SheetIterator) reader.getSheetsData(); Map<URI, InputStream> sheetStreams = new LinkedHashMap<>(); while(iter.hasNext()) { InputStream is = iter.next(); sheetStreams.put(iter.getSheetPart().getPartName().getURI(), is); } //Iterate over the loaded streams int i = 0; for(URI uri : sheetStreams.keySet()) { XMLEventReader parser = StaxHelper.newXMLInputFactory().createXMLEventReader(sheetStreams.get(uri)); sheets.add(new StreamingSheet(sheetProperties.get(i++).get("name"), new StreamingSheetReader(sst, stylesTable, parser, use1904Dates, rowCacheSize))); } }
Example #7
Source File: XSSFUnmarshaller.java From poiji with MIT License | 6 votes |
private <T> void processSheet(StylesTable styles, XMLReader reader, ReadOnlySharedStringsTable readOnlySharedStringsTable, Class<T> type, InputStream sheetInputStream, Consumer<? super T> consumer) { DataFormatter formatter = new DataFormatter(); InputSource sheetSource = new InputSource(sheetInputStream); try { PoijiHandler<T> poijiHandler = new PoijiHandler<>(type, options, consumer); ContentHandler contentHandler = new XSSFSheetXMLPoijiHandler(styles, null, readOnlySharedStringsTable, poijiHandler, formatter, false, options); reader.setContentHandler(contentHandler); reader.parse(sheetSource); } catch (SAXException | IOException e) { IOUtils.closeQuietly(sheetInputStream); throw new PoijiException("Problem occurred while reading data", e); } }
Example #8
Source File: XLSX2CSV.java From azeroth with Apache License 2.0 | 6 votes |
/** * Initiates the processing of the XLS workbook file to CSV. * * @throws IOException * @throws OpenXML4JException * @throws ParserConfigurationException * @throws SAXException */ public List<String> process() throws IOException, OpenXML4JException, ParserConfigurationException, SAXException { ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(this.xlsxPackage); XSSFReader xssfReader = new XSSFReader(this.xlsxPackage); StylesTable styles = xssfReader.getStylesTable(); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData(); int index = 0; while (iter.hasNext()) { if (blankRowNum == 10) { break; } InputStream stream = iter.next(); String sheetName = iter.getSheetName(); results.add(ExcelValidator.SHEET_NAME_PREFIX + sheetName); processSheet(styles, strings, new SheetToCSV(), stream); stream.close(); ++index; } return results; }
Example #9
Source File: XLSX2CSV.java From DBus with Apache License 2.0 | 6 votes |
/** * Initiates the processing of the XLS workbook file to CSV. * * @throws IOException * @throws OpenXML4JException * @throws ParserConfigurationException * @throws SAXException */ public void process() throws IOException, OpenXML4JException, ParserConfigurationException, SAXException { ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable( this.xlsxPackage); XSSFReader xssfReader = new XSSFReader(this.xlsxPackage); StylesTable styles = xssfReader.getStylesTable(); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader .getSheetsData(); //int index = 0; while (iter.hasNext()) { InputStream stream = iter.next(); //String sheetName = iter.getSheetName(); //this.output.println(); //this.output.println(sheetName + " [index=" + index + "]:"); processSheet(styles, strings, stream); stream.close(); //++index; } }
Example #10
Source File: XlsxFileReader.java From birt with Eclipse Public License 1.0 | 5 votes |
private SheetHandler(StylesTable st, SharedStringsTable sst, XlsxRowCallBack callback, int xlsxRowsToRead) { this.sst = sst; this.st = st; this.callback = callback; values = new ArrayList<Object>(); this.cellDataType = cDataType.NUMBER; this.xlsxRowsToRead = xlsxRowsToRead; sdf = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" );//ISO date format }
Example #11
Source File: XLSX2CSV.java From jeesuite-libs with Apache License 2.0 | 5 votes |
/** * Parses and shows the content of one sheet using the specified styles and * shared-strings tables. * * @param styles * @param strings * @param sheetInputStream */ public void processSheet(StylesTable styles, ReadOnlySharedStringsTable strings, SheetContentsHandler sheetHandler, InputStream sheetInputStream) throws IOException, ParserConfigurationException, SAXException { DataFormatter formatter = new DataFormatter(); InputSource sheetSource = new InputSource(sheetInputStream); try { XMLReader sheetParser = SAXHelper.newXMLReader(); ContentHandler handler = new XSSFSheetXMLHandler(styles, null, strings, sheetHandler, formatter, false); sheetParser.setContentHandler(handler); sheetParser.parse(sheetSource); } catch (ParserConfigurationException e) { throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage()); } }
Example #12
Source File: StreamingWorkbookReader.java From components with Apache License 2.0 | 5 votes |
void loadSheets(XSSFReader reader, SharedStringsTable sst, StylesTable stylesTable, int rowCacheSize) throws IOException, InvalidFormatException, XMLStreamException { lookupSheetNames(reader.getWorkbookData()); Iterator<InputStream> iter = reader.getSheetsData(); int i = 0; while (iter.hasNext()) { XMLEventReader parser = XMLInputFactory.newInstance().createXMLEventReader(iter.next()); if(i < sheetNames.size()) { sheets.add(new StreamingSheet(sheetNames.get(i++), new StreamingSheetReader(sst, stylesTable, parser, rowCacheSize))); } } }
Example #13
Source File: StreamingSheetReader.java From data-prep with Apache License 2.0 | 5 votes |
public StreamingSheetReader(ReadOnlySharedStringsTable sst, StylesTable stylesTable, XMLEventReader parser, int rowCacheSize) { this.sst = sst; this.stylesTable = stylesTable; this.parser = parser; this.rowCacheSize = rowCacheSize; }
Example #14
Source File: StreamingWorkbookReader.java From data-prep with Apache License 2.0 | 5 votes |
void loadSheets(XSSFReader reader, ReadOnlySharedStringsTable sst, StylesTable stylesTable, int rowCacheSize) throws IOException, InvalidFormatException, XMLStreamException { lookupSheetNames(reader.getWorkbookData()); Iterator<InputStream> iter = reader.getSheetsData(); int i = 0; while (iter.hasNext()) { XMLEventReader parser = XMLInputFactory.newInstance().createXMLEventReader(iter.next()); sheets.add(new StreamingSheet(sheetNames.get(i++), new StreamingSheetReader(sst, stylesTable, parser, rowCacheSize))); } }
Example #15
Source File: StreamingSheetTest.java From data-prep with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { OPCPackage pkg = OPCPackage.open(StreamingSheetTest.class.getResourceAsStream("../dates.xlsx")); XSSFReader reader = new XSSFReader(pkg); ReadOnlySharedStringsTable sst = new ReadOnlySharedStringsTable(pkg); StylesTable styles = reader.getStylesTable(); Iterator<InputStream> iter = reader.getSheetsData(); XMLEventReader parser = XMLInputFactory.newInstance().createXMLEventReader(iter.next()); final StreamingSheetReader streamingSheetReader = new StreamingSheetReader(sst, styles, parser, 10); streamingSheet = new StreamingSheet("name", streamingSheetReader); }
Example #16
Source File: XlsxFileReader.java From birt with Eclipse Public License 1.0 | 5 votes |
public void processSheet(String rid, XlsxRowCallBack callback, int xlsxRowsToRead) throws InvalidFormatException, IOException, SAXException { SharedStringsTable sst = reader.getSharedStringsTable(); StylesTable st = reader.getStylesTable(); XMLReader parser = fetchSheetParser(st, sst, callback, xlsxRowsToRead); BufferedInputStream sheet = new BufferedInputStream(reader.getSheet(rid)); try { InputSource sheetSource = new InputSource(sheet); parser.parse(sheetSource); } finally { if (sheet != null) sheet.close(); } }
Example #17
Source File: XlsxFileReader.java From birt with Eclipse Public License 1.0 | 5 votes |
private XMLReader fetchSheetParser(StylesTable st, SharedStringsTable sst, XlsxRowCallBack callback, int xlsxRowsToRead) throws SAXException { XMLReader parser = getXMLReader( ); ContentHandler handler = new SheetHandler(st, sst, callback, xlsxRowsToRead); parser.setContentHandler(handler); return parser; }
Example #18
Source File: StaxPoiSheetTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testNoUsedRangeSpecified() throws Exception { final String sheetId = "1"; final String sheetName = "Sheet 1"; SharedStringsTable sharedStringsTableMock = mockSharedStringsTable( "Report ID", "Report ID", "Approval Status", "Total Report Amount", "Policy", "ReportIdValue_1", "ReportIdValue_1", "ApprovalStatusValue_1", "PolicyValue_1" ); XSSFReader reader = mockXSSFReader( sheetId, SHEET_NO_USED_RANGE_SPECIFIED, sharedStringsTableMock, mock( StylesTable.class ) ); StaxPoiSheet spSheet = new StaxPoiSheet( reader, sheetName, sheetId ); // The first row is empty - it should have empty rowCells KCell[] rowCells = spSheet.getRow( 0 ); assertEquals( 0, rowCells.length ); // The second row - is the header - just skip it rowCells = spSheet.getRow( 1 ); assertEquals( 0, rowCells.length ); // The row3 - is the first row with data - validating it rowCells = spSheet.getRow( 2 ); assertEquals( KCellType.LABEL, rowCells[ 0 ].getType() ); assertEquals( "ReportIdValue_1", rowCells[ 0 ].getValue() ); assertEquals( KCellType.LABEL, rowCells[ 1 ].getType() ); assertEquals( "ReportIdValue_1", rowCells[ 1 ].getValue() ); assertEquals( KCellType.LABEL, rowCells[ 2 ].getType() ); assertEquals( "ApprovalStatusValue_1", rowCells[ 2 ].getValue() ); assertEquals( KCellType.NUMBER, rowCells[ 3 ].getType() ); assertEquals( 2623.0, rowCells[ 3 ].getValue() ); assertEquals( KCellType.LABEL, rowCells[ 4 ].getType() ); assertEquals( "PolicyValue_1", rowCells[ 4 ].getValue() ); }
Example #19
Source File: StreamingSheetReader.java From excel-streaming-reader with Apache License 2.0 | 5 votes |
public StreamingSheetReader(SharedStringsTable sst, StylesTable stylesTable, XMLEventReader parser, final boolean use1904Dates, int rowCacheSize) { this.sst = sst; this.stylesTable = stylesTable; this.parser = parser; this.use1904Dates = use1904Dates; this.rowCacheSize = rowCacheSize; }
Example #20
Source File: ConvertExcelToCSVProcessor.java From nifi with Apache License 2.0 | 5 votes |
public ExcelSheetReadConfig(List<Integer> columnsToSkip, int overrideFirstRow, String sheetName, boolean formatValues, ReadOnlySharedStringsTable sst, StylesTable styles){ this.sheetName = sheetName; this.columnsToSkip = columnsToSkip; this.overrideFirstRow = overrideFirstRow; this.formatValues = formatValues; this.sst = sst; this.styles = styles; }
Example #21
Source File: ExcelReader.java From excelReader with MIT License | 5 votes |
/** * Parses the content of one sheet using the specified styles and shared-strings tables. * * @param styles a {@link StylesTable} object * @param sharedStringsTable a {@link ReadOnlySharedStringsTable} object * @param sheetInputStream a {@link InputStream} object * @throws IOException * @throws ParserConfigurationException * @throws SAXException */ private void readSheet(StylesTable styles, ReadOnlySharedStringsTable sharedStringsTable, InputStream sheetInputStream) throws IOException, ParserConfigurationException, SAXException { SAXParserFactory saxFactory = SAXParserFactory.newInstance(); XMLReader sheetParser = saxFactory.newSAXParser().getXMLReader(); ContentHandler handler = new XSSFSheetXMLHandler(styles, sharedStringsTable, sheetContentsHandler, true); sheetParser.setContentHandler(handler); sheetParser.parse(new InputSource(sheetInputStream)); }
Example #22
Source File: StaxPoiSheetTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testEmptySheet() throws Exception { XSSFReader reader = mockXSSFReader( "sheet1", SHEET_EMPTY, mock( SharedStringsTable.class ), mock( StylesTable.class ) ); // check no exceptions StaxPoiSheet sheet = new StaxPoiSheet( reader, "empty", "sheet1" ); for ( int j = 0; j < sheet.getRows(); j++ ) { sheet.getRow( j ); } }
Example #23
Source File: StaxPoiSheetTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private XSSFReader mockXSSFReader( final String sheetId, final String sheetContent, final SharedStringsTable sst, final StylesTable styles ) throws Exception { XSSFReader reader = mock( XSSFReader.class ); when( reader.getSharedStringsTable() ).thenReturn( sst ); when( reader.getStylesTable() ).thenReturn( styles ); when( reader.getSheet( sheetId ) ).thenAnswer( new Answer<InputStream>() { public InputStream answer( InvocationOnMock invocation ) throws Throwable { return IOUtils.toInputStream( sheetContent, "UTF-8" ); } } ); return reader; }
Example #24
Source File: StaxPoiSheetTest.java From hop with Apache License 2.0 | 5 votes |
@Test public void testEmptySheet() throws Exception { XSSFReader reader = mockXSSFReader( "sheet1", SHEET_EMPTY, mock( SharedStringsTable.class ), mock( StylesTable.class ) ); // check no exceptions StaxPoiSheet sheet = new StaxPoiSheet( reader, "empty", "sheet1" ); for ( int j = 0; j < sheet.getRows(); j++ ) { sheet.getRow( j ); } }
Example #25
Source File: XLSX2CSV.java From bdf3 with Apache License 2.0 | 5 votes |
public void processSheet(StylesTable styles, ReadOnlySharedStringsTable strings, InputStream sheetInputStream) throws IOException, ParserConfigurationException, SAXException { InputSource sheetSource = new InputSource(sheetInputStream); SAXParserFactory saxFactory = SAXParserFactory.newInstance(); SAXParser saxParser = saxFactory.newSAXParser(); XMLReader sheetParser = saxParser.getXMLReader(); ContentHandler handler = new MyXSSFSheetHandler(styles, strings, this.minColumns, this.output); sheetParser.setContentHandler(handler); sheetParser.parse(sheetSource); }
Example #26
Source File: StaxPoiSheetTest.java From hop with Apache License 2.0 | 5 votes |
private XSSFReader mockXSSFReader( final String sheetId, final String sheetContent, final SharedStringsTable sst, final StylesTable styles ) throws Exception { XSSFReader reader = mock( XSSFReader.class ); when( reader.getSharedStringsTable() ).thenReturn( sst ); when( reader.getStylesTable() ).thenReturn( styles ); when( reader.getSheet( sheetId ) ).thenAnswer( new Answer<InputStream>() { public InputStream answer( InvocationOnMock invocation ) throws Throwable { return IOUtils.toInputStream( sheetContent, "UTF-8" ); } } ); return reader; }
Example #27
Source File: StaxPoiSheetTest.java From hop with Apache License 2.0 | 5 votes |
@Test public void testNoUsedRangeSpecified() throws Exception { final String sheetId = "1"; final String sheetName = "Sheet 1"; SharedStringsTable sharedStringsTableMock = mockSharedStringsTable( "Report ID", "Report ID", "Approval Status", "Total Report Amount", "Policy", "ReportIdValue_1", "ReportIdValue_1", "ApprovalStatusValue_1", "PolicyValue_1" ); XSSFReader reader = mockXSSFReader( sheetId, SHEET_NO_USED_RANGE_SPECIFIED, sharedStringsTableMock, mock( StylesTable.class ) ); StaxPoiSheet spSheet = new StaxPoiSheet( reader, sheetName, sheetId ); // The first row is empty - it should have empty rowCells KCell[] rowCells = spSheet.getRow( 0 ); assertEquals( 0, rowCells.length ); // The second row - is the header - just skip it rowCells = spSheet.getRow( 1 ); assertEquals( 0, rowCells.length ); // The row3 - is the first row with data - validating it rowCells = spSheet.getRow( 2 ); assertEquals( KCellType.LABEL, rowCells[ 0 ].getType() ); assertEquals( "ReportIdValue_1", rowCells[ 0 ].getValue() ); assertEquals( KCellType.LABEL, rowCells[ 1 ].getType() ); assertEquals( "ReportIdValue_1", rowCells[ 1 ].getValue() ); assertEquals( KCellType.LABEL, rowCells[ 2 ].getType() ); assertEquals( "ApprovalStatusValue_1", rowCells[ 2 ].getValue() ); assertEquals( KCellType.NUMBER, rowCells[ 3 ].getType() ); assertEquals( 2623.0, rowCells[ 3 ].getValue() ); assertEquals( KCellType.LABEL, rowCells[ 4 ].getType() ); assertEquals( "PolicyValue_1", rowCells[ 4 ].getValue() ); }
Example #28
Source File: StaxPoiSheetTest.java From hop with Apache License 2.0 | 5 votes |
@Test public void testEmptySheet() throws Exception { XSSFReader reader = mockXSSFReader( "sheet1", SHEET_EMPTY, mock( SharedStringsTable.class ), mock( StylesTable.class ) ); // check no exceptions StaxPoiSheet sheet = new StaxPoiSheet( reader, "empty", "sheet1" ); for ( int j = 0; j < sheet.getRows(); j++ ) { sheet.getRow( j ); } }
Example #29
Source File: StaxPoiSheetTest.java From hop with Apache License 2.0 | 5 votes |
private XSSFReader mockXSSFReader( final String sheetId, final String sheetContent, final SharedStringsTable sst, final StylesTable styles ) throws Exception { XSSFReader reader = mock( XSSFReader.class ); when( reader.getSharedStringsTable() ).thenReturn( sst ); when( reader.getStylesTable() ).thenReturn( styles ); when( reader.getSheet( sheetId ) ).thenAnswer( new Answer<InputStream>() { public InputStream answer( InvocationOnMock invocation ) throws Throwable { return IOUtils.toInputStream( sheetContent, "UTF-8" ); } } ); return reader; }
Example #30
Source File: StaxPoiSheetTest.java From hop with Apache License 2.0 | 5 votes |
@Test public void testNoUsedRangeSpecified() throws Exception { final String sheetId = "1"; final String sheetName = "Sheet 1"; SharedStringsTable sharedStringsTableMock = mockSharedStringsTable( "Report ID", "Report ID", "Approval Status", "Total Report Amount", "Policy", "ReportIdValue_1", "ReportIdValue_1", "ApprovalStatusValue_1", "PolicyValue_1" ); XSSFReader reader = mockXSSFReader( sheetId, SHEET_NO_USED_RANGE_SPECIFIED, sharedStringsTableMock, mock( StylesTable.class ) ); StaxPoiSheet spSheet = new StaxPoiSheet( reader, sheetName, sheetId ); // The first row is empty - it should have empty rowCells IKCell[] rowCells = spSheet.getRow( 0 ); assertEquals( 0, rowCells.length ); // The second row - is the header - just skip it rowCells = spSheet.getRow( 1 ); assertEquals( 0, rowCells.length ); // The row3 - is the first row with data - validating it rowCells = spSheet.getRow( 2 ); assertEquals( KCellType.LABEL, rowCells[ 0 ].getType() ); assertEquals( "ReportIdValue_1", rowCells[ 0 ].getValue() ); assertEquals( KCellType.LABEL, rowCells[ 1 ].getType() ); assertEquals( "ReportIdValue_1", rowCells[ 1 ].getValue() ); assertEquals( KCellType.LABEL, rowCells[ 2 ].getType() ); assertEquals( "ApprovalStatusValue_1", rowCells[ 2 ].getValue() ); assertEquals( KCellType.NUMBER, rowCells[ 3 ].getType() ); assertEquals( 2623.0, rowCells[ 3 ].getValue() ); assertEquals( KCellType.LABEL, rowCells[ 4 ].getType() ); assertEquals( "PolicyValue_1", rowCells[ 4 ].getValue() ); }