EasyExcel.write修改列宽
时间: 2024-06-19 12:02:10 浏览: 14
EasyExcel.write可以用于写入Excel文件,同时也可以设置Excel文件的列宽。具体实现方法如下:
1. 首先需要创建一个WriteSheet对象
```
WriteSheet writeSheet = EasyExcel.writerSheet().build();
```
2. 然后,使用WriteSheet对象的setDefaultColumnWidth方法来设置默认列宽。
```
writeSheet.setDefaultColumnWidth(20);
```
3. 如果需要设置某一列的列宽,则需要使用WriteSheet对象的setColumnWidth方法,并指定列的索引和列宽。
```
writeSheet.setColumnWidth(0, 30);
```
其中,第一个参数是列的索引,从0开始;第二个参数是列宽,单位为字符数。
4. 最后,调用EasyExcel.write方法,并传入写入数据的类、文件路径、sheet名称和WriteSheet对象即可实现Excel文件的写入和列宽的设置。
```
EasyExcel.write(fileName, DemoData.class).sheet(sheetName).registerWriteHandler(new FreezeAndFilterTable()).withTemplate(templatePath).relativeHeadRowIndex(relativeHeadRowIndex).needHead(needHead).needMapList(needMapList).doWrite(dataList, writeSheet);
```
相关推荐
![](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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)