本文整理汇总了Java中org.apache.poi.openxml4j.exceptions.OpenXML4JException类的典型用法代码示例。如果您正苦于以下问题:Java OpenXML4JException类的具体用法?Java OpenXML4JException怎么用?Java OpenXML4JException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OpenXML4JException类属于org.apache.poi.openxml4j.exceptions包,在下文中一共展示了OpenXML4JException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unmarshal
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; //导入依赖的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);
}
}
示例2: processAll
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; //导入依赖的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();
}
示例3: processBySheet
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; //导入依赖的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();
}
示例4: process
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; //导入依赖的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;
}
示例5: microsoftExcelDocumentToString
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; //导入依赖的package包/类
private static String microsoftExcelDocumentToString(InputStream inputStream) throws IOException, OpenXML4JException, XmlException {
StringBuilder sb = new StringBuilder();
try (InputStream excelStream = new BufferedInputStream(inputStream)) {
if (POIFSFileSystem.hasPOIFSHeader(excelStream)) { // Before 2007 format files
POIFSFileSystem excelFS = new POIFSFileSystem(excelStream);
ExcelExtractor excelExtractor = new ExcelExtractor(excelFS);
sb.append(excelExtractor.getText());
excelExtractor.close();
} else { // New format
XSSFWorkbook workBook = new XSSFWorkbook(excelStream);
int numberOfSheets = workBook.getNumberOfSheets();
for (int i = 0; i < numberOfSheets; i++) {
XSSFSheet sheet = workBook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.rowIterator();
while (rowIterator.hasNext()) {
XSSFRow row = (XSSFRow) rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
XSSFCell cell = (XSSFCell) cellIterator.next();
sb.append(cell.toString());
sb.append(" ");
}
sb.append("\n");
}
sb.append("\n");
}
}
}
return sb.toString();
}
示例6: LowMemXlsReader
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; //导入依赖的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 );
}
}
示例7: process
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; //导入依赖的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: readStreamToList
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; //导入依赖的package包/类
@Override
public void readStreamToList(InputStream stream,
ReaderCondition[] conditions, BingReadListener listener)
throws IOException, SQLException, OpenXML4JException, SAXException {
this.listener = listener;
BingExcelReaderListener listner = new BingExcelReaderListener(
conditions);
ReadHandler handler = ExcelReaderFactory.create(stream, listner, true);
int[] indexArr = new int[conditions.length];
int minNum = 0;
for (int i = 0; i < conditions.length; i++) {
int sheetNum = conditions[i].getSheetIndex();
indexArr[i] = sheetNum;
if (minNum > conditions[i].getEndRow()) {
minNum = conditions[i].getEndRow();
}
}
handler.readSheet(indexArr, minNum);
}
示例9: readStreamToList
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; //导入依赖的package包/类
@Override
public List<SheetVo> readStreamToList(InputStream stream, ReaderCondition[] conditions) throws IOException, SQLException, OpenXML4JException, SAXException {
List<SheetVo> resultList = Lists.newArrayList();
BingExcelReaderListener listner = new BingExcelReaderListener(conditions, resultList);
ReadHandler handler = ExcelReaderFactory.create(stream, listner, true);
int[] indexArr = new int[conditions.length];
int minNum = 0;
for (int i = 0; i < conditions.length; i++) {
int sheetNum = conditions[i].getSheetIndex();
indexArr[i] = sheetNum;
if (minNum > conditions[i].getEndRow()) {
minNum = conditions[i].getEndRow();
}
}
handler.readSheet(indexArr, minNum);
return resultList;
}
示例10: streamSheetByName
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; //导入依赖的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.openxml4j.exceptions.OpenXML4JException; //导入依赖的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.openxml4j.exceptions.OpenXML4JException; //导入依赖的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: parseXlsxFileAndWriteTmxBody
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; //导入依赖的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();
}
示例14: readRows
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; //导入依赖的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();
}
}
示例15: process
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; //导入依赖的package包/类
/**
* Initiates the processing of the XLS workbook file to CSV.
*
* @throws IOException
* @throws org.apache.poi.openxml4j.exceptions.OpenXML4JException
* @throws javax.xml.parsers.ParserConfigurationException
* @throws org.xml.sax.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();
PrintStream output = dispatcher.openStreamForSheet(iter.getSheetName());
processSheet(styles, strings, stream, output);
dispatcher.closeStreamForSheet(output, iter.getSheetName());
stream.close();
++index;
}
}