码农的狗蛋 2023-06-13 09:51 采纳率: 47.9%
浏览 13

请问spiredoc在word文档中,读取的表格在填入数据后,为什么会默认有换行呢,如下图

请问spiredoc在word文档中,读取的表格在填入数据后,为什么会默认有换行呢,如下图

img


代码如下:

                     Document doc= new Document(in);
            Table table = doc.getSections().get(0).getTables().get(0);
                    TableCell tc1=table.getRows().get(0).getCells().get(1);
                Paragraph para1 = new Paragraph(doc);
                para1.appendText(ceshi);
                tc1.getParagraphs().add(para1);
  • 写回答

1条回答 默认 最新

  • 辉煌仪奇 2023-06-13 10:15
    关注
    Document doc = new Document(in);
    Table table = doc.getSections().get(0).getTables().get(0);
    TableCell tc1 = table.getRows().get(0).getCells().get(1);
    
    // 移除单元格中的所有子元素(包括换行符)
    tc1.getParagraphs().get(0).removeAllChildren();
    
    // 添加文本
    Paragraph para1 = new Paragraph(doc);
    para1.appendText(ceshi);
    tc1.getParagraphs().add(para1);
    

    有帮助请采纳一下,谢谢

    评论

报告相同问题?

问题事件

  • 创建了问题 6月13日