我实际上是在尝试将.xlsx文件转换为.csv文件。我在网上找到了很多关于如何从.xlsx转换为.csv。
的资源我试试这个:
private static void convertSelectedSheetInXLXSFileToCSV(File xlsxFile, int sheetIdx) throws Exception {
FileInputStream fileInStream = new FileInputStream(xlsxFile);
// Open the xlsx and get the requested sheet from the workbook
XSSFWorkbook workBook = new XSSFWorkbook(fileInStream);
XSSFSheet selSheet = workBook.getSheetAt(sheetIdx);
...
代码似乎没问题,但我有一个例外,我无法理解......
java.io.IOException: Failed to read zip entry source
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:103)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:324)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:295)
at fr.cls.ihs.injector.reader.ConvertXLSXToCSV.convertSelectedSheetInXLXSFileToCSV(ConvertXLSXToCSV.java:21)
at fr.cls.ihs.injector.reader.ConvertXLSXToCSV.convert(ConvertXLSXToCSV.java:64)
at fr.cls.ihs.injector.processing.ConverterProcessing.process(ConverterProcessing.java:46)
at fr.cls.ihs.injector.pool.IhsInjectorRunnable.process(IhsInjectorRunnable.java:64)
at fr.cls.generic.server.processing.AbstractServerProcessing.execute(AbstractServerProcessing.java:58)
at fr.cls.generic.server.runnable.GenericRunnable.run(GenericRunnable.java:55)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.zip.ZipException: too many length or distance symbols
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:194)
at org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream.read(ZipSecureFile.java:220)
at java.io.FilterInputStream.read(FilterInputStream.java:107)
at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource$FakeZipEntry.<init>(ZipInputStreamZipEntrySource.java:132)
at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.<init>(ZipInputStreamZipEntrySource.java:56)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:100)
为了解决这个问题,我尝试使用另一个带有String或Zip参数的XSSFworkbook构造函数,但这不是我想要的。
如果有人知道如何解决部分错误,那可能会很棒:D
提前谢谢你,