我通过 aspose.word 使用节点在 ms word 中创建了一个表。现在我需要第二列将被合并的表,除了第一行我得到了合并列,但第一行和最后一行没有合并。第一行没问题,因为它是为此编码的。但我不知道为什么最后一行没有合并。
我没有足够的声誉来附上图片。所以,我必须描述我的输出的细节
这是我的代码:
Document doc=new Document();
Table table = new Table(doc);
// Add the table to the document.
doc.getFirstSection().getBody().appendChild(table);//add table
Row row[]= new Row[4];Cell cell[] = new Cell[3];
for (int i = 0; i < row.length; i++) {
row[i]=new Row(doc);table.appendChild(row[i]);
table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW);//if I set this here last row not //merge
for (int j = 0; j < cell.length; j++) {
cell[j]=new Cell(doc);
row[i].appendChild(cell[j].deepClone(false));//cell creation
// but in this position table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW) create //no problem
row[i].getLastCell().appendChild(new Paragraph(doc));
if(row[i]==table.getFirstRow())
{
}
else
{
if(j==1)
{
if(i==1)
{
row[i].getCells().get(j).getCellFormat().setVerticalMerge(CellMerge.FIRST);
}
else
{
row[i].getCells().get(j).getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
}
}
}
}
}