【学习笔记】-运用python生成word并下载

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

【学习笔记】-运用python生成word并下载

image.webp

①创建菜单,标识改为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例如

image.webp

【学习笔记】-运用python生成word并下载

①创建菜单,标识改为CREATEDOC_Api (其中Api是生成word中用到的参数)②注册动态表单Python插件import clr#添加对cloud插件开发的常用组件...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息