本文整理汇总了Java中org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable类的典型用法代码示例。如果您正苦于以下问题:Java ReadOnlySharedStringsTable类的具体用法?Java ReadOnlySharedStringsTable怎么用?Java ReadOnlySharedStringsTable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReadOnlySharedStringsTable类属于org.apache.poi.xssf.eventusermodel包,在下文中一共展示了ReadOnlySharedStringsTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processSheet
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的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: unmarshal
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的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.ReadOnlySharedStringsTable; //导入依赖的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;
}
示例4: XSSFSheetXMLHandlerPlus
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的package包/类
/**
* Accepts objects needed while parsing.
*
* @param styles Table of styles
* @param strings Table of shared strings
*/
public XSSFSheetXMLHandlerPlus(
StylesTable styles,
CommentsTable comments,
ReadOnlySharedStringsTable strings,
XSSFSheetXMLHandlerPlus.SheetContentsHandler sheetContentsHandler,
DataFormatter dataFormatter,
boolean formulasNotResults) {
this.stylesTable = styles;
this.commentsTable = comments;
this.sharedStringsTable = strings;
this.output = sheetContentsHandler;
this.formulasNotResults = formulasNotResults;
this.nextDataType = XSSFSheetXMLHandlerPlus.xssfDataType.NUMBER;
this.formatter = dataFormatter;
init();
}
示例5: process
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的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;
}
示例6: ContentHandlerImpl
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的package包/类
/**
* Default constructor of {@link ContentHandlerImpl}
*
* @param sheetNumber The sheet number
* @param dataCallback
* @param styles Table of styles
* @param sharedStringsTable Table of shared strings
* @param dataHandler The handler to be delivered when data cell is ready to
* @param ignoreEmptyRow If it should ignore missing/empty rows.
* be used
*/
public ContentHandlerImpl(long sheetNumber,
DataCallback dataCallback,
StylesTable styles,
ReadOnlySharedStringsTable sharedStringsTable,
DataHandler dataHandler,boolean ignoreEmptyRow) {
this.stylesTable = styles;
this.sharedStringsTable = sharedStringsTable;
this.bufferedReadedValue = new StringBuffer();
this.sheetNumber = sheetNumber;
this.dataCallback = dataCallback;
this.currentCol = -1;
this.rawValues = new NotNullList();
this.formattedValues = new NotNullList();
this.dataTypeService = new XlsxDataTypeServiceImpl();
if (dataHandler == null) {
this.dataHandler = new DefaultDataHandlerImpl(rawValues, formattedValues, sharedStringsTable);
} else {
this.dataHandler = dataHandler;
}
this.ignoreEmptyRow = ignoreEmptyRow;
}
示例7: processSheet
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的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());
}
}
示例8: parseXlsxFileAndWriteTmxBody
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的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();
}
示例9: readRows
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的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();
}
}
示例10: importSchema
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的package包/类
private SchemaSheetInformation importSchema(XSSFReader r,StylesTable styles ,ReadOnlySharedStringsTable sst ){
try {
XSSFReader.SheetIterator it = (XSSFReader.SheetIterator) r.getSheetsData();
while(it.hasNext()) {
try(InputStream sheet = it.next()){
String name = it.getSheetName();
if(Strings.equalsStd(PoiIO.SCHEMA_SHEET_NAME, name)){
InputSource sheetSource = new InputSource(sheet);
ReadSchemaSheet readSchemaSheet = new ReadSchemaSheet();
parseSheet(styles, sst, sheetSource, readSchemaSheet);
return readSchemaSheet.finish(report);
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
示例11: processSheet
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的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());
}
}
示例12: process
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的package包/类
/**
* 开始解析Excel文档
*
* @throws ReadExcelException
*/
public void process() throws ReadExcelException {
try {
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(this.xlsxPackage);
XSSFReader xssfReader = new XSSFReader(this.xlsxPackage);
StylesTable styles = xssfReader.getStylesTable();
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
while (iter.hasNext()) {
//初始化数据
this.initDataPerSheet();
InputStream stream = iter.next();
this.processSheet(styles, strings, this, stream);
stream.close();
}
//解析完后,判断用户是否设置了limit,若设置了执行以下操作
if (this.limit > 0) {
if (!this.datas.isEmpty()) {
if (this.callback != null) {
//若数据不为空且回调函数被设置,则调用回调函数
this.callback.callback(this.currentRowInSheet, this.currentSheetInExcel, this.realRowInSheet,
this.realRowInExcel, this.allSheetInExcel, this.titles, this.columns, this.datas);
}
this.datas.clear();
}
}
} catch (Exception e) {
throw new ReadExcelException(e.getMessage());
}
}
示例13: processSheet
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的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());
}
}
示例14: processSheet
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的package包/类
/**
* Parses and shows the content of one sheet using the specified styles and
* shared-strings tables.
*
* @param styles
* @param strings
* @param sheetInputStream
* @param sheetNumber
* @throws java.io.IOException
* @throws javax.xml.parsers.ParserConfigurationException
* @throws org.xml.sax.SAXException
*/
public void processSheet(
StylesTable styles,
ReadOnlySharedStringsTable strings,
InputStream sheetInputStream, int sheetNumber)
throws IOException, ParserConfigurationException, SAXException {
InputSource sheetSource = new InputSource(sheetInputStream);
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxFactory.newSAXParser();
XMLReader sheetParser = saxParser.getXMLReader();
ContentHandler handler = new ContentHandlerImpl(sheetNumber, dataCallback, styles, strings, null,ignoreEmptyRow);
sheetParser.setContentHandler(handler);
sheetParser.parse(sheetSource);
}
示例15: parse
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; //导入依赖的package包/类
public void parse(InputStream sheetInputStream, ReadOnlySharedStringsTable sharedStringsTable,
AbstractWriter tmxWriter) throws ParserConfigurationException, SAXException, IOException {
InputSource sheetSource = new InputSource(sheetInputStream);
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxFactory.newSAXParser();
XMLReader sheetParser = saxParser.getXMLReader();
ContentHandler handler = new XSSFHander(sharedStringsTable);
sheetParser.setContentHandler(handler);
sheetParser.parse(sheetSource);
if(langCodes.isEmpty()){
throw new SAXException("EMPTY-LANG-CODE");
}
writeEnd();
}