Aspose邮件合并布局不关注Word模板
我使用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())});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如我所见,您将输出文档保存为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
.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.