Spire.Doc 能够非常完美的识别中文字符并支持丰富的word文档元素:文本框、页眉、页脚、项目符号和编号、表格、文本、超链接、水印、图片、形状等。
本文介绍如何使用Spire.Doc for Java让Word表格的列宽自适应内容,或者让Word表格的宽度自适应页面宽度,或者固定表格的列宽。如果你还没有使用过Spire.DOC for Java,可点击此处下载最新版测试。
列宽自适应内容
import com.spire.doc.*;
import com.spire.doc.fields.TextRange;
public class AutofitToContent {
public static void main(String[] args) {
//创建Document对象
Document document = new Document();
//添加节
Section section = document.addSection();
//添加表格
Table table = section.addTable();
//设置行数和列数
table.resetCells(3, 2);
//添加内容到单元格并设置字体
TextRange textRange = table.get(0, 0).addParagraph().appendText("产品编号");
textRange.getCharacterFormat().setFontName("宋体");
textRange = table.get(0, 1).addParagraph().appendText("名称");
<