Jump to content

Excel IS_AUTO_DETECT_CELL_TYPE Suggestion


Recommended Posts

By: Steve Jenkings - stevejenks

Excel IS_AUTO_DETECT_CELL_TYPE Suggestion

2005-11-02 10:01

I wonder what the Jasper authors think about changing the code in the JRXlsExporter class 'exportText' method as follows..

 

Current code.

 

if (isAutoDetectCellType)

{

try

{

cell.setCellValue(Double.parseDouble(styledText.getText()));

}

catch(NumberFormatException e)

{

cell.setCellValue(JRStringUtil.replaceDosEOL(styledText.getText()));

}

}

 

 

Proposed code.

 

if (isAutoDetectCellType)

{

try

{

cell.setCellValue(Double.parseDouble(styledText.getText().replaceAll(",", "")));

}

catch(NumberFormatException e)

{

cell.setCellValue(JRStringUtil.replaceDosEOL(styledText.getText()));

}

}

 

i.e. by stripping out any commas in the text string before attempting to convert the String to a Double we can successfully convert Strings such as "123,456.00" into numbers.

 

Best,

 

Steve.

 

 

By: Doug Berkland - berkland

RE: Excel IS_AUTO_DETECT_CELL_TYPE Suggestion

2005-11-03 02:16

It would need to be more complex than that so as not to break the locales that use comma as the decimal point and period as the thousands seperator.

Link to comment
Share on other sites

  • 6 months later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...