poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 21571] - [NEEDS-INFO]EXCEL application error appears when closing and not saving a POI generated xls spreadsheet
Date Tue, 29 Jul 2003 06:31:54 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21571>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21571

[NEEDS-INFO]EXCEL application error appears when closing and not saving a POI generated xls
spreadsheet





------- Additional Comments From fred.barnes@za.tiscali.com  2003-07-29 06:31 -------
Good morning Andy,

I think I may have found a problem. I wrote a small test application that 
generates a Excel workbook. During my testing/debugging I found that the 
minute I add a 3rd sheet to the workbook I experience the above mentioned 
problem/error. Working with less than 3 sheet work 100% :) Please advise?

Kind Regards
Fred

/*
 * POI.java
 *
 * 2003/07/28
 *
 * 1.0
 *
 * Copyright (c) 1999 - 2003 Tiscali (Pty) Ltd. All rights reserved.
 */
package com.wol.reporting;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


/**
 * @author Fred Barnes
 * @version 1.0
 */
public class POI
{
    private HSSFCellStyle style;
    private HSSFCellStyle style2;
    private HSSFCellStyle style3;

    public POI()
    {
        //Create a work book.
        HSSFWorkbook wb = new HSSFWorkbook();

        //Create a font.
        HSSFFont font = wb.createFont();
        font.setFontHeightInPoints((short) 16);
        font.setFontName("Arial");
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        //Create style.
        style = wb.createCellStyle();
        style.setFont(font);

        //Create 2nd font.
        HSSFFont font2 = wb.createFont();
        font2.setFontHeightInPoints((short) 14);
        font2.setFontName("Arial");
        font2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        style2 = wb.createCellStyle();
        style2.setFont(font2);

        //Create 3rd font.
        HSSFFont font3 = wb.createFont();
        font3.setFontHeightInPoints((short) 10);
        font3.setFontName("Arial");
        font3.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        style3 = wb.createCellStyle();
        style3.setFont(font3);

        createSheet(wb);
        createSheet(wb);
        createSheet(wb);

        FileOutputStream fileOut = null;

        try
        {
            fileOut = new FileOutputStream("c:/test.xls");
            wb.write(fileOut);
            fileOut.close();
        }
        catch (FileNotFoundException e)
        {
            if (fileOut != null)
            {
                try
                {
                    fileOut.close();
                }
                catch (IOException ioe)
                {
                }

                fileOut = null;
            }
        }
        catch (IOException e)
        {
            if (fileOut != null)
            {
                try
                {
                    fileOut.close();
                }
                catch (IOException ioe)
                {
                }

                fileOut = null;
            }
        }
    }

    private void createSheet(HSSFWorkbook wb)
    {
        //		Create a sheet.
        HSSFSheet sheet = wb.createSheet("Test sheet");

        //Set zoom to 80%.
        sheet.setZoom(4, 5);

        //Merge columns.
        sheet.addMergedRegion(new Region(0, (short) 0, 0, (short) 3));

        //Create row1.        
        HSSFRow row = sheet.createRow(0);
        HSSFCell row0Cell0 = row.createCell((short) 0);
        row0Cell0.setCellStyle(style);
        row0Cell0.setCellValue("Row 1");

        //Create row2.
        HSSFRow row1 = sheet.createRow(1);
        HSSFCell row1Cell0 = row1.createCell((short) 0);
        row1Cell0.setCellStyle(style2);
        row1Cell0.setCellValue("Row 2");

        //Create row3.
        HSSFRow row2 = sheet.createRow(2);
        HSSFCell row2Cell0 = row2.createCell((short) 0);
        row2Cell0.setCellStyle(style3);
        row2Cell0.setCellValue("Row 3");

        //Insert a long value.
        long aLong = 123;
        HSSFRow row3 = sheet.createRow(3);
        HSSFCell row3Cell0 = row3.createCell((short) 0);
        row3Cell0.setCellStyle(style3);
        row3Cell0.setCellValue(aLong);

        //Insert a double value.
        double aDouble = 456;
        HSSFRow row4 = sheet.createRow(4);
        HSSFCell row4Cell0 = row4.createCell((short) 0);
        row4Cell0.setCellStyle(style3);
        row4Cell0.setCellValue(aDouble);

        //Insert data.
        for (int i = 5; i < 1005; i++)
        {
            HSSFRow rowX = sheet.createRow(i);

            for (short j = 0; j < 22; j++)
            {
                HSSFCell rowY = rowX.createCell(j);
                rowY.setCellStyle(style3);

                if ((j % 2) == 0)
                {
                    String nullString = null;
                    rowY.setCellValue(nullString);
                }
                else
                {
                    rowY.setCellValue("test");
                }
            }
        }
    }

    public static void main(String[] args)
    {
        POI poi = new POI();
    }
}

Mime
View raw message