https://bz.apache.org/bugzilla/show_bug.cgi?id=58480

--- Comment #3 from Kasper Sørensen <[email protected]> ---
That's not the problem IMO. I am closing the stream.

Please see this test case that I just built to reproduce the issue on current
trunk:

------------

package org.apache.poi.hssf.usermodel;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.junit.Test;

public class HSSFWorkbookTest {

    @Test
    public void testWriteScenario() throws Exception {
        final File file = new File(
                "build/HSSFWorkbookTest-testWriteScenario.xls");

        // create new workbook
        {
            final Workbook workbook = new HSSFWorkbook();
            final Sheet sheet = workbook.createSheet("foo");
            final Row row = sheet.createRow(1);
            row.createCell(1).setCellValue("bar");

            writeAndCloseWorkbook(workbook, file);
        }

        // edit the workbook
        {
            final Workbook workbook = WorkbookFactory.create(file);
            final Sheet sheet = workbook.getSheet("foo");
            sheet.getRow(1).createCell(2).setCellValue("baz");

            writeAndCloseWorkbook(workbook, file);
        }
    }

    private void writeAndCloseWorkbook(Workbook workbook, File file)
            throws IOException {
        final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        workbook.write(bytesOut);
        workbook.close();

        final byte[] byteArray = bytesOut.toByteArray();
        bytesOut.close();

        final FileOutputStream fileOut = new FileOutputStream(file);
        fileOut.write(byteArray);
        fileOut.close();

    }
}

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to