Basic Excel currency format with Apache POI

后端 未结 4 1419
萌比男神i
萌比男神i 2020-12-01 06:16

I\'m able to get cells to format as Dates, but I\'ve been unable to get cells to format as currency... Anyone have an example of how to create a style to get this to work?

4条回答
  •  被撕碎了的回忆
    2020-12-01 06:52

    For at least Excel 2010: Go into Excel. Format a cell they way you want it.

    enter image description here

    Then go back into the format dialogue. Select custom.

    enter image description here

    Copy paste the text it has on the top row under Type: into

    createHelper.createDataFormat().getFormat("");
    

    Example:

    createHelper.createDataFormat().getFormat("_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)"); //is the "Accounting" format.
    

    Make sure you set your populate your cells by using a double. Using the index may cause problems with different versions of Excel. Note that the new format you create above ends up in the custom dialogue from step two.

提交回复
热议问题