本文整理汇总了Java中org.apache.poi.xssf.eventusermodel.XSSFReader.getSheetsData方法的典型用法代码示例。如果您正苦于以下问题:Java XSSFReader.getSheetsData方法的具体用法?Java XSSFReader.getSheetsData怎么用?Java XSSFReader.getSheetsData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.xssf.eventusermodel.XSSFReader
的用法示例。
在下文中一共展示了XSSFReader.getSheetsData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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);
}
}
示例3: 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();
}
}
示例4: 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();
}
}
示例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: 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;
}
示例7: 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();
}
}
示例8: 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导入数据失败");
}
}
示例9: 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;
}
示例10: 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);
}
示例11: 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);
}
示例12: 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;
}
示例13: process
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
/**
* 遍历 excel 文件
*/
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();
}
pkg.close();
}
示例14: parseXlsxFileAndWriteTmxBody
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
public void parseXlsxFileAndWriteTmxBody(String fileName, AbstractWriter tmxWriter, IProgressMonitor monitor)
throws ParserConfigurationException, SAXException, IOException, OpenXML4JException {
this.tmxWriter = tmxWriter;
this.monitor = monitor;
File file = new File(fileName);
long length = file.length();
monitor.beginTask("", countTotal(length));
OPCPackage p = OPCPackage.open(fileName, PackageAccess.READ);
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(p);
XSSFReader xssfReader = new XSSFReader(p);
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
try {
while (iter.hasNext()) {
InputStream stream = iter.next();
parse(stream, strings, tmxWriter);
stream.close();
// 目前只处理第一个sheet
break;
}
} finally {
p.close();
}
monitor.done();
}
示例15: readRows
import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
public void readRows(IProgressMonitor monitor) throws ParserConfigurationException, SAXException, IOException, OpenXML4JException {
monitor.beginTask("", 10);
monitor.worked(1);
OPCPackage p = OPCPackage.open(xlsxFile, PackageAccess.READ);
ReadOnlySharedStringsTable shareString = new ReadOnlySharedStringsTable(p);
XSSFReader xssfReader = new XSSFReader(p);
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
try {
while (iter.hasNext()) {
InputStream stream = iter.next();
readCells(stream, shareString, new SubProgressMonitor(monitor, 9));
stream.close();
// 目前只处理第一个sheet
break;
}
} finally {
p.close();
monitor.done();
}
}