• 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

Convert string to numeric using APACHE POI

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have been trying to convert the database value i.e in string format to integer, the value is getting converted but displaying as 1.69411E+11 in the excel sheet. It has to be displayed as 169411000258.

My Code:

cell1.setCellValue(Long.parseLong(rs1.getString("Proposal_No")));

Thanks in Advance.
 
Greenhorn
Posts: 16
jQuery AngularJS Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Harini,

You'd want to format the cell with the desired format ( like a number ). Please check this recipe here DataFormats

Thanks
Srikkanth
 
Srikkanth Mohansundaram
Greenhorn
Posts: 16
jQuery AngularJS Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way , I just noticed you posted the question "Ranch Office". Always post your question in an appropriate forum.

-- Srikkanth
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Do you have any options on that cell to handle the number as floating‑point? Look at the spreadsheet.

I shall try moving you to a more appropriate location.
 
Harini Sangani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Srikkanth ,


I have tried what you have suggested but it still showing the same output.


Code used:

cell1=row1.createCell(5);
cell1.setCellValue(rs2.getString("ReceiptNo"));
CellStyle styledata = workbook.createCellStyle();
styledata.setDataFormat(formatchange.getFormat("#"));
cell1.setCellStyle(styledata);

This code used is not even converting the data to numeric.

The code below is converting to numeric but in excel it is showing the value as 1.69411E+11 instead of 169411000258

cell1.setCellValue(Long.parseLong(rs1.getString("Proposal_No")));

Kindly suggest as it is an urgent requirement.

 
Harini Sangani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Campbell Ritchie,

I am getting the value from the database and it is in the string format. From string i am changing it to Long and showing it in the excel. It is getting converted to numeric but the point is it is showing 1.69411E+11 (with a + symbol) instead of 169411000258
 
Srikkanth Mohansundaram
Greenhorn
Posts: 16
jQuery AngularJS Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Harini,

Did you try to autoSize the column ?



Thanks
Srikkanth
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic