excel 动态高度

while_go 2022-04-13 11:58:16

Java poi 导出excel时,设置自动换行。之后获取行的高度,始终是一行的高度。 求解如何获取excel里显示的行高?

...全文
8268 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
while_go 2022-04-13
  • 打赏
  • 举报
回复

根据行内容重新计算行高

public static float calcAndSetRowHeight(HSSFRow contentRow, String cellContent, int cellWidth) {

    double totalRows = 0;
    String[] arr  = cellContent.split("\n");
    for (int i = 0; i < arr.length; i++) {
        String s = arr[i];

        int totalCount = 0;
        for(int j=0;j<s.length();j++){
            String b=Character.toString(s.charAt(j));
            if (b.getBytes().length == 1) {
                totalCount++;
            } else {
                totalCount = totalCount + 2;
            }
        }

        double l = totalCount * 256;

        if (l < cellWidth) {
            l = cellWidth;
        }

        // 字符串需要的行数 不做四舍五入之类的操作。
        double stringNeedsRows = Math.ceil(l / cellWidth);

        totalRows += stringNeedsRows;
    }

    return (float) ((totalRows + 2) * contentRow.getHeightInPoints());
}

10,612

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧