|
楼主 |
发表于 2017-5-31 14:05:38
|
显示全部楼层
已解决,可以结帖!
通过vba操作转成js实现!
Model.prototype.attContOfficeLoaded = function(event) {
//debugger;
var data = this.comp("mainData");
// 将需要填充的内容构造成一个JSON数据
var detail = this.comp("detailData");
var djson = "";
detail.each(function(op){
var remark = op.row.val('REMARK')==undefined?""p.row.val('REMARK');
var collDate = op.row.val('COLL_DATE')==undefined?""p.row.val('COLL_DATE');
djson += '{"ITEM_NO":"'+op.row.val('ITEM_NO')+'"'
+',"COLL_TYPE_NAME":"'+op.row.val('COLL_TYPE_NAME')+'"'
+',"COLL_AMT":"'+op.row.val('COLL_AMT')+'"'
+"},";
});
djson = "["+djson.substring(0, djson.length-1)+"]";
var p = {
"CONT_NAME" : data.getValue("CONT_NAME"),
"CONT_ISSG_PARTY" : data.getValue("CONT_ISSG_PARTY"),
"CONTRACTOR" : data.getValue("CONTRACTOR"),
"dt":djson
};
event.officeEditorContext.execute(function(params, officeEditor, ovObj) {
// 当前文档对象实例
var activeDocument = ovObj.ActiveDocument;
// 全局的选中对象实例
var selection = ovObj.ActiveDocument.Application.Selection;
// 在officeEditor对话框的页面内获取officeViewer
// 遍历填充数据
$.each(params, function(k, v) {
if (k === "dt") {
return true;
}
// 填充
ovObj.WriteWordBookmarkInfo(k, v);
});
// 填充表格数据,获取word中的第二个表格
var table = activeDocument.Tables(2);
var o;
var obj = eval('(' + params.dt + ')');
for (o in obj) {
table.Rows.Last.Select();
selection.InsertRowsBelow(1);
selection.MoveRight(12); // tab 键功能,移至下一列
selection.TypeText(obj[o].ITEM_NO);
selection.MoveRight(12);
selection.TypeText(obj[o].COLL_TYPE_NAME);
selection.MoveRight(12);
selection.TypeText(obj[o].COLL_AMT);
}
}, p);
}; |
|