Bug 12899

Summary: (RFE: Unicode Custom Number formats. ) Corrupted, but readable excel file is generated. Excel displays "File error. Some number formats may have been lost." on open.
Product: POI Reporter: Victor Arabadjiyski <victor>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: alaskausaroutingnumber
Priority: P3    
Version: 2.0-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Template file
Generated Excel file (corrupted)

Description Victor Arabadjiyski 2002-09-22 06:50:10 UTC
Hi,
I tried to generate excel file from template. When opening generated file with 
Excel (2002) it displayed the message: "File error. Some number formats may 
have been lost.".

Here are the files:
 - template file (http://www.geocities.com/et_victor/template.xls)
 - generated file (http://www.geocities.com/et_victor/result.xls)
 
The source of a generator program follows:
import java.io.*;
import java.util.*;
import java.sql.*;

import beans.common.*;
import beans.customers.*;

import util.transfer.*;

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.*;

public class ExcelGenerator
{
 private static void generate(File objTemplate, File objTarget) throws Exception
 {
  //open
  FileInputStream fis = new FileInputStream(objTemplate);
  POIFSFileSystem fs = new POIFSFileSystem(fis);
  HSSFWorkbook wb = new HSSFWorkbook(fs);
  fis.close();

  FileOutputStream fileOut = new FileOutputStream(objTarget);
  wb.write(fileOut);
  fileOut.close();
 }

 public static void main(String[] args)
 {
  try
  {
   File objTemplate = new File("c:/temp/template.xls");
   File objTarget = new File("c:/temp/result.xls");
   generate(objTemplate, objTarget);
  }catch (Exception ex)
  {
   ex.printStackTrace();
  }
 }
}
Comment 1 Victor Arabadjiyski 2002-09-22 10:59:37 UTC
Created attachment 3165 [details]
Template file
Comment 2 Victor Arabadjiyski 2002-09-22 11:02:40 UTC
Created attachment 3166 [details]
Generated Excel file (corrupted)
Comment 3 Andy Oliver 2002-09-22 16:58:32 UTC
There are what I presume is an extended character in the custom number formats
saved in the file.  I bet HSSF is trying to render them as 8-bit ("compressed
unicode") strings.  That of course is not going to work.

Since this area has been recently enhanced please try this with the 1.8
development release and report back.
Comment 4 Victor Arabadjiyski 2002-09-22 20:04:36 UTC
Success!
Development release 1.8 fixes this.
Generated Excel file is read without any problems or error messages.
Good work, guys!
Comment 5 Andy Oliver 2002-09-23 00:25:39 UTC
Excellent.  Because this is a 2.0 feature, I'm marking it fixed in the 2.0-dev
series.  This feature won't be backported to 1.5.x.