Java Code Examples for org.apache.poi.xssf.model.StylesTable

The following examples show how to use org.apache.poi.xssf.model.StylesTable. These examples are extracted from open source projects. 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 Project: hop   Source File: StaxPoiSheetTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: hop   Source File: StaxPoiSheetTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 3
Source Project: poiji   Source File: XSSFUnmarshaller.java    License: MIT License 6 votes vote down vote up
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 4
Source Project: DBus   Source File: XLSX2CSV.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source Project: azeroth   Source File: XLSX2CSV.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 6
Source Project: bdf3   Source File: XLSX2CSV.java    License: Apache License 2.0 6 votes vote down vote up
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 7
Source Project: jeesuite-libs   Source File: XLSX2CSV.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 8
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 9
Source Project: pentaho-kettle   Source File: StaxPoiSheetTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 10
Source Project: hop   Source File: StaxPoiSheetTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 11
Source Project: hop   Source File: StaxPoiSheetTest.java    License: Apache License 2.0 5 votes vote down vote up
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 12
Source Project: hop   Source File: StaxPoiSheetTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 13
Source Project: hop   Source File: StaxPoiSheetTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 14
Source Project: hop   Source File: StaxPoiSheetTest.java    License: Apache License 2.0 5 votes vote down vote up
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 15
Source Project: hop   Source File: StaxPoiSheetTest.java    License: Apache License 2.0 5 votes vote down vote up
@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() );
}
 
Example 16
Source Project: DBus   Source File: XLSX2CSV.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Accepts objects needed while parsing.
 *
 * @param styles  Table of styles
 * @param strings Table of shared strings
 * @param cols    Minimum number of columns to show
 * @param target  Sink for output
 */
public MyXSSFSheetHandler(StylesTable styles,
                          ReadOnlySharedStringsTable strings, int cols, PrintStream target) {
    this.stylesTable = styles;
    this.sharedStringsTable = strings;
    this.minColumnCount = cols;
    this.output = target;
    this.value = new StringBuffer();
    this.nextDataType = xssfDataType.NUMBER;
    this.formatter = new DataFormatter();
}
 
Example 17
Source Project: DBus   Source File: XLSX2CSV.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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, 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 18
Source Project: azeroth   Source File: XLSX2CSV.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 19
Source Project: bdf3   Source File: XLSX2CSV.java    License: Apache License 2.0 5 votes vote down vote up
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 20
Source Project: hadoopoffice   Source File: XSSFPullParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param sheetName        name of sheet
 * @param sheetInputStream sheet in xlsx format input stream
 * @param sst              Shared strings table of Excel file
 * @param styles           StylesTable of the document
 * @param isDate1904       date format 1904 (true) or 1900 (false)
 * @throws XMLStreamException
 */
public XSSFPullParser(String sheetName, InputStream sheetInputStream, SharedStringsTable sst, StylesTable styles,
		DataFormatter dataFormatter, boolean isDate1904) throws XMLStreamException {
	this.sheetName = sheetName;
	this.xer = StaxHelper.newXMLInputFactory().createXMLEventReader(sheetInputStream);
	this.nextBeingCalled = false;
	this.finalized = false;
	this.nextRow = 1;
	this.currentRow = 1;
	this.sst = sst;
	this.styles = styles;
	this.dataFormatter = dataFormatter;
	this.isDate1904 = isDate1904;
}
 
Example 21
Source Project: jeesuite-libs   Source File: XLSX2CSV.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 22
Source Project: components   Source File: StreamingWorkbookReader.java    License: Apache License 2.0 5 votes vote down vote up
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 23
Source Project: data-prep   Source File: StreamingSheetReader.java    License: Apache License 2.0 5 votes vote down vote up
public StreamingSheetReader(ReadOnlySharedStringsTable sst, StylesTable stylesTable, XMLEventReader parser,
        int rowCacheSize) {
    this.sst = sst;
    this.stylesTable = stylesTable;
    this.parser = parser;
    this.rowCacheSize = rowCacheSize;
}
 
Example 24
Source Project: data-prep   Source File: StreamingWorkbookReader.java    License: Apache License 2.0 5 votes vote down vote up
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 25
Source Project: data-prep   Source File: StreamingSheetTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 26
Source Project: birt   Source File: XlsxFileReader.java    License: Eclipse Public License 1.0 5 votes vote down vote up
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 27
Source Project: birt   Source File: XlsxFileReader.java    License: Eclipse Public License 1.0 5 votes vote down vote up
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 28
Source Project: birt   Source File: XlsxFileReader.java    License: Eclipse Public License 1.0 5 votes vote down vote up
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 29
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 30
Source Project: nifi   Source File: ConvertExcelToCSVProcessor.java    License: Apache License 2.0 5 votes vote down vote up
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;
}