Word字体的字号与像素对应关系

字号      OpenXMl大小    像素大小

初号      84            56    
小初      72            48
一号      52            34
小一      48            32
二号      44            29
小二      36            24
三号      32            21
小三      30            20
四号      28            18
小四      24            16
五号      21            14
小五      18            12
六号      15            10
小六      13            8
七号      11            7
八号      10            6

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Java中导出Word表格并设置表格的字体字号,你可以使用Apache POI库来实现。下面是一个示例代码: ```java import org.apache.poi.xwpf.usermodel.*; import java.io.FileOutputStream; import java.io.IOException; public class WordTableExporter { public static void main(String[] args) { // 创建文档对象 XWPFDocument document = new XWPFDocument(); // 创建表格对象 XWPFTable table = document.createTable(3, 3); // 创建一个3行3列的表格 // 设置表格字体字号 CTTblPr tblPr = table.getCTTbl().getTblPr(); CTFonts fonts = CTFonts.Factory.newInstance(); fonts.setAscii("Arial"); // 设置字体为Arial fonts.setHAnsi("Arial"); fonts.setCs("Arial"); CTHpsMeasure fontSize = CTHpsMeasure.Factory.newInstance(); fontSize.setVal(new BigInteger("14")); // 设置字号为14 fonts.setSz(fontSize); tblPr.setTblBorders(tblPr.addNewTblBorders()); // 添加表格边框 tblPr.getTblBorders().getTop().setVal(STBorder.SINGLE); tblPr.getTblBorders().getBottom().setVal(STBorder.SINGLE); tblPr.getTblBorders().getLeft().setVal(STBorder.SINGLE); tblPr.getTblBorders().getRight().setVal(STBorder.SINGLE); // 设置表格内容 for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { XWPFTableCell cell = table.getRow(row).getCell(col); cell.setText("Cell " + (row + 1) + "-" + (col + 1)); } } // 保存文档 try { FileOutputStream out = new FileOutputStream("table.docx"); document.write(out); out.close(); System.out.println("表格导出成功!"); } catch (IOException e) { e.printStackTrace(); } } } ``` 在上面的示例代码中,我们使用了`XWPFDocument`类创建一个新的Word文档对象,并使用`createTable`方法创建一个3行3列的表格。然后,我们使用`CTTblPr`类设置了表格的边框样式,使用`CTFonts`类设置了字体字号,并将其应用于表格。最后,我们使用`setText`方法将内容填充到表格单元格中,并将文档保存为"table.docx"文件。 你可以根据需要修改字体名称和字号值来适应你的需求。记得在运行代码之前,确保已经将Apache POI库添加到你的项目依赖中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值