Tajinder
Tajinder

Reputation: 2348

Create Excel files in java(invalid number)

I have a string like "2,345".I want to put it into a excel cell.I successfully did but in my excel file i got "2,345" as a string.So please suggest me how can i get "2,345" as a number value but with the same format as i used above(comma seperated).

Thanks in advance.

Upvotes: 0

Views: 98

Answers (1)

Andy G
Andy G

Reputation: 19367

Remove the comma before inserting it into Excel, cast it to a number before inserting, then format the column to show the comma.

String replace

In Excel the code to format a Range with commas is:

SomeRange.Style = "Comma"    'or, recorded version
SomeRange.NumberFormat = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"

'a simpler version..
SomeRange.NumberFormat = "#,##0"

Upvotes: 1

Related Questions