• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert string to numeric using APACHE POI  RSS feed

 
Harini Sangani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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.
 
Srikkanth Mohansundaram
Greenhorn
Posts: 16
AngularJS Chrome jQuery
  • Mark post as helpful
  • send pies
  • 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
AngularJS Chrome jQuery
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Marshal
Posts: 56520
172
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
AngularJS Chrome jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Harini,

Did you try to autoSize the column ?



Thanks
Srikkanth
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!