poi设置行高,excel怎么设置行高

创新互联建站咨询电话:028-86922220,为您提供成都网站建设网页设计及定制高端网站建设服务,创新互联建站网页制作领域10年,包括广告推广等多个方面拥有多年的营销推广经验,选择创新互联建站,为企业保驾护航!

本文目录一览

1,excel怎么设置行高

选中要修改的所有行,在行标
(1 2 3……)处单击右键->行高,然后输入相应值就可以了

右击左侧序号栏,选择设置行高。。。

2,java POI excel 自动调整行高请高手给予解答谢谢请注意是在

HSSFWorkbook wb = new HSSFWorkbook();HSSFSheet sheet = wb.createSheet();HSSFRow row = sheet.createRow(0);然后使用row.setHeight()或者row.setHeightInPoints()来调整行高

3,在excel中如何设置行高

office 2007中是这样的:选中要设置的行,在开始-->单元格-->格式-->行高中设置。

选择要设置行高的一行或多行点击右键,选择“行高”,输入行高数字,点击确定,就设置好了行高。

excel中行高的设置方法如下:一、打开excel,把鼠标指针放到1、2、3等序号之间的中间线上,此时鼠标会变成一个“十”字状,可以上下拖动的状态。
二、此时可以拖着这条中间线向下拖动 ,根据需要,想让行高变多少就拖多少。
三、当拖动到需要的指定位置,松开鼠标,此时一整行的单元格高度就都被设置成了一样的行高。如果想把一整列单元格全部设置为一样的高度,就用鼠标左键选定左边的数字栏,向下拖动即可。拖动完成,这一列全部选定,用鼠标指针向下拖动某二个单元格之间的中间线,拖动到理想位置的大小,松开鼠标。

选中你要设置行高的单元格,点菜单栏的格式—行—行高。

选取行,再在行号的间隙中调整就可以调整行高了。列也如此。另外也可以这样: 选取行,右击,行高。列的话也类似的。

在excel里面,把鼠标放在最左边的数字上变成箭头符号,点击鼠标左键覆盖要设置的范围,在点击右键选择“行高”设置就可以了

4,如何利用poi对excel里的某一列的宽度进行设定

EXCEL的行高度和列宽度单位是不一样的。
1,EXCEL列高度的单位是磅,Apache POI的行高度单位是缇(twip):1英寸=72磅=25.4毫米=1440缇1磅=0.353毫米=20缇POI中的行高=Excel的行高度*20Excel的行高度=POI中的行高/20这里顺便把像素的换行方法说一下:DPI = 1英寸内可显示的像素点个数。通常电脑屏幕是96DPI, IPhone4s的屏幕是326DPI, 普通激光黑白打印机是400DPI要计算POI行高或者Excel的行高,就先把它行转换到英寸,再乘小DPI就可以得到像素像素 = (磅/72)*DPI像素= (Excel的行高度/72)*DPI像素= (POI中的行高/20/72)*DPIExcel的行高度=像素/DPI*72POI中的行高=像素/DPI*72*20例如在电脑屏幕上, Excel默认行高度为13.5, (13.5/72)*96=18像素,而Excel中也确实显示的就是18像素。
2,EXCEL列宽度的单位是字符个数
(2014-08-18备注:关于Excel的宽度计算的详细介绍在这篇文章Excel的宽度怎么算的?)在excel2003以上的版本中,可以建立一个空白的xls文档并将第一列宽度拉到10。然后在A1单元格中输入1234567890可以看到单元格正好可以容纳这十个字符。
一个字符的宽度是通过测量1234567890这十个字符在默认字体(通常是宋体11号字,视版本可能不同)下的平均宽度得到的。只要记住一个字符的宽度是8像素 (2013-10-29备注:一个字符的宽度取决于Excel文件中的第一个字体大小,并不一定就是8像素)就可以了。
一个单元格实际的像素宽度还要在(字符个数 * 默认字符的宽度)的基础上前后各加2个像素的空白边。另外字符之间会叠加一个像素,在计算时也要减去:(2013-10-29备注:一个字符的边距不一定只是2像素,和字体有关系)像素 = 2个像素空白 + (字符个数 * 默认字符的宽度) + 2个像素空白 - (字符个数 - 1)整理一下,公式变成:像素 = 5 + (字符个数 * (默认字符的宽度 - 1))代入默认字符宽度8:像素 = 5 + (字符个数 * 7)POI中的字符宽度算法是:double 宽度 = (字符个数 * (字符宽度 - 1) + 5) / (字符宽度 - 1) * 256;然后再四舍五入成整数。最后把我写的一个工具类贴上来,方便使用。public class HSSFUtil private static final short TWIPS_PER_PIEXL = 15; //1 Pixel = 1440 TPI / 96 DPI = 15 Twips public static short pixel2PoiHeight(int pixel) return (short) (pixel * TWIPS_PER_PIEXL); } public static int poiHeight2Pixel(short height) return height / TWIPS_PER_PIEXL; } //像素转poi宽度 public static int pixel2PoiWidth(FontInfo fontInfo, int pixel) double numChars = pixel2Character(fontInfo, pixel); numChars *= fontInfo.charWidth; numChars += fontInfo.spacing; numChars /= fontInfo.charWidth; numChars *= 256; return (int)numChars; } //poi宽度转像素 public static int poiWidth2Pixel(FontInfo fontInfo, int poiWidth) double numChars = poiWidth2Character(fontInfo, poiWidth); return character2Piexl(fontInfo, numChars); } public static double poiWidth2Character(FontInfo fontInfo, int poiWidth) double numChars = poiWidth / 256.0 - (fontInfo.spacing * 1.0 / fontInfo.charWidth); //2位小数 return new BigDecimal(numChars).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); } public static int character2PoiWidth(FontInfo fontInfo, double numChars) double w = (numChars + (fontInfo.spacing * 1.0 / fontInfo.charWidth)) * 256; return (int) w; } //excel字符转像素 public static int character2Piexl(FontInfo fontInfo, double numChars) double pixel = fontInfo.charWidth * numChars + fontInfo.spacing; return (int)pixel; } //excel像素转字符 public static double pixel2Character(FontInfo fontInfo, int pixel) double numChars = (pixel - fontInfo.spacing) * 1.0 / fontInfo.charWidth; return new BigDecimal(numChars).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); } //获得工作簿默认字符宽度 public static FontInfo getDefaultCharWidth(Workbook book) //博客没人气,我已删除此段代码,请自行研究或者留邮箱 } //获得不同字体的字符边距 private static int getSpacing(int fontHeightInPoints, int charWidth) //博客没人气,我已删除此段代码,请自行研究或者留邮箱 } }

你好,去看一下官方的api文档,或许你就会了https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/sheet.html

5,POI生成excel如何实现自动调整行高

在开发中经常需要用到对Excel文件的操作,POI生成excel实现自动调整行高的代码如下: import javaioFileOutputStream; import orgapachepoihssfusermodelHSSFCell; import orgapachepoihssfusermodelHSSFCellStyle; import orgapac

在开发中经常需要用到对excel文件的操作,poi生成excel实现自动调整行高的代码如下:import java.io.fileoutputstream;import org.apache.poi.hssf.usermodel.hssfcell;import org.apache.poi.hssf.usermodel.hssfcellstyle;import org.apache.poi.hssf.usermodel.hssffont;import org.apache.poi.hssf.usermodel.hssfrow;import org.apache.poi.hssf.usermodel.hssfsheet;import org.apache.poi.hssf.usermodel.hssfworkbook;import org.apache.poi.hssf.usermodel.hssfrichtextstring;import org.apache.poi.hssf.usermodel.hssfdataformat;import org.apache.poi.hssf.usermodel.hssfcomment;import org.apache.poi.hssf.usermodel.hssfpatriarch;import org.apache.poi.hssf.usermodel.hssfclientanchor;public class poicreateexceltest public static void main(string[] args) /** * @see for more */ // 创建新的excel 工作簿 hssfworkbook workbook = new hssfworkbook(); // 在excel工作簿中建一工作表,其名为缺省值, 也可以指定sheet名称 hssfsheet sheet = workbook.createsheet(); //hssfsheet sheet = workbook.createsheet("sheetname"); // 用于格式化单元格的数据 hssfdataformat format = workbook.createdataformat(); // 创建新行(row),并将单元格(cell)放入其中. 行号从0开始计算. hssfrow row = sheet.createrow((short) 1); // 设置字体 hssffont font = workbook.createfont(); font.setfontheightinpoints((short) 20); //字体高度 font.setcolor(hssffont.color_red); //字体颜色 font.setfontname("黑体"); //字体 font.setboldweight(hssffont.boldweight_bold); //宽度 font.setitalic(true); //是否使用斜体// font.setstrikeout(true); //是否使用划线 // 设置单元格类型 hssfcellstyle cellstyle = workbook.createcellstyle(); cellstyle.setfont(font); cellstyle.setalignment(hssfcellstyle.align_center); //水平布局:居中 cellstyle.setwraptext(true); // 添加单元格注释 // 创建hssfpatriarch对象,hssfpatriarch是所有注释的容器. hssfpatriarch patr = sheet.createdrawingpatriarch(); // 定义注释的大小和位置,详见文档 hssfcomment comment = patr.createcomment(new hssfclientanchor(0, 0, 0, 0, (short)4, 2, (short) 6, 5)); // 设置注释内容 comment.setstring(new hssfrichtextstring("可以在poi中添加注释!")); // 设置注释作者. 当鼠标移动到单元格上是可以在状态栏中看到该内容. comment.setauthor("xuys."); // 创建单元格 hssfcell cell = row.createcell((short) 1); hssfrichtextstring hssfstring = new hssfrichtextstring("hello world!"); cell.setcellvalue(hssfstring);//设置单元格内容 cell.setcellstyle(cellstyle);//设置单元格样式 cell.setcelltype(hssfcell.cell_type_string);//指定单元格格式:数值、公式或字符串 cell.setcellcomment(comment);//添加注释 //格式化数据 row = sheet.createrow((short) 2); cell = row.createcell((short) 2); cell.setcellvalue(11111.25); cellstyle = workbook.createcellstyle(); cellstyle.setdataformat(format.getformat("0.0")); cell.setcellstyle(cellstyle); row = sheet.createrow((short) 3); cell = row.createcell((short) 3); cell.setcellvalue(9736279.073); cellstyle = workbook.createcellstyle(); cellstyle.setdataformat(format.getformat("#,##0.0000")); cell.setcellstyle(cellstyle); sheet.autosizecolumn((short)0); //调整第一列宽度 sheet.autosizecolumn((short)1); //调整第二列宽度 sheet.autosizecolumn((short)2); //调整第三列宽度 sheet.autosizecolumn((short)3); //调整第四列宽度 try fileoutputstream fileout = new fileoutputstream("c:/3.xls"); workbook.write(fileout); fileout.close(); } catch (exception e) system.out.println(e.tostring()); } }}

标题名称:poi设置行高,excel怎么设置行高
分享路径:https://www.cdcxhl.com/article48/iceehp.html

成都网站建设公司_创新互联,为您提供ChatGPT手机网站建设网站排名外贸建站移动网站建设企业网站制作

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

小程序开发