use of org.apache.poi.xssf.eventusermodel.XSSFReader in project translationstudio8 by heartsome.
the class Xlsx2TmxHelper method parseXlsxFileAndWriteTmxBody.
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();
}
use of org.apache.poi.xssf.eventusermodel.XSSFReader in project cubrid-manager by CUBRID.
the class XLSXImportFileHandler method getSheets.
/**
*
* Get the sheets
*
* @return List<InputStream>
* @throws IOException The exception
* @throws OpenXML4JException The exception
*/
public List<InputStream> getSheets() throws IOException, OpenXML4JException {
// FIXME move this logic to core module
synchronized (this) {
if (reader == null) {
try {
workbookSteam = new BufferedInputStream(new FileInputStream(fileName));
OPCPackage pkg = OPCPackage.open(workbookSteam);
reader = new XSSFReader(pkg);
} catch (OutOfMemoryError error) {
throw new RuntimeException(error);
}
}
sharedStringTable = reader.getSharedStringsTable();
Iterator<InputStream> sheetsIt = reader.getSheetsData();
List<InputStream> sheets = new ArrayList<InputStream>();
while (sheetsIt.hasNext()) {
sheets.add(sheetsIt.next());
}
return sheets;
}
}
use of org.apache.poi.xssf.eventusermodel.XSSFReader in project poi by apache.
the class LoadPasswordProtectedXlsxStreaming method printSheetCount.
public static void printSheetCount(final InputStream inputStream) throws Exception {
AesZipFileZipEntrySource source = AesZipFileZipEntrySource.createZipEntrySource(inputStream);
try {
OPCPackage pkg = OPCPackage.open(source);
try {
XSSFReader reader = new XSSFReader(pkg);
SheetIterator iter = (SheetIterator) reader.getSheetsData();
int count = 0;
while (iter.hasNext()) {
iter.next();
count++;
}
System.out.println("sheet count: " + count);
} finally {
IOUtils.closeQuietly(pkg);
}
} finally {
IOUtils.closeQuietly(source);
}
}
use of org.apache.poi.xssf.eventusermodel.XSSFReader in project poi by apache.
the class FromHowTo method processAllSheets.
public void processAllSheets(String filename) throws Exception {
OPCPackage pkg = OPCPackage.open(filename, PackageAccess.READ);
try {
XSSFReader r = new XSSFReader(pkg);
SharedStringsTable sst = r.getSharedStringsTable();
XMLReader parser = fetchSheetParser(sst);
Iterator<InputStream> sheets = r.getSheetsData();
while (sheets.hasNext()) {
System.out.println("Processing new sheet:\n");
InputStream sheet = sheets.next();
InputSource sheetSource = new InputSource(sheet);
parser.parse(sheetSource);
sheet.close();
System.out.println("");
}
} finally {
pkg.close();
}
}
use of org.apache.poi.xssf.eventusermodel.XSSFReader in project poi by apache.
the class FromHowTo method processFirstSheet.
public void processFirstSheet(String filename) throws Exception {
OPCPackage pkg = OPCPackage.open(filename, PackageAccess.READ);
try {
XSSFReader r = new XSSFReader(pkg);
SharedStringsTable sst = r.getSharedStringsTable();
XMLReader parser = fetchSheetParser(sst);
// process the first sheet
InputStream sheet2 = r.getSheetsData().next();
InputSource sheetSource = new InputSource(sheet2);
parser.parse(sheetSource);
sheet2.close();
} finally {
pkg.close();
}
}
Aggregations