When I try to open the file using excel, it refused to open the second file and show the message. The first opens correctly.
I also noticed that the two file sizes are different. Rgds, On 16 Aug, 2013, at 5:17 PM, Dominik Stadler <[email protected]> wrote: > Hi, > > can you explain what you mean with "corrupt" in your case? Does Excel refuse > to read the file? Does POI itself refuse the read the file in again? Which > errors are you seeing? > > We currently know about two issues that can happen if you continue to use a > XSSF workbook after it was written out, one is solved in latest trunk, the > other is still under investigation. > > A workaround might be to read the file back in after you write it out the > first time, this way it should be ok and fine to write it out a second time. > > Thanks... Dominik. > > > On Fri, Aug 16, 2013 at 5:14 AM, Joe Black <[email protected]> wrote: >> >> >> I am trying to create Excel (.xlsx) files with the same content >> with two different filenames. >> >> I create the Workbook (wb) and create the first file. There is no >> problem. >> However, when I tried to write another file with the same (wb), >> the file is created. But it is considered corrupted. That is, when I >> tried to open the Excel file, the message said, it is corrupted. >> >> Here is the code snippet that I tested. >> { >> Workbook wb = new XSSFWorkbook(); >> Sheet sheet = wb.createSheet("abc"); >> Row row = sheet.createRow(0); >> >> Cell cell = row.createCell(1); >> cell.setCellValue("abcdljasklfj"); >> >> >> try >> { >> FileOutputStream fos = new FileOutputStream("./data/BBB.xlsx"); >> wb.write(fos); >> fos.close(); >> >> FileOutputStream floss = new FileOutputStream("./data/CCC.xlsx"); >> wb.write(floss); >> floss.close(); >> >> >> } >> catch (IOException ioex) >> { >> ioex.printStackTrace(); >> } >> } >> >> >> In another instance, where my actual program runs, which has more >> complicated processing involved, I have the similar problem. If I >> created only one file, it is created successfully. But when I use the >> same workbook to create another file, there is an error. But in this >> case is >> Since this program is huge, I do not want to complicate the >> matters. >> >> If the first instance of problem can be explained, I hope I can >> resolve it. >> As a comparison, if I use HSSFWorkbook >> instead of XSSFWorkbook, the similar program can create both files >> without problems. >> But it is (.xls) and not (.xlsx) file. >> >> My main objective is to create the Excel file in two different >> filenames and (possibly) different paths. >
