abap 上传excel数字去除千分符_使用Apache POI在Excel中使用数千个分隔符格式化数字...

本文介绍如何在Excel中使用带有千位分隔符的数字格式。通过简单的格式代码#,###或#,##0,即可实现每三位数字插入逗号作为千位分隔符。文章还提供了如何手动设置并查看自定义格式的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I want to format some number cells, with a comma as thousands separator. For example:

12 -> 12

1200 -> 1,200

12000 -> 12,000

12000000 -> 12,000,000

120000000 -> 120,000,000

I have the following code. What should I use as formatStr? Is there an easy way? Or do I have to detect the number of zeros in order to produce something like this #,###,###?

String formatStr = "";

HSSFCellStyle style = workbook.createCellStyle();

HSSFDataFormat format = workbook.createDataFormat();

style.setDataFormat(format.getFormat(formatStr));

cell.setCellStyle(style);

cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);

Keep in mind that I'm dealing with numbers. The cell type will be numeric, not string.

Update

解决方案

Just #,### or #,##0 should be sufficient. Excel interprets this as having thousands separators every three digits (not just before the last three, which I infer is what you were expecting).

In the spirit of teaching a man to fish, this is how you can find out for yourself:

Format as Number, 0 decimal places, with 1000 separator:

Click OK, then re-open the number format dialog and go to Custom. Have a look at the formatting code ("Type"). It says #,##0, which for me gives the exact same result as #,###.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值