Implémentation du problème
OPCPackage p = null;
try {
p = OPCPackage.open(file, PackageAccess.READ);
log.info("Read File:[" + file + "]");
XSSFStringsTable strings = new XSSFStringsTable(p);
XSSFReader xssfReader = new XSSFReader(p);
StylesTable styles = xssfReader.getStylesTable();
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
List<CommonRecord> resultList = new ArrayList<CommonRecord>();
List<String> targetSheetList = ConfigUtil.getTargetSheet(key);
while (iter.hasNext()) {
InputStream stream = iter.next();
String sheetName = iter.getSheetName();
if (targetSheetList.isEmpty()
|| !targetSheetList.isEmpty() && targetSheetList.contains(sheetName.trim())) {
log.info("Read Sheet:[" + sheetName + "]");
resultList.addAll(processSheet(styles, strings, stream, key, file));
}
stream.close();
}
return resultList;
StylesTable styles = xssfReader.getStylesTable (); L'erreur suivante se produit.
java.lang.ClassCastException: org.apache.poi.xssf.usermodel.XSSFWorkbook cannot be cast to org.apache.poi.xssf.streaming.SXSSFWorkbook
Évitez les erreurs en appelant ZipSecureFile.setMinInflateRatio ()
Mise en œuvre après rénovation
OPCPackage p = null;
try {
p = OPCPackage.open(file, PackageAccess.READ);
log.info("Read File:[" + file + "]");
XSSFStringsTable strings = new XSSFStringsTable(p);
XSSFReader xssfReader = new XSSFReader(p);
StylesTable styles = xssfReader.getStylesTable();
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
List<CommonRecord> resultList = new ArrayList<CommonRecord>();
List<String> targetSheetList = ConfigUtil.getTargetSheet(key);
while (iter.hasNext()) {
InputStream stream = iter.next();
String sheetName = iter.getSheetName();
if (targetSheetList.isEmpty()
|| !targetSheetList.isEmpty() && targetSheetList.contains(sheetName.trim())) {
log.info("Read Sheet:[" + sheetName + "]");
resultList.addAll(processSheet(styles, strings, stream, key, file));
}
stream.close();
}
return resultList;
Recommended Posts