POI自动调整列宽支持中文
/**
* @Description:表格自适应宽度(中文支持)
* @Author:
* @param sheet sheet
* @param columnLength 列数
*/
private static void setSizeColumn(HSSFSheet sheet, int columnLength) {
for (int columnNum = 0; columnNum <= columnLength; columnNum++) {
int columnWidth = sheet.getColumnWidth(columnNum) / 256;
for (int rowNum = 0; rowNum < sheet.getLastRowNum(); rowNum++) {
HSSFRow currentRow; // 当前行未被使用过
if (sheet.getRow(rowNum) == null) {
currentRow = sheet.createRow(rowNum);
} else {
currentRow = sheet.getRow(rowNum);
}
if (currentRow.getCell(columnNum) != null) {
HSSFCell currentCell = currentRow.getCell(columnNum);
if (currentCell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
int length = currentCell.getStringCellValue().getBytes().length;
if (columnWidth < length) {
columnWidth = length;
}
}
}
}
sheet.setColumnWidth(columnNum, columnWidth * 256);
}
}
POI自动调整列宽支持中文的更多相关文章
- 使用poi调整字体格式、添加单元格注释、自动调整列宽
1 创建新的工作铺 import java.io.FileOutputStream; import org.apache.poi.hssf.usermodel.HSSFCell; import org ...
- C#中操作刚导出的Excel,设置其为自动调整列宽
[问题] 用C#导出数据为excel,但是导出的数据中,不是自动调整列宽的: 希望变成这样的: [解决过程] 1.参考: 在C#里对excel文件的列宽进行操作 去试试: //auto adjust ...
- Excel 如何自动调整列宽?
excel如何自动调整列宽 1.打开Excel表格,选中要调整的表格. 2.点击"格式",选择"自动调整列宽",右键点击"设置单元格格式" ...
- java Excel 自动调整列宽
在开发中经常需要用到对Excel文件的操作,现在根据网上的资料整理如下: import java.io.FileOutputStream; import org.apache.poi.hssf.use ...
- jqgrid在页面出来竖型滚动条自动调整列宽
在项目中使用jqgrid的时候,需要设置在页面竖型滚动条出来的时候,列宽进行调整 1. 判断jqgrid的宽度是否和页面的宽度不一致(判断滚动条是否出来) 2. 调整jqgrid的列宽,因为jqgri ...
- excel 根据单元格内容自动调整列宽
excel 根据单元格内容自动调整列宽 CreateTime--2018年5月28日08:49:40 Author:Marydon 1.情景展示 单元格宽度超过了列宽 2.解决方案 第一步:同时选 ...
- POI设置列宽 自动调整列宽
for (int i = 0; i <= totalColumn; i++) { sheet.autoSizeColumn((short)i,true); //调整列宽 } 其中totalCol ...
- WPF学习笔记(3):ListView根据内容自动调整列宽
DataGrid中,只要不设置DataGrid的宽度和列宽度,或者将宽度设置为Auto,那么表格就会根据内容自动调整宽度,以显示所有内容.但如果是ListView,按以上方法设置,却达不到列宽自动调整 ...
- MS WORD 表格自动调整列宽,自动变漂亮,根据内容自动调整 .
在MS WORD中,当有大量的表格出现时,调整每个表格的的高和宽和大小将是一件非常累的事情,拖来拖去,非常耗时间,而且当WORD文档达到300页以上时,调整反应非常的慢,每次拖拉线后,需要等待一段时间 ...
随机推荐
- IIS运行WCF服务报错
试图加载格式不正确的程序 image 解决方法 image HTTP 错误 500.19 image 解决方法在控制面板————>程序————>启用或关闭windows功能—— ...
- 【码云周刊第 22 期】GO :互联网时代的 C 语言!
技术干货 标签:独家译文 1.Go 很好,为什么我们不使用它? 在这篇文章中,我将分享一下为什么我认为它很棒,使用它的一些缺点,以及为什么它还不是我们 Zapier 堆栈中的一部分. 2.从 Scal ...
- XF 开关控件
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http:/ ...
- 《Docker 实战》第三章 Docker Hub 寻宝游戏
# 秘密仓库和密码 docker run --rm -it --name password dockerinaction/ch3_ex2_huntanswer
- MVC 行为过滤器
using FilterExam.Fiter;using System;using System.Collections.Generic;using System.Linq;using System. ...
- 浅谈.NET(C#)与Windows用户账户信息的获取
原文:浅谈.NET(C#)与Windows用户账户信息的获取 目录 1. 用户账户名称 - 使用Environment类 2. 用户账户信息 - 使用WindowsIdentity和IdentityR ...
- java模拟post请求发送json数据
import com.alibaba.fastjson.JSONObject; import org.apache.http.client.methods.CloseableHttpResponse; ...
- Dlib 19.4(算法,压缩,图像处理,机器学习,Meta编程,网络,HTTP服务器)
Algorithms API Wrappers Bayesian Nets Compression Containers Graph Tools Image Processing Linear Alg ...
- MQTT-CN MQTT协议中文版
欢迎任何形式的转载,但请务必注明出处:http://www.cnblogs.com/liangjingyang 项目地址:https://github.com/liangjingyang/MQTT-C ...
- scrapy爬虫框架研究!
最近由于项目需要,开始研究scrapy爬虫,走过不少弯路,准备写个记录,记下踩过的各种坑.