Jar Files硒的webdriver - 爪哇 - 在嘗試使用Apache POI
我想寫一個值,現有的Excel,試圖運行我得到異常下面寫在Excel中的數據異常。有人可以指導請
Exception in thread "main" java.io.IOException: Failed to read zip entry source
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:106)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:342)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:285)
at samplescripts.WriteExcel.main(WriteExcel.java:19)
Caused by: java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(Unknown Source)
at java.util.zip.InflaterInputStream.read(Unknown Source)
at java.util.zip.ZipInputStream.read(Unknown Source)
at org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream.read(ZipSecureFile.java:213)
at java.io.FilterInputStream.read(Unknown Source)
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:99)
... 4 more
下面是用於
package samplescripts;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class WriteExcel {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
File src=new File("C:\\Selenium\\ExcelData\\TestData.xlsx");
FileInputStream fis=new FileInputStream(src);
XSSFWorkbook wb=new XSSFWorkbook(fis);
XSSFSheet sheet1=wb.getSheetAt(0);
sheet1.getRow(0).createCell(2).setCellValue("Pass");
sheet1.getRow(1).createCell(2).setCellValue("Fail");
sheet1.getRow(2).createCell(2).setCellValue("14.12");
FileOutputStream fout=new FileOutputStream(src);
wb.write(fout);
wb.close();
}
}
你google是個例外嗎?你發現了什麼? – JeffC
嘗試將TestData.xlsx重命名爲TestData.zip並檢查該文件的一致性(驗證或解壓縮它) – user1516873