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.

Reply via email to