首页 > 其他分享 >[转]POI获取单元格的宽和高

[转]POI获取单元格的宽和高

时间:2024-01-24 14:45:15浏览次数:23  
标签:width 单元格 像素 获取 POI height row

 

sheet.getColumnWidth(cell.getColumnIndex())
//获取的宽度默认一个字符占256,即字符个数*256,默认字符宽度是8像素px,所以转成像素为(/256*8)即/32

原文地址:POI获取单元格的宽和高 - 贾树丙 - 博客园

获取单元格的宽,即获取所在列的宽。先获取单元格所在的sheet:cell.getSheet()


sheet.getColumnWidth( cell.getColumnIndex() )  单位不是像素,是1/256个字符宽度
sheet.getColumnWidthInPixels( cell.getColumnIndex() )  单位是像素


获取单元格的高,即获取所在行的高。先获取单元格所在的row:cell.getRow()


row.getHeight()
row.getHeightInPoints()
这两个属性的区别在于HeightInPoints的单位是点,而Height的单位是1/20个点,所以Height的值永远是HeightInPoints的20倍


如果说,我非要获取到单元格行高的像素值,该怎么办呢?俺有个不太精确的方法。


网上有大神总结:
  EXCEL列高度的单位是磅,Apache POI的行高度单位是缇(twip)
  DPI = 1英寸内可显示的像素点个数。通常电脑屏幕是96DPI, IPhone4s的屏幕是326DPI, 普通激光黑白打印机是400DPI
  要计算POI行高或者Excel的行高,就先把它行转换到英寸,再乘小DPI就可以得到像素
  像素= (Excel的行高度/72)*DPI


所以获取行高的像素值的方法就是: (row.getHeightInPoints() / 72) * 96


 


四个方法对应的参考文档如下:


前两个,参考文档链接:https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Sheet.html



复制代码
getColumnWidth
    int getColumnWidth(int columnIndex)
    get the width (in units of 1/256th of a character width )
    Character width is defined as the maximum digit width of the numbers 0, 1, 2, ... 9 as rendered using the default font (first font in the workbook)
Parameters:
    columnIndex - - the column to get (0-based)
Returns:
    width - the width in units of 1/256th of a character width
复制代码

 



复制代码
getColumnWidthInPixels
    float getColumnWidthInPixels(int columnIndex)
    get the width in pixel
    Please note, that this method works correctly only for workbooks with the default font size (Arial 10pt for .xls and Calibri 11pt for .xlsx). If the default font is changed the column width can be streched
Parameters:
    columnIndex - - the column to set (0-based)
Returns:
    width in pixels
复制代码

  


后两个,参考文档链接:https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Row.html



复制代码
getHeight
short getHeight()
    Get the row's height measured in twips (1/20th of a point). If the height is not set, the default worksheet value is returned, See Sheet.getDefaultRowHeightInPoints()
Returns:
    row height measured in twips (1/20th of a point)
复制代码

 



复制代码
getHeightInPoints
    float getHeightInPoints()
    Returns row height measured in point size. If the height is not set, the default worksheet value is returned, See Sheet.getDefaultRowHeightInPoints()
Returns:
    row height measured in point size
See Also:
    Sheet.getDefaultRowHeightInPoints()
复制代码  

其他参考文章:使用Apache POI精确设置Excel的行高和列宽-CSDN博客

标签:width,单元格,像素,获取,POI,height,row
From: https://www.cnblogs.com/dirgo/p/17984626

相关文章

  • 获取猜你喜欢数据,类型定义和列表渲染
    1.封装获取猜你喜欢数据API2.组件挂载完毕调用API这个是接口文档:  下面: 组件内部获取数据,我们其他的都是在index.vue里面获取的: 我们来看一下数据,可以看到数据很多(items商品信息): 定义数据类型: 这里的分页我们其他地方也会用到,因此我们把他定义成一个通用的类......
  • python多线程id获取
    demoimportthreadingimporttimedefprint_thread_info(thread_name):"""线程函数,打印线程名称和ID以及一些文本"""foriinrange(3):time.sleep(1)thread_id=threading.current_thread().identprint(f"{thr......
  • 图论---可视区域获取(C++)
    1.开源库获取   地址:http://en.wikipedia.org/wiki/Visibility_graph2.使用使用处包含头文件 #include"visilibity.hpp"即可,以下面在Qt中使用为例:1/*2=========AVisiLibityExampleProgram=========3Thisprogramprovidesatextinterfacewhic......
  • get 获取n条数据
    //云涵数'usestrict';constdb=uniCloud.database()exports.main=async(event,context)=>{constcollection=db.collection(event.name)constres=awaitcollection.limit(event.num).get()returnres};//前端代码get(){uni.sh......
  • java 反射获取某个类的属性名和属性的值
    /***根据字段饰扣可以为空获取每个属性的变更内容如课程名称:英语-->数学;*@paramvo*@paramfieldName字段名:传值类型为CourseName周首字母大写*@paramdescribe字段的描述:可以理解为就是字段的名称如课程名称*@paramsbStringBuffer对象*@return*@th......
  • [element-ui] table表格点击单元格,单元格改变背景色
     <el-table:data="tableData"border@cell-click="cellclick":cell-style="tableCellStyle"></el-table>data(){row:'',column:''}cellclick(row,column,cell......
  • [POI2014] KUR-Couriers
    可持久化线段树维护由任意一段区间得到的权值线段树线段树的深度:\(ceil(log_{2}(n))+1\)由于询问的特殊性,我们可以直接在线段树上二分,而不需要另写查询函数,从而节省掉1个log的复杂度点击查看代码#include<bits/stdc++.h>usingnamespacestd;inttot,root[500005];int......
  • 安装Kaspersky Endpoint Security for Windows (12.3.0) 失败,提示安装了 360 Antiviru
    最近,在升级卡巴斯基KES时,部分用户出现安装失败,提示已安装360杀毒软件,需要卸载后再安装。用户已经删除所有360软件。 经过测试,需要在注册表删除:HKEY_CURRENT_USER下面的software里面360和2345的东西。HKEY_LOCAL_MACHINE下面的software中有关360和2345的东西。HKEY_LOCAL_MAC......
  • 使用windows工具获取性能数据(任务管理器+资源监视器)
    Windows工具 任务管理器执行taskmgr来打开任务管理器CPU内存磁盘 网络GPU 进程详细情况 资源监视器执行perfmon来打开资源监视器概述CPU内存磁盘网络 ......
  • 时间格式化,获取最近七天时间,获取昨天,明天得时间等
    时间格式化整理优化时间类发现之前发现大部分这样写的,获取当前日期,再一个个取年,月,日,再拼接成自己想要得格式letcurDate=newDate()letyyyy=curDate.getFullYear()letmm=curDate.getMonth()+1mm=mm<10?("0"+mm):mmletdd=curDate.getDate()......