poi导出excel数据加千分位
时间: 2023-11-24 17:06:21 浏览: 51
可以使用Apache POI中的DataFormat类来实现对Excel单元格数据的格式化,包括加千分位。以下是一个示例代码:
```java
// 创建Workbook和Sheet对象
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("Sheet1");
// 创建DataFormat对象
DataFormat format = workbook.createDataFormat();
// 创建CellStyle对象,并设置格式
CellStyle style = workbook.createCellStyle();
style.setDataFormat(format.getFormat("#,##0"));
// 创建数据行并设置单元格格式
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue(12345678.9);
cell.setCellStyle(style);
// 输出Excel文件
FileOutputStream out = new FileOutputStream("example.xls");
workbook.write(out);
out.close();
```
在上述示例中,`format.getFormat("#,##0")`方法返回一个格式字符串,包含了千分位分隔符的格式。然后通过`CellStyle`对象的`setDataFormat`方法将该格式应用到单元格上。最后将数据写入Excel文件中。
相关推荐
![text/x-java](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)