當我修改服務器中現有的excel文件並複製到本地機器並打開它時,我得到excel could not open because some content is unreadable, do you want to open and repair this workbook?
下面是我的代碼。有人可以建議我如何避免這種情況?使用apache poi修改現有的excel
File f = new File(directory+"users.xlsx");
FileInputStream fileInputStream = new FileInputStream(f);
workbook = new XSSFWorkbook(fileInputStream);
sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(4);
for(int i = 0; i<5; i++)
{
Cell cell = row1.getCell(i);
cell.setCellValue(formattedDate);
cell.setCellStyle(normalStyle);
}
FileOutputStream out = new FileOutputStream(f, false);
workbook.write(out);
out.close();
一直試圖解決8小時,沒有運氣。如果有人能夠闡明這一點,會很感激。
嘗試使用WoorkbookFactory.create(的FileInputStream)閱讀和使用新FileOutputStream中另一個文件( f,錯誤);而不是「f」使用另一個文件。我應該工作。 – Koitoer
@Koitoer您能否詳細說明一下? – rick