use of org.apache.poi.openxml4j.opc.OPCPackage 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.openxml4j.opc.OPCPackage in project goci by EBISPOT.
the class SheetCreationService method createSheet.
public XSSFSheet createSheet(String fileName) throws InvalidFormatException, IOException, InvalidOperationException {
// Open file
OPCPackage pkg = OPCPackage.open(fileName);
XSSFWorkbook current = new XSSFWorkbook(pkg);
pkg.close();
return current.getSheetAt(0);
}
use of org.apache.poi.openxml4j.opc.OPCPackage 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.openxml4j.opc.OPCPackage in project poi by apache.
the class XDGFFileHandler method test.
// a test-case to test this locally without executing the full TestAllFiles
@Test
public void test() throws Exception {
OPCPackage pkg = OPCPackage.open("test-data/diagram/test.vsdx", PackageAccess.READ);
try {
XmlVisioDocument doc = new XmlVisioDocument(pkg);
new POIXMLDocumentHandler().handlePOIXMLDocument(doc);
} finally {
pkg.close();
}
}
use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.
the class XSSFBFileHandler method handleExtracting.
@Override
public void handleExtracting(File file) throws Exception {
OPCPackage pkg = OPCPackage.open(file, PackageAccess.READ);
try {
testOne(pkg);
} finally {
pkg.close();
}
pkg = OPCPackage.open(file, PackageAccess.READ);
try {
testNotHandledByWorkbookException(pkg);
} finally {
pkg.close();
}
}
Aggregations