Java Code Examples for org.apache.poi.xssf.eventusermodel.XSSFReader#getSharedStringsTable()

The following examples show how to use org.apache.poi.xssf.eventusermodel.XSSFReader#getSharedStringsTable() . 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: Excel2007Reader.java    From o2oa with 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 File: Excel2007Reader.java    From o2oa with 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 3
Source File: Excel2007Reader.java    From o2oa with 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 4
Source File: Excel2007Reader.java    From o2oa with 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 5
Source File: Excel2007Reader.java    From o2oa with 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 6
Source File: Excel2007Reader.java    From o2oa with 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 File: XSSFUtil.java    From javautils with 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 8
Source File: Excel2007Reader.java    From o2oa with 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 File: ExcelReader.java    From frpMgr with 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 10
Source File: Excel2007Reader.java    From o2oa with 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 11
Source File: Excel2007Reader.java    From o2oa with 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 12
Source File: Excel2007Reader.java    From o2oa with 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 File: Excel2007Reader.java    From o2oa with 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 File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 5 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 15
Source File: StAXBasedParser.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Create instance
 * @param inputStream sheet input stream
 * @param pluginConfig config options
 * @param writer {@link VectorContainerWriter} for writing values into vectors.
 * @param managedBuf Workspace buffer.
 * @param maxCellSize maximum allowable size of variable length cells
 */
public StAXBasedParser(final InputStream inputStream, final ExcelFormatPluginConfig pluginConfig,
                       final VectorContainerWriter writer, final ArrowBuf managedBuf,
                       final HashSet<String> columnsToProject, final int maxCellSize) throws Exception {
  pkgInputStream = OPCPackage.open(inputStream);
  this.writer = writer.rootAsStruct();
  this.managedBuf = managedBuf;
  this.maxCellSize = maxCellSize;

  final XSSFReader xssfReader = new XSSFReader(pkgInputStream);

  // Find the sheet id of the given sheet name in workbook
  try (final InputStream wbInputStream = xssfReader.getWorkbookData()) {
    final String sheetId = ExcelUtil.getSheetId(wbInputStream, pluginConfig.sheet);
    if (sheetId == null) {
      throw new SheetNotFoundException();
    }

    // Open the InputStream for sheet
    sheetInputStream = xssfReader.getSheet(sheetId);
  }


  // WARNING: XSSFReader can actually return null instances of sst and styles
  sst = xssfReader.getSharedStringsTable();
  styles = checkNotNull(xssfReader.getStylesTable(), "Expected a valid styles table instance");

  init(pluginConfig.extractHeader, pluginConfig.hasMergedCells);

  this.columnsToProject = columnsToProject;
}
 
Example 16
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 5 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 17
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 5 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 18
Source File: XlsxHandler.java    From easyexcel with Apache License 2.0 5 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * 
 * @param filename
 * @throws IOException
 * @throws OpenXML4JException
 * @throws SAXException
 * @throws Exception
 */
public void process(String filename) throws IOException, OpenXML4JException, SAXException {
    OPCPackage pkg = null;
    try {
	    pkg = OPCPackage.open(filename);
        XSSFReader xssfReader = new XSSFReader(pkg);
        stylesTable = xssfReader.getStylesTable();
        SharedStringsTable sst = xssfReader.getSharedStringsTable();
        XMLReader parser = this.fetchSheetParser(sst);
        Iterator<InputStream> sheets = xssfReader.getSheetsData();
   		while (sheets.hasNext()) {
   			currRowIndex = 0;
   			sheetIndex++;
   			InputStream sheet = null;
   			try {
   			    sheet = sheets.next();
   			    InputSource sheetSource = new InputSource(sheet);
   			    parser.parse(sheetSource);
   			} finally {
   			    sheet.close();
               }
   		}
   		while (!context.fileEnd());
	} finally {
           pkg.close();
       }
}
 
Example 19
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 5 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 20
Source File: XlsxLoader.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void loadData(List<Tuple<String, File>> files, Importer importer) throws InvalidFileException, IOException {
  try {
    RowCellHandler rowCellHandler = makeRowCellHandler(importer);
    SAXParserFactory saxFactory = SAXParserFactory.newInstance();
    saxFactory.setNamespaceAware(true);
    for (Tuple<String, File> file : files) {
      OPCPackage pkg = OPCPackage.open(file.getRight().getPath());
      XSSFReader xssfReader = new XSSFReader(pkg);

      final SharedStringsTable sharedStringsTable = xssfReader.getSharedStringsTable();
      XSSFReader.SheetIterator worksheets = (XSSFReader.SheetIterator) xssfReader.getSheetsData();

      while (worksheets.hasNext()) {
        final InputStream sheet = worksheets.next();

        XMLReader sheetParser = saxFactory.newSAXParser().getXMLReader();
        sheetParser.setContentHandler(new SheetXmlParser(sharedStringsTable, rowCellHandler));

        rowCellHandler.start(worksheets.getSheetName());
        sheetParser.parse(new InputSource(sheet));
        rowCellHandler.finish();
      }
    }
  } catch (SAXException | OpenXML4JException | ParserConfigurationException e) {
    throw new InvalidFileException("Not a valid Excel file", e);
  }
}