Hi... wrong list, this is a poi-dev kind of issue.

Custom formats are on the plate for HSSF 2.0.  I'm going to need this 
soon for some stuff I'm working on.  If you're game, take a crack at it. 
 I'll apply and help debug the patches.  

So do a cvs diff -u and send in the patch, just annotate that it doesn't 
work yet.  Please accompany it with a unit test that expects it to work 
how you're intending.  Someone on the poi-dev list will undoubtably 
figure it out and apply it.  Patches that have unit tests associated 
with them get extra special attention.  (and if you use test first 
design then Glen S. will really think nice things about you)..

Thanks,

Andy

Bernd Bartke wrote:

>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