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(); } } }
Created attachment 3165 [details] Template file
Created attachment 3166 [details] Generated Excel file (corrupted)
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.
Success! Development release 1.8 fixes this. Generated Excel file is read without any problems or error messages. Good work, guys!
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.