easyexcel设置居中
时间: 2023-10-18 14:57:05 浏览: 167
您可以使用EasyExcel的HorizontalCellStyleStrategy来设置单元格内容居中对齐。在您的代码中,可以按照以下方式设置居中样式:
```java
// 导入需要的类
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
// 创建居中样式
CellStyle cellStyle = new CellStyle();
cellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
// 使用HorizontalCellStyleStrategy设置居中样式
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(cellStyle);
// 在写入Excel时注册该样式
EasyExcel.write(outputStream)
.head(header)
.registerWriteHandler(horizontalCellStyleStrategy)
.sheet()
.doWrite(dataList);
```
这样设置之后,生成的Excel中的单元格内容将居中显示。希望对您有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [EasyExcel设置表格样式](https://blog.csdn.net/weixin_46114883/article/details/129031331)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [easyExcel的一些操作](https://blog.csdn.net/qq_45936359/article/details/126976343)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [【使用easyexcel导出excel--字体居中】](https://blog.csdn.net/weixin_45559862/article/details/108126332)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文