Aspose邮件合并布局不关注Word模板

发布于 2025-01-30 17:47:45 字数 1449 浏览 2 评论 0原文

我使用Aspose Word,创建一个数据表,添加列,然后与单词模板合并。但是我在输出中发现,列宽度与单词模板有很大不同(例如,最后一列“最后一个值班日期”),为什么?

代码如下:

DataTable tableOrders = new DataTable("Orders");
tableOrders.getColumns().add("rank");
tableOrders.getColumns().add("staffNo");
tableOrders.getColumns().add("name");
tableOrders.getColumns().add("idNo");
tableOrders.getColumns().add("nature");
tableOrders.getColumns().add("effDate");
tableOrders.getColumns().add("b4effDate");
while(i.hasNext()) {
    Object[] rs = (Object[]) i.next();
    String rank = rs[0]==null?"":rs[0].toString();
    String staffNo = rs[1]==null?"":rs[1].toString();
    String name = rs[2]==null?"":rs[2].toString();
    String id_no = rs[3]==null?"":rs[3].toString();
    String nature = rs[4]==null?"":rs[4].toString();
    String effDate = rs[5]==null?"":(new SimpleDateFormat("yyyy-MM-dd")).format(rs[5]);
    String lastDutyDate = rs[6]==null?"":(new SimpleDateFormat("yyyy-MM-dd")).format(rs[6]);
    // Create the orders table.
    tableOrders.getRows().add(rank, staffNo, name, id_no, nature, effDate, lastDutyDate);
}
doc.getMailMerge().executeWithRegions(tableOrders);
doc.getMailMerge().execute(new String[] {"currentDate"}, new String[] {sdf2.format(new Date())});

”在此处输入图像描述”

I use aspose word, create a datatable, add column, and then mail merge with the word template. But I find in the output, the column width is very different from the word template (e.g. the last column "last date of duty"), why?

The code is as follows:

DataTable tableOrders = new DataTable("Orders");
tableOrders.getColumns().add("rank");
tableOrders.getColumns().add("staffNo");
tableOrders.getColumns().add("name");
tableOrders.getColumns().add("idNo");
tableOrders.getColumns().add("nature");
tableOrders.getColumns().add("effDate");
tableOrders.getColumns().add("b4effDate");
while(i.hasNext()) {
    Object[] rs = (Object[]) i.next();
    String rank = rs[0]==null?"":rs[0].toString();
    String staffNo = rs[1]==null?"":rs[1].toString();
    String name = rs[2]==null?"":rs[2].toString();
    String id_no = rs[3]==null?"":rs[3].toString();
    String nature = rs[4]==null?"":rs[4].toString();
    String effDate = rs[5]==null?"":(new SimpleDateFormat("yyyy-MM-dd")).format(rs[5]);
    String lastDutyDate = rs[6]==null?"":(new SimpleDateFormat("yyyy-MM-dd")).format(rs[6]);
    // Create the orders table.
    tableOrders.getRows().add(rank, staffNo, name, id_no, nature, effDate, lastDutyDate);
}
doc.getMailMerge().executeWithRegions(tableOrders);
doc.getMailMerge().execute(new String[] {"currentDate"}, new String[] {sdf2.format(new Date())});

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久夏青 2025-02-06 17:47:45

如我所见,您将输出文档保存为PDF。可能会出现问题,因为您的表布局是不当构建的。但是,没有您的真实文件,很难说。您可以在Aspose.words 支持论坛中发布问题。

另外,您可以尝试配置模板以使用固定列宽度

最有可能在模板中,自动拟合行为设置为autofit to contents,在执行邮件合并列宽度后,根据数据进行了调整。

As I can see you are saving your output document as PDF. The problem might occur because your table layout is built improperly. But it is difficult to say without your a real document. You can post your question and attach your document in Aspose.Words support forum.

Also, you can try configuring your template to use Fixed Column Width.

enter image description here

Most likely, in your template, auto fit behavior is set to AutoFit to Contents and after executing mail merge column widths are adjusted according to the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文