本文整理汇总了Java中org.apache.poi.xssf.eventusermodel.XSSFReader类的典型用法代码示例。如果您正苦于以下问题:Java XSSFReader类的具体用法?Java XSSFReader怎么用?Java XSSFReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XSSFReader类属于org.apache.poi.xssf.eventusermodel包,在下文中一共展示了XSSFReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
/**
* 遍历工作簿中所有的电子表格
*
* @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();
}
}
示例2: process
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
/**
* 遍历工作簿中所有的电子表格
*
* @param filename
* @throws Exception
*/
public void process(InputStream stream) throws Exception {
OPCPackage pkg = OPCPackage.open(stream);
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();
}
}
示例3: unmarshal
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T> List<T> unmarshal(Class<T> type) {
try (OPCPackage open = OPCPackage.open(poijiFile.file())) {
ReadOnlySharedStringsTable readOnlySharedStringsTable = new ReadOnlySharedStringsTable(open);
XSSFReader xssfReader = new XSSFReader(open);
StylesTable styles = xssfReader.getStylesTable();
SheetIterator iter = (SheetIterator) xssfReader.getSheetsData();
int index = 0;
while (iter.hasNext()) {
try (InputStream stream = iter.next()) {
if (index == options.sheetIndex()) {
return processSheet(styles, readOnlySharedStringsTable, type, stream);
}
}
++index;
}
return new ArrayList<>();
} catch (SAXException | IOException | OpenXML4JException e) {
throw new PoijiException("Problem occurred while reading data", e);
}
}
示例4: process
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
/**
* 遍历工作簿中所有的电子表格
*
* @param filename string
* @throws Exception if an error occurred
*/
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();
}
}
示例5: processAll
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
private void processAll(OPCPackage pkg)
throws IOException, OpenXML4JException, InvalidFormatException, SAXException {
XSSFReader xssfReader = new XSSFReader(pkg);
mStylesTable = xssfReader.getStylesTable();
SharedStringsTable sst = xssfReader.getSharedStringsTable();
XMLReader parser = this.fetchSheetParser(sst);
Iterator<InputStream> sheets = xssfReader.getSheetsData();
while (sheets.hasNext()) {
mCurrentRowIndex = 0;
mSheetIndex++;
InputStream sheet = sheets.next();
InputSource sheetSource = new InputSource(sheet);
parser.parse(sheetSource);
sheet.close();
}
pkg.close();
}
示例6: processBySheet
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
private void processBySheet(int sheetIndex, OPCPackage pkg)
throws IOException, OpenXML4JException, InvalidFormatException, SAXException {
XSSFReader r = new XSSFReader(pkg);
SharedStringsTable sst = r.getSharedStringsTable();
XMLReader parser = fetchSheetParser(sst);
// rId2 found by processing the Workbook
// 根据 rId# 或 rSheet# 查找sheet
InputStream sheet = r.getSheet("rId" + (sheetIndex + 1));
mSheetIndex++;
InputSource sheetSource = new InputSource(sheet);
parser.parse(sheetSource);
sheet.close();
pkg.close();
}
示例7: process
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
/**
* 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;
}
示例8: execute
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
public void execute(InputStream inputStream, IParseExcelRowMapper parseExcelRowMapper) throws Exception {
OPCPackage pkg = OPCPackage.open(inputStream);
XSSFReader xssfReader = new XSSFReader(pkg);
sst = xssfReader.getSharedStringsTable();
stylesTable = xssfReader.getStylesTable();
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxFactory.newSAXParser();
XMLReader parser = saxParser.getXMLReader();
parser.setContentHandler(new XSSFParserHandler());
this.parseExcelRowMapper = parseExcelRowMapper;
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
while (iter.hasNext()) {
curRow = 0;
sheetIndex++;
InputStream sheet = iter.next();
sheetName = iter.getSheetName();
InputSource sheetSource = new InputSource(sheet);
parser.parse(sheetSource);
sheet.close();
}
}
示例9: LowMemXlsReader
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
public LowMemXlsReader( InputStream stream ) throws IOException {
log.debug( "reading with lo-mem xls reader" );
sharedStrings = new ArrayList<>();
try {
pkg = OPCPackage.open( stream );
reader = new XSSFReader( pkg );
styles = reader.getStylesTable();
sheetNameIdLkp = readSheetInfo( reader );
populateSharedStrings( reader );
}
catch ( OpenXML4JException e ) {
throw new IOException( "unexpected error" + e.getLocalizedMessage(), e );
}
}
示例10: readExcel
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
private <T> List<T> readExcel(OPCPackage opcPackage, Class<?> pojoClass, ImportParams params,
ISaxRowRead rowRead, IExcelReadRowHanlder hanlder) {
try {
XSSFReader xssfReader = new XSSFReader(opcPackage);
SharedStringsTable sst = xssfReader.getSharedStringsTable();
if (rowRead == null) {
rowRead = new SaxRowRead(pojoClass, params, hanlder);
}
XMLReader parser = fetchSheetParser(sst, rowRead);
Iterator<InputStream> sheets = xssfReader.getSheetsData();
int sheetIndex = 0;
while (sheets.hasNext() && sheetIndex < params.getSheetNum()) {
sheetIndex++;
InputStream sheet = sheets.next();
InputSource sheetSource = new InputSource(sheet);
parser.parse(sheetSource);
sheet.close();
}
return rowRead.getList();
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
throw new ExcelImportException("SAX导入数据失败");
}
}
示例11: process
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
/**
* 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;
}
示例12: streamSheetByName
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
@Override
public void streamSheetByName(String sheetName) throws IOException, SAXException, OpenXML4JException, ParserConfigurationException, SheetNotFoundException {
if (sheetName == null) {
throw new IllegalArgumentException("SheetName can't be null!");
} else if (sheetName.isEmpty()) {
throw new IllegalArgumentException("SheetName can't be empty!");
}
XSSFReader streamer = new XSSFReader(pack);
SheetIterator sheetIterator = (SheetIterator) streamer.getSheetsData();
int sheetNumber = 0;
InputStream stream;
while (sheetIterator.hasNext()) {
stream = sheetIterator.next();
if (sheetIterator.getSheetName().contentEquals(sheetName)) {
dataCallback.onBegin();
streamSheet(streamer, stream, sheetNumber);
dataCallback.onEnd();
return;
}
sheetNumber++;
}
throw new SheetNotFoundException(sheetName);
}
示例13: streamSheetByIndex
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
@Override
public void streamSheetByIndex(int index) throws IOException, SAXException, OpenXML4JException, ParserConfigurationException, SheetNotFoundException {
if (index < 0) {
throw new IllegalArgumentException("Index must be higher than -1!");
}
XSSFReader streamer = new XSSFReader(pack);
SheetIterator sheetIterator = (SheetIterator) streamer.getSheetsData();
int sheetNumber = 0;
InputStream stream;
while (sheetIterator.hasNext()) {
stream = sheetIterator.next();
if (sheetNumber == index) {
dataCallback.onBegin();
streamSheet(streamer, stream, sheetNumber);
dataCallback.onEnd();
return;
}
sheetNumber++;
}
throw new SheetNotFoundException(index);
}
示例14: getSheetIndexBySheetName
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
/**
* Fetch the index of the sheet by its name.
*
* @param sheetName
* @return The sheet index, -1 otherwise
* @throws IOException
* @throws SAXException
* @throws OpenXML4JException
*/
public int getSheetIndexBySheetName(String sheetName) throws IOException, SAXException, OpenXML4JException {
if (sheetName == null) {
throw new IllegalArgumentException("SheetName can't be null!");
} else if (sheetName.isEmpty()) {
throw new IllegalArgumentException("SheetName can't be empty!");
}
int index = 0;
XSSFReader streamer = new XSSFReader(pack);
SheetIterator sheetIterator = (SheetIterator) streamer.getSheetsData();
while (sheetIterator.hasNext()) {
sheetIterator.next();
if (sheetIterator.getSheetName().contentEquals(sheetName)) {
return index;
}
index++;
}
return -1;
}
示例15: processOneSheet
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入依赖的package包/类
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);
// rId2 found by processing the Workbook
// 根据 rId# 或 rSheet# 查找sheet
InputStream sheet2 = r.getSheet("rId" + sheetId);
sheetIndex++;
InputSource sheetSource = new InputSource(sheet2);
parser.parse(sheetSource);
sheet2.close();
pkg.close();
}