Bug 9612 - MS Excel crashes while opening XLS file generated from template.
Summary: MS Excel crashes while opening XLS file generated from template.
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 1.5
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-06-05 00:34 UTC by Inder Mohan
Modified: 2005-03-20 17:06 UTC (History)
0 users



Attachments
Template excel file (14.00 KB, application/vnd.ms-excel)
2002-06-05 00:40 UTC, Inder Mohan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Inder Mohan 2002-06-05 00:34:05 UTC
Hi,

When I try to create excel file from template with filled values and try to 
open this file from MS Excel, excel really crashes. I used following code:

import java.util.*;
import java.text.*;
import java.lang.Math.*;
import java.io.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.*;

public class inder7 {
	public static void main(String[] args) {
		final String TEMPLATE = "ordertest2.xls";
		final String WORKING_DIRECTORY = "c:\\sample\\";
		final String OUTFILE = WORKING_DIRECTORY + "sampleout.xls";

		try {
			FileInputStream fis = new FileInputStream
(WORKING_DIRECTORY + TEMPLATE);

			POIFSFileSystem pfs = new POIFSFileSystem(fis);

			HSSFWorkbook book = new HSSFWorkbook(pfs);
			HSSFSheet sheet1 = book.getSheet("Sheet1");

			HSSFRow row = sheet1.getRow(1);
			HSSFCell cell = row.getCell((short)1);
			cell.setCellValue("Inder");

			byte[] bbuf = book.getBytes();

			File f = new File(OUTFILE);
			FileOutputStream fos = new FileOutputStream(f);
			fos.write(bbuf);
			fos.close();
		}
		catch (java.io.IOException e) {
			e.printStackTrace(System.out);
		}
		catch (Exception e) {
			e.printStackTrace(System.out);
		}
	}
}

Help!!
Inder
Comment 1 Inder Mohan 2002-06-05 00:40:57 UTC
Created attachment 2004 [details]
Template excel file
Comment 2 Glen Stampoultzis 2002-06-10 02:54:18 UTC
Works fine when I use this method to write the workbook:

            File f = new File( OUTFILE );
            FileOutputStream fos = new FileOutputStream( f );
            book.write(fos);
            fos.close();

One thing to note though.  The cell you're writting the text into is merged and
so it will not display the text Inder.