• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Formating problem

 
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I;m facing a weird problem in my system , actually it's a reporting tool using servlets and jsp getting the data from the DB then display it in an excel sheet , the problem in that some numbers was displayed in the excel sheet as this : 8.052409268919E12 although it was found like this in the DB : 8052409268919.0 , so why is the format was changed in the excel sheet , i;m using apache POI for make these excel files my IDE is myeclipse ...

Any recommendations ?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excel has limited numerical accuracy regarding the display of numbers. If the number gets too big it automatically switches to the scientific format (like n.nnnnEnn).
If you *need* the non-scientific notation, you may have to set the cell type to text instead of number.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Excel has limited numerical accuracy regarding the display of numbers. If the number gets too big it automatically switches to the scientific format (like n.nnnnEnn).
If you *need* the non-scientific notation, you may have to set the cell type to text instead of number.


Hi Ulf ,
actually i set the cell type by but still the problem exists , Do you think it may be related to the computer regional settings ?
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried this sample code

HSSFWorkbook workBook = new HSSFWorkbook();
HSSFSheet sheet = workBook.createSheet();
HSSFRow row1 = sheet.createRow((short) 0);
HSSFCell c11 = row1.createCell((short) 0);
c11.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
c11.setCellValue("80524092689197777777.0");
try{
FileOutputStream stream = new
FileOutputStream("c:/temp/Book1.xls");
workBook.write(stream);
}catch(Exception e) {
e.printStackTrace();
}
and generated excel. Output of the excel is coming fine and I am using 3.0-rc4-20070503 version of POI API. Might be shifting version of POI will help to resolve your problem.
 
Sanjeev K Jain
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry my mistake ....I missed c11.setCellValue("80524092689197777777.0");. When something comes in quotes it will be displayed as String.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually i;m using Apache POI 3.1 20080629 ..
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,
When i was debugging my code to see from where this problem came , i fill the cell value form vector of Strings , but i found that the value was putted in the vector in this format : 6.4552410135625E13 although i;m not doing any formatting process before filling the vector all i do read from DB put in a vector ..

Any recommendations ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so this has nothing to do with POI or Excel, then? It's a question of where between the DB and your Java code it gets reformatted; is that correct? If so, some strategically placed println statements, or running the code through a debugger, should pinpoint the problem pretty quickly.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:OK, so this has nothing to do with POI or Excel, then? It's a question of where between the DB and your Java code it gets reformatted; is that correct? If so, some strategically placed println statements, or running the code through a debugger, should pinpoint the problem pretty quickly.


Ok, i;ll debug my code again and see what's wrong ...
 
reply
    Bookmark Topic Watch Topic
  • New Topic