设置表格线条样式
示例代码
package test.create.c04;
import iofd.kernel.colors.OfdRgbColor;
import iofd.layout.OfdDocument;
import iofd.layout.block.Paragraph;
import iofd.layout.block.Table;
import iofd.layout.element.graph.Border;
import iofd.layout.element.graph.LineStyle;
import iofd.layout.element.table.Cell;
import iofd.layout.element.table.HeadCell;
import iofd.layout.element.table.TableRow;
import java.util.ArrayList;
import java.util.List;
import test.create.TestDocUtil;
public class C0416TableSetLineStyle {
public static void main(String[] args) throws Throwable {
C0416TableSetLineStyle o = new C0416TableSetLineStyle();
o.done();
}
private void done() throws Throwable {
String clzName = this.getClass().getSimpleName();
System.out.println(clzName + " begin");
OfdDocument doc = new OfdDocument();
String s = "这是一个表格的示例,这里演示如何设置表格线条样式";
Paragraph p = new Paragraph();
p.add(s);
doc.add(p);
/*
* 设置表格线条样式
* */
LineStyle style = new LineStyle();
style.setWidth(0.7f);
style.setStrokeColor(OfdRgbColor.RED);
Border border = new Border(style);
TableRow row0 = new TableRow(0);
List head0 = new ArrayList<>();
HeadCell c = new HeadCell(0, 0, 0, 0);
c.setBorder(border);
c.add("标题一");
head0.add(c);
c = new HeadCell(0, 1, 0, 0);
c.setBorder(border);
c.add("标题二");
head0.add(c);
c = new HeadCell(0, 2, 0, 0);
c.setBorder(border);
c.add("标题三");
head0.add(c);
row0.setCellList(head0);
List head = new ArrayList<>();
head.add(row0);
List body = createBody();
Table table = Table.createTable(head, body);
doc.add(table);
String fileName = TestDocUtil.getOfdFilePath(this.getClass());
doc.save(fileName);
System.out.println(clzName + " end");
}
private List createBody() throws Exception {
List ret = new ArrayList<>();
for (int i = 0; i < 10; i++) {
TableRow row = new TableRow(i);
List cellList = new ArrayList<>();
for(int j = 0; j < 3; j++) {
Cell c = new Cell(i, j);
c.add("[" + i + "," + j + "]");
cellList.add(c);
}
row.setCellList(cellList);
ret.add(row);
}
return ret;
}
}
| |