本文整理汇总了Java中org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler类的典型用法代码示例。如果您正苦于以下问题:Java XSSFSheetXMLHandler类的具体用法?Java XSSFSheetXMLHandler怎么用?Java XSSFSheetXMLHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XSSFSheetXMLHandler类属于org.apache.poi.xssf.eventusermodel包,在下文中一共展示了XSSFSheetXMLHandler类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processSheet
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T> List<T> processSheet(StylesTable styles, ReadOnlySharedStringsTable readOnlySharedStringsTable,
Class<T> type, InputStream sheetInputStream) {
DataFormatter formatter = new DataFormatter();
InputSource sheetSource = new InputSource(sheetInputStream);
try {
XMLReader sheetParser = SAXHelper.newXMLReader();
PoijiHandler poijiHandler = new PoijiHandler(type, options);
ContentHandler contentHandler =
new XSSFSheetXMLHandler(styles, null, readOnlySharedStringsTable, poijiHandler, formatter, false);
sheetParser.setContentHandler(contentHandler);
sheetParser.parse(sheetSource);
return poijiHandler.getDataset();
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new PoijiException("Problem occurred while reading data", e);
}
}
示例2: processSheet
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler; //导入依赖的package包/类
public void processSheet(SheetContentsHandler sheetContentsExtractor,
StylesTable styles, ReadOnlySharedStringsTable strings,
InputStream sheetInputStream) throws IOException, SAXException {
InputSource sheetSource = new InputSource(sheetInputStream);
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
try {
SAXParser saxParser = saxFactory.newSAXParser();
XMLReader sheetParser = saxParser.getXMLReader();
XSSFSheetInterestingPartsCapturer handler = new XSSFSheetInterestingPartsCapturer(
new XSSFSheetXMLHandler(styles, strings, sheetContentsExtractor,
formatter, false));
sheetParser.setContentHandler(handler);
sheetParser.parse(sheetSource);
sheetInputStream.close();
if (handler.hasProtection) {
metadata.set(TikaMetadataKeys.PROTECTED, "true");
}
} catch (ParserConfigurationException e) {
throw new RuntimeException("SAX parser appears to be broken - "
+ e.getMessage());
}
}
示例3: processSheet
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler; //导入依赖的package包/类
/**
* Parses and shows the content of one sheet using the specified styles and
* shared-strings tables.
*
* @param styles
* @param strings
* @param sheetInputStream
*/
public void processSheet(StylesTable styles, ReadOnlySharedStringsTable strings, SheetContentsHandler sheetHandler,
InputStream sheetInputStream) throws IOException, ParserConfigurationException, SAXException {
DataFormatter formatter = new DataFormatter();
InputSource sheetSource = new InputSource(sheetInputStream);
try {
XMLReader sheetParser = SAXHelper.newXMLReader();
ContentHandler handler = new XSSFSheetXMLHandler(styles, null, strings, sheetHandler, formatter, false);
sheetParser.setContentHandler(handler);
sheetParser.parse(sheetSource);
} catch (ParserConfigurationException e) {
throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage());
}
}
示例4: processSheet
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler; //导入依赖的package包/类
/**
* Parses and shows the content of one sheet using the specified styles and
* shared-strings tables.
*
* @param styles
* @param strings
* @param sheetInputStream
*/
public void processSheet(StylesTable styles, ReadOnlySharedStringsTable strings, SheetContentsHandler sheetHandler,
InputStream sheetInputStream) throws IOException, ParserConfigurationException, SAXException {
DataFormatter formatter = new DataFormatter();
InputSource sheetSource = new InputSource(sheetInputStream);
try {
XMLReader sheetParser = SAXHelper.newXMLReader();
ContentHandler handler = new XSSFSheetXMLHandler(styles, null, strings, sheetHandler, formatter, false);
sheetParser.setContentHandler(handler);
sheetParser.parse(sheetSource);
} catch (ParserConfigurationException e) {
throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage());
}
}
示例5: parseSheet
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler; //导入依赖的package包/类
private void parseSheet(StylesTable styles, ReadOnlySharedStringsTable sst, InputSource sheetSource, SheetContentsHandler handler) {
try {
createSheetParser( new XSSFSheetXMLHandler(styles, sst, handler, false)).parse(sheetSource);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例6: readSheet
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler; //导入依赖的package包/类
/**
* Parses the content of one sheet using the specified styles and shared-strings tables.
*
* @param styles a {@link StylesTable} object
* @param sharedStringsTable a {@link ReadOnlySharedStringsTable} object
* @param sheetInputStream a {@link InputStream} object
* @throws IOException
* @throws ParserConfigurationException
* @throws SAXException
*/
private void readSheet(StylesTable styles, ReadOnlySharedStringsTable sharedStringsTable,
InputStream sheetInputStream) throws IOException, ParserConfigurationException, SAXException {
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
XMLReader sheetParser = saxFactory.newSAXParser().getXMLReader();
ContentHandler handler =
new XSSFSheetXMLHandler(styles, sharedStringsTable, sheetContentsHandler, true);
sheetParser.setContentHandler(handler);
sheetParser.parse(new InputSource(sheetInputStream));
}
示例7: process
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler; //导入依赖的package包/类
/**
* Reads a list of POJOs from the given excel file.
*
* @param file Excel file to read from
* @param sheetName The sheet to extract from in the workbook
* @param reader The reader class to use to load the file from the sheet
*/
public static void process(File file, String sheetName, ZeroCellReader reader) {
try (FileInputStream fis = new FileInputStream(file);
OPCPackage opcPackage = OPCPackage.open(fis)) {
DataFormatter dataFormatter = new DataFormatter();
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(opcPackage);
XSSFReader xssfReader = new XSSFReader(opcPackage);
StylesTable stylesTable = xssfReader.getStylesTable();
InputStream sheetInputStream = null;
XSSFReader.SheetIterator sheets = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
while (sheets.hasNext()) {
sheetInputStream = sheets.next();
if (sheets.getSheetName().equalsIgnoreCase(sheetName)) {
break;
} else {
sheetInputStream = null;
}
}
if (Objects.isNull(sheetInputStream)) {
throw new SheetNotFoundException(sheetName);
}
XMLReader xmlReader = SAXHelper.newXMLReader();
xmlReader.setContentHandler(new XSSFSheetXMLHandler(stylesTable, strings, reader, dataFormatter, false));
xmlReader.parse(new InputSource(sheetInputStream));
sheetInputStream.close();
xmlReader = null;
sheetInputStream = null;
stylesTable = null;
strings = null;
xssfReader = null;
} catch(org.apache.poi.openxml4j.exceptions.InvalidFormatException | NotOfficeXmlFileException ife) {
throw new ZeroCellException("Cannot load file. The file must be an Excel 2007+ Workbook (.xlsx)");
} catch(SheetNotFoundException ex) {
throw new ZeroCellException(ex.getMessage());
} catch (ZeroCellException ze) {
throw ze; // Rethrow the Exception
} catch (Exception e) {
throw new ZeroCellException("Failed to process file", e);
}
}