weixin_45315260 2019-09-24 18:25 采纳率: 33.3%
浏览 1331
已采纳

c# aspose.words word表格都是添加行,怎么添加列?

c# aspose.words word表格都是添加行,怎么添加列?

  • 写回答

2条回答 默认 最新

  • threenewbee 2019-09-24 19:08
    关注

    下面的代码是java的,稍微修改即可适合C#
    添加列需要遍历每一行,然后在最后一个单元格后面再插入一个单元格

    //Open document
    
    Document doc = new Document("C:\\Temp\\in.doc");
    
    
    //Get table from the document
    
    Table tab = doc.getFirstSection().getBody().getTables().get(0);
    
    
    //Add few more columns
    
    for(int i=0; i<3; i++)
    
    {
    
    for(Row row : tab.getRows())
    
    {
    
    //clone las cell of the row and append it to the row
    
    Node cellClone = row.getLastCell().deepClone(true);
    
    row.appendChild(cellClone);
    
    }
    
    }
    
    
    //Save output document
    
    doc.save("C:\\Temp\\out.doc");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?