我不知道爲什麼使用POI編寫的文件無法由Excel 2013打開,但該文件仍可由POI讀取。 (單元格值可以改變)從Apache POI無法打開文件Excel由Excel女士打開(損壞)
this是從文件
在這裏的錯誤是代碼
FileInputStream fis = null;
try {
fis = new FileInputStream(fileUri); //not error at fileUri
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String urii = fileUri.replace(".xls", "0.xls"); //not error
File fisx = new File(urii);
Workbook workbook = null;
workbook = new HSSFWorkbook(fis);
Sheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
String p = cell.getStringCellValue();
TextView a = (TextView) findViewById(R.id.txtUri);
cell.setCellValue(new String("popo"));
String x = cell.getStringCellValue();
TextView b = (TextView) findViewById(R.id.txtFile);
a.setText(p);
b.setText(x);
OutputStream fos = null;
fos = new FileOutputStream(fisx);
workbook.write(fos); //main problem
fos.flush();
fos.close();
感謝您的幫助!
HSSFWorkbook工作過於概括。 –
是的..但要能夠在MS Excel 2013上打開,您需要使用... XSSFWorkbook –
我的輸入文件是xls類型,輸出也是xls類型。另外,我試圖將輸出文件上傳到谷歌文檔,並沒有上傳(我認爲是因爲輸出文件已損壞) – ketelagoreng