我已经通过 aspose.word 使用节点在 ms word 中创建了一个表。现在我需要一个表格,其中第二列将被合并(第一行除外) 我得到了合并列,但第一行和最后一行没有合并。第一行没问题,因为它是为此编码的。但我无法找出为什么最后一行没有合并。
I have not enough reputation to attach image. So, I have to describe details of my output
这是我的代码:
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);
}
}
}
}
}
最佳答案
通过运行您的代码,我得到以下输出。请确保您使用的是最新版本的Aspose.Words for Java 。如果您在最新版本中也遇到同样的问题,请分享您的环境详细信息,以便我可以在我身边重现它。 访问Aspose.Words for Java下载最新版本或直接下载Jar file来 self 们的 Maven 存储库。
披露:我是 Aspose 的开发人员。
关于java - 最后一行未使用 aspose word for java 合并到 ms word 表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25710251/