Java POI 產生Excel時顯示貨幣格式,如: 23,332.00

來源:互聯網
上載者:User

<br />HSSFWorkbook workbook = new HSSFWorkbook();<br />HSSFSheet sheet = workbook.createSheet("Sheet1");<br />HSSFRow row = sheet.createRow(0);<br />HSSFCell cell = row.createCell(0);<br />HSSFCellStyle currencyStyle = workbook.createCellStyle();<br />currencyStyle.setDataFormat((short)4);<br />cell.setCellStyle(currencyStyle);<br />

setDataFormat 後面跟的數字對應的格式如下: 

0, "General"<br />1, "0"<br />2, "0.00"<br />3, "#,##0"<br />4, "#,##0.00"<br />5, "$#,##0_);($#,##0)"<br />6, "$#,##0_);[Red]($#,##0)"<br />7, "$#,##0.00);($#,##0.00)"<br />8, "$#,##0.00_);[Red]($#,##0.00)"<br />9, "0%"<br />0xa, "0.00%"<br />0xb, "0.00E+00"<br />0xc, "# ?/?"<br />0xd, "# ??/??"<br />0xe, "m/d/yy"<br />0xf, "d-mmm-yy"<br />0x10, "d-mmm"<br />0x11, "mmm-yy"<br />0x12, "h:mm AM/PM"<br />0x13, "h:mm:ss AM/PM"<br />0x14, "h:mm"<br />0x15, "h:mm:ss"<br />0x16, "m/d/yy h:mm"</p><p>// 0x17 - 0x24 reserved for international and undocumented 0x25, "#,##0_);(#,##0)"<br />0x26, "#,##0_);[Red](#,##0)"<br />0x27, "#,##0.00_);(#,##0.00)"<br />0x28, "#,##0.00_);[Red](#,##0.00)"<br />0x29, "_(*#,##0_);_(*(#,##0);_(* /"-/"_);_(@_)"<br />0x2a, "_($*#,##0_);_($*(#,##0);_($* /"-/"_);_(@_)"<br />0x2b, "_(*#,##0.00_);_(*(#,##0.00);_(*/"-/"??_);_(@_)"<br />0x2c, "_($*#,##0.00_);_($*(#,##0.00);_($*/"-/"??_);_(@_)"<br />0x2d, "mm:ss"<br />0x2e, "[h]:mm:ss"<br />0x2f, "mm:ss.0"<br />0x30, "##0.0E+0"<br />0x31, "@" - This is text format.<br />0x31 "text" - Alias for "@"<br /> 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.