-
word table
table分两种
word中的table对应org.anyline.office.docx.entity.Wtable
与html中的table对就org.anyline.office.docx.entity.html.Table
word中的Table需要从Document中提取
根据书签获取word中的表格,需要在表格中添加一个书签,在任何一个单元格添加都可以。
WDocument doc = new WDocument("file path");
Wtable table = doc.getTable("mk_table");
也可以获取所有table
List<Wtable> tables = doc.tables(); -
根据模板插入行
插入行 如果模板位于当前表中则从当前模板位置往后插入,否则插入到最后一行 Wtable.insert(Wtr template, String html) 如果提供了下标,则插入到下标位置 Wtable.insert(Integet index, Wtr template, String html -
单元格文本替换
/** * 文本替换,不限层级查的所有t标签 * @param target 查找target * @param replacement 替换成replacement -
提取单元格(tc)中的文本
Wtc tc = 一般通过上级Wtr.getTcs()获取 也可以直接通过Wtable.getTc(行,列)获取 tc.getText() 查找直接子级t标签文本,tc中可能有多个 t标签,可以调用getTextList或getText返回所有t标签文本(不限层级) t -
提取word中的所有table
WDocument doc = new WDocument(file); List<Wtable> tables = doc.tables(); -
根据书签获取word中的表格
根据书签获取word中的表格,需要在表格中添加一个书签,在任务一个单元格添加都可以。 WDocument doc = new WDocument(tar); Wtable table = doc.getTable("mk_table"); -
在表格中根据书签获取指定行
需要在tr中插入书签,在当前行的任意单元格都可以 Wtr tr = table.getTr("mk_tr"); -
在表格中插入一行
在表格中插入一行 -
根据数据集合往word中的table插入行
现有表格中插入行 有些表格的样式比较复杂,可以先在word中创建好模版,把数据插入到模版中,并复制模版中的样式,这样html中就不需要设置复杂的css只填充数据就可以。 首先在表格中插入一个书签 通过WTable table = WDocumnt.getTable("书签名");获取表格 如果表格大于2行,将自动以最后一行作为样式模板。执行完插入后,模版行将被删除,表格中经常以空行作为最后一行并在这一行上设置字体等样式。 -
现有表格中插入行(根据模板行样式)
现有表格中插入行(根据模板行样式) 首先在表格的模版中插入一个书签 通过WTable table = WDocumnt.getTable("书签名");获取表格 通过WTr template = WDocumnt.getTr("书签名");获取模版行 -
根据数据集生成tr插入table
根据数据集生成tr插入table,如果是集合则会插入多行,否则插入一行 -
根据数据集生成tr插入table的指定位置
table.insert(index, list, "ID","NAME"); index表示需要插入的下标位置 -
table获取行或列
Wtr tr = table.getTr(rows); Wtc tc = table.getTc(rows, cols); -
设置单元格内容(含css样式)
设置单元格内容(含css样式) -
在指定位置添加行列,默认复制上一行(列)样式
所有行添加一列,并复制前一列的样式 table.addColumns(1); 从下标1位置开始添加10行,并复制上一行的样式 table.addRows(1,10); -
设置单元格背景色
table.setBackgroundColor(rows, cols, "red"); 支持css颜色值 -
设置默认边框
table.setBorder(rows, cols); 边框线条以4为一个单位 table.setBorder(rows, cols, 4, "red", "single"); -
设置所有单元格边框
设置所有单元格边框 边框有top bootom left right tl2br tr2bl insideH insideV table.setTcBorder(); table.setTl2brBorder(rows, cols); table.removeBorder(rows, cols); table.removeLeftBorder(rows, cols); -
设置高度宽度
高度表示整行高度 宽度表示整列宽度 table.setHeight(rwos, '100px'); table.setWidth(cols, '100px'); -
设置对齐方式
水平对齐 table.setAlign(rows, cols, "right"); 垂直对齐 table.stVerticalAlign(rows, cols, "top"); -
设置字体
字号支持word字号与html字号 table.setFontSize(rows, cols, "一号"); table.setFontSize(rows, cols, "30pt"); table.setFontFamily(rows, cols, "黑体")