Hi,

is it possible to specify additional number formats with more than two
positions after decimal point?
(like "#.##0,000" or "0,000")

I read the "Excel Binary header-thread" earlier this month and tried to add
the desired formats this way,
but this didn't work correctly - Excel signals corrupted Formats:

package org.apache.poi.hssf.model;
...
public class Workbook
{
...
  static final String[] formats = new String[]
  {
    "#.##0,0",
    "0,0",
    "#.##0,000",
    "0,000",
    "0,0%",
    "0,000%",
    "JJJJ-MM-TT",
    "TT.MM.JJJJ"
  };
...
  protected Record createFormat(int id)
  {   // we'll need multiple editions for
    FormatRecord retval = new FormatRecord();   // the different formats
    switch(id)
    {
      case 0 :
        retval.setIndexCode(( short ) 5);
        break;
      case 1 :
        retval.setIndexCode(( short ) 6);
        break;
      case 2 :
        retval.setIndexCode(( short ) 7);
        break;
      case 3 :
        retval.setIndexCode(( short ) 8);
        break;
      case 4 :
        retval.setIndexCode(( short ) 0x2a);
        break;
      case 5 :
        retval.setIndexCode(( short ) 0x29);
        break;
      case 6 :
        retval.setIndexCode(( short ) 0x2c);
        break;
      case 7 :
        retval.setIndexCode(( short ) 0x2b);
        break;
    }
    retval.setFormatStringLength((byte)formats[id].length());
    retval.setFormatString(formats[id]);
    return retval;
  }

I would appreciate having the possibility to specify DataFormats this way:

HSSFWorkbook workbook = new HSSFWorkbook();
HSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setDataFormat(HSSFDataFormat.getUserDefinedFormat("#.##0,00000"));

so every possible userdefined format colud be applied to a CellStyle.

Thanks,
Bernd Bartke.

Reply via email to