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

The following examples show how to use org.apache.poi.xssf.model.SharedStringsTable. 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: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 7 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open( filename );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example 2
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 7 votes vote down vote up
/**只遍历一个电子表格,其中sheetId为要遍历的sheet索引,从1开始,1-3
 * @param filename
 * @param sheetId
 * @throws Exception
 */
public void processOneSheet(String filename,int sheetId) throws Exception {
	OPCPackage pkg = OPCPackage.open(filename);
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	
	// 根据 rId# 或 rSheet# 查找sheet
	InputStream sheet2 = r.getSheet( "rId"+sheetId);
	sheetIndex++;
	InputSource sheetSource = new InputSource(sheet2);
	parser.parse(sheetSource);
	sheet2.close();
}
 
Example 3
Source Project: frpMgr   Source File: ExcelReader.java    License: MIT License 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @throws Exception
 */
public void process(String filename) throws Exception {
	OPCPackage pkg = OPCPackage.open(filename);
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse(sheetSource);
		sheet.close();
	}
}
 
Example 4
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 5
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 6
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open( filename );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example 7
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param is
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example 8
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param is
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example 9
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open( filename );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example 10
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param is
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example 11
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open( filename );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example 12
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param is
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example 13
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open( filename );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example 14
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param is
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example 15
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open(filename);
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example 16
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
}
 
Example 17
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open(filename);
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example 18
Source Project: o2oa   Source File: Excel2007Reader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
}
 
Example 19
Source Project: javautils   Source File: XSSFUtil.java    License: Apache License 2.0 6 votes vote down vote up
public void processAllSheets(String filename) throws Exception {
    OPCPackage pkg = OPCPackage.open(filename);
    XSSFReader r = new XSSFReader( pkg );
    SharedStringsTable sst = r.getSharedStringsTable();

    XMLReader parser = fetchSheetParser(sst);

    Iterator<InputStream> sheets = r.getSheetsData();
    while(sheets.hasNext()) {
        System.out.println("Processing new sheet:\n");
        InputStream sheet = sheets.next();
        InputSource sheetSource = new InputSource(sheet);
        parser.parse(sheetSource);
        sheet.close();
        System.out.println("");
    }
}
 
Example 20
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 21
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 22
Source Project: frpMgr   Source File: ExcelReader.java    License: MIT License 5 votes vote down vote up
/**
 * 只遍历一个电子表格,其中sheetId为要遍历的sheet索引,从1开始,1-3
 * @param filename
 * @param sheetId
 * @throws Exception
 */
public void process(String filename, int sheetId) throws Exception {
	OPCPackage pkg = OPCPackage.open(filename);
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	// 根据 rId# 或 rSheet# 查找sheet
	InputStream sheet2 = r.getSheet("rId" + sheetId);
	sheetIndex++;
	InputSource sheetSource = new InputSource(sheet2);
	parser.parse(sheetSource);
	sheet2.close();
}
 
Example 23
Source Project: frpMgr   Source File: ExcelReader.java    License: MIT License 5 votes vote down vote up
public XMLReader fetchSheetParser(SharedStringsTable sst)
		throws SAXException {
	XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
	this.sst = sst;
	parser.setContentHandler(this);
	return parser;
}
 
Example 24
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 25
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 26
Source Project: hop   Source File: StaxPoiSheetTest.java    License: Apache License 2.0 5 votes vote down vote up
private SharedStringsTable mockSharedStringsTable( String... strings ) {
  SharedStringsTable sst = new SharedStringsTable();
  for ( String str : strings ) {
    CTRst st = CTRst.Factory.newInstance();
    st.setT( str );
    sst.addEntry( st );
  }
  return sst;
}
 
Example 27
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 28
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 29
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 30
Source Project: hop   Source File: StaxPoiSheetTest.java    License: Apache License 2.0 5 votes vote down vote up
private SharedStringsTable mockSharedStringsTable( String... strings ) {
  SharedStringsTable sst = new SharedStringsTable();
  for ( String str : strings ) {
    CTRst st = CTRst.Factory.newInstance();
    st.setT( str );
    sst.addEntry( st );
  }
  return sst;
}