【学习笔记】-运用python生成word并下载
①创建菜单,标识改为CREATEDOC_Api (其中Api是生成word中用到的参数)
②注册动态表单Python插件
import clr #添加对cloud插件开发的常用组件的引用 clr.AddReference('System') clr.AddReference('System.Data') clr.AddReference('Kingdee.BOS') clr.AddReference('Kingdee.BOS.DataEntity') clr.AddReference('Kingdee.BOS.Core') clr.AddReference('Kingdee.BOS.App') clr.AddReference('Kingdee.BOS.App.Core') clr.AddReference('Kingdee.BOS.ServiceHelper') clr.AddReference("Newtonsoft.Json") #导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入) from Kingdee.BOS import * from Kingdee.BOS.Core import * from Kingdee.BOS.Core.DependencyRules import * from Kingdee.BOS.Core.Bill import * from Kingdee.BOS.Core.DynamicForm.PlugIn import * from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import * from System import * from System.Data import * from System.IO import * from Kingdee.BOS.App.Data import * from System.Collections.Generic import List from Kingdee.BOS.ServiceHelper import * from Kingdee.BOS.Core.DynamicForm import * from Kingdee.BOS.Core.Metadata.EntityElement import * from Kingdee.BOS.Core.Metadata.FieldElement import * from Kingdee.BOS.Orm.DataEntity import * from Kingdee.BOS.Util import * from Newtonsoft.Json import JsonConvert from Newtonsoft.Json.Linq import * def BarItemClick(e): key=e.BarItemKey.ToUpperInvariant(); if(key=="CREATEDOC_API"): key=key.replace("CREATEHTML_","") fid=this.View.Model.GetPKValue(); billid=str(this.View.BillBusinessInfo.GetForm().Id); sql=("/*dialect*/exec CreateApiHtml '{0}','{1}','{2}'").format(billid,fid,key) ds=DBServiceHelper.ExecuteDataSet(this.Context,sql); AllRows=ds.Tables[0].Rows if(AllRows.Count<=0): return; html=AllRows[0][0] html=html.replace("<!--RichEdit.WPF1-->","") fileName=this.View.Model.GetValue("FBillNo")+".doc" Path=PathUtils.GetPhysicalPath(KeyConst.TEMPFILEPATH, fileName) fileUrl=PathUtils.GetServerPath(KeyConst.TEMPFILEPATH, fileName) sw=StreamWriter(Path, False) sw.WriteLine(html); sw.Flush(); sw.Close(); showParameter=DynamicFormShowParameter(); showParameter.FormId="BOS_FileDownload"; showParameter.OpenStyle.ShowType=ShowType.Modal; showParameter.CustomParams.Add("url", fileUrl); this.View.ShowForm(showParameter); #this.View.ShowMessage(fileUrl)
注意需要引用
from System.IO import *
③创建存储过程,exec CreateApiHtml '业务对象','单据内码','菜单标识', 生成word所需的html内容,如果要赋值到富文本控件,需要在html前面加上<!--RichEdit.WPF1-->
最终生成的word例如
【学习笔记】-运用python生成word并下载
①创建菜单,标识改为CREATEDOC_Api (其中Api是生成word中用到的参数)②注册动态表单Python插件import clr#添加对cloud插件开发的常用组件...
点击下载文档
本文2024-09-16 17:16:49发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-14683.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章