使用DocumentBuild在word中添加table,怎么给单cell或某row填充底色

使用DocumentBuild在word中添加table,怎么给单cell或某row填充底色

@liufei951027 下面举例说明如何做到这一点:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.startTable();
builder.insertCell();
builder.write("City");
builder.insertCell();
builder.write("Country");
builder.endRow();
builder.insertCell();
builder.write("London");
builder.insertCell();
builder.write("U.K.");
builder.endTable();

Row row = table.getRows().get(0);
for (Cell cell : row.getCells())
    cell.getCellFormat().getShading().setBackgroundPatternColor(Color.BLACK);

CellFormat cellFormat = table.getLastRow().getFirstCell().getCellFormat();
cellFormat.getShading().setBackgroundPatternColor(Color.ORANGE);

doc.save("output.docx");

此外,请查看以下文章,了解创建表格的更多信息:How to Create a Table in Java|Aspose.Words for Java