how to set number format to cells using jexcel api

CyprUS picture CyprUS · Mar 18, 2011 · Viewed 8.7k times · Source

I am writing a excel sheet with various floating values . It is absolutely necessary that i do not lose any decimal point when doing this. I am using this code:

              number = new Number(1, rowno2,biashidden[i]);
              sheet.addCell(number);

When i do this, the default format is only up to 3 decimal places. I can see the values written correctly in the excel sheet, but when do System.out.println , i see only values upto 3 decimal places. I do not know upto how many places the values will be, it may be 1.0 or it may 1.0000045667 ( thus i cannot specify a maximum limit using Numberformat too). What should i do? Thanks in advance

Answer

CyprUS picture CyprUS · Mar 22, 2011

This is the code for my problem .

        WritableCellFormat wcf1=new WritableCellFormat(new  jxl.write.NumberFormat("#.###############"));
         wcf1.setShrinkToFit(true);
        try
         {
                   for(int i=0;i<=numberOfNeurons[0];i++)
         {
                          for(int j=0;j<numberOfNeurons[1];j++)
            {
               number = new Number(0,rowno1,wtofnetwork[i][j],wcf1);

    sheet.addCell(number);
            rowno1++;

            }
             }

For some reason, we cannot specify the number of decimal places dynamically. so i gave enough decimal places so that no digit is lost. It is a crude way of doing it , but it achieves the purpose.