最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

Creating a Word document with repeating in Dynamics ax 2012

网络文摘 William 3148浏览 0评论

In this recipe, we will create a Word document with repeating elements. For this demonstration, we will display the contents of the LedgerParameters table in a dynamically generated Word table
we need to prepare a new Word template and save it as a file named table.dotx. The template should contain one bookmark named TableName at the top, and one table beneath with a single row and two columns, as follows:
w2

In the AOT, create a new job named CreateWordTable with the following code:
static void CreateWordTable(Args _args)
{
TableId tableId;
COM word;
COM documents;
COM document;
COM bookmarks;
COM bookmark;
COM tables;
COM table;
COM rows;
COM row;
COM cells;
COM cell;
COM range;
Query query;
QueryRun queryRun;
Common common;
TmpSysTableField fields;
DictField dictField;
int i;
void processBookmark(str _name, str _value)
{
if (!bookmarks.exists(_name))
{
return;
}
bookmark = bookmarks.item(_name);
range = bookmark.range();
range.insertAfter(_value);
}
#define.Word(‘Word.Application’)
#define.template(@’C:temptable.dotx’);
tableId = tableNum(LedgerParameters);
try
{
word = new COM(#Word);
}
catch (Exception::Internal)
{
if (word == null)
{
throw error(“Microsoft Word is not installed”);
}
}
documents = word.documents();
document = documents.add(#template);
bookmarks = document.bookmarks();
processBookmark(
‘TableName’,
tableId2pname(tableId));
tables = document.tables();
table = tables.Item(1);
rows = table.rows();
query = new Query();
query.addDataSource(tableId);
queryRun = new QueryRun(query);
queryRun.next();
common = queryRun.get(tableId);
fields = TmpSysTableField::findTableFields(
null, tableId);
while select fields
{
dictField = new DictField(
tableId,
fields.FieldId);
if (dictField.isSystem())
{
continue;
}
i++;
row = rows.item(i);
cells = row.cells();
cell = cells.item(1);
range = cell.range();
range.insertAfter(fields.FieldLabel);
cell = cells.item(2);
range = cell.range();
range.insertAfter(
strFmt(‘%1′, common.(fields.FieldId)));
row = rows.add();
}
row.delete();
word.visible(true);
}

2. Run the job to generate the document containing a list, the LedgerParameters table
field, and their values:

w23


发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址