Python插件常见报错原因
@ lsq | 星期一,十二月 12 日,2022 年 | 2 分钟阅读 | 更新于 星期一,十二月 12 日,2022 年

Python表单插件报错

常用引用

import clr
clr.AddReference('Kingdee.BOS.App')
clr.AddReference('Kingdee.BOS.DataEntity')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.ServiceHelper')
clr.AddReference('Kingdee.BOS.Contracts')
clr.AddReference('Kingdee.BOS')
clr.AddReference('System.Data')
clr.AddReference('System')
clr.AddReference("System.Core")
clr.AddReference("Kingdee.BOS")
clr.AddReference("Kingdee.BOS.Log")
clr.AddReference('Newtonsoft.Json')

from System import *
from System.Data import *
from System.Text import *
from System.Linq import *
from System.Collections import *
from System.Collections.Generic import *
from Kingdee.BOS.JSON import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.Const import *
from Kingdee.BOS.Core.Bill import *
from Kingdee.BOS.Core.List import *
from Kingdee.BOS.Log import *
from Kingdee.BOS.App.Data import *
from Kingdee.BOS.Orm.Metadata.DataEntity import * 
from Kingdee.BOS.Orm.DataEntity import *
from Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn import * 
from Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args import * 
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.ServiceHelper import * 
from Kingdee.BOS.Core.List.PlugIn import *
from Kingdee.BOS.Core.Metadata.EntityElement import *
from Newtonsoft.Json import JsonConvert
from Newtonsoft.Json.Linq import *

C#与Python代码转换

str() 与 ToString()

C#中ToString()对应python的str(),但是当返回python的None时,ToString()方法会报错,需要改用str(),或者判断是否为None.

list() 与 List()

Python中list()对应C#中的List(),使用的时候需要改写,例如:

C#写法是:List<LockStockArg> lst=new List<LockStockArg>();

Python写法就应该是:lst=List[LockStockArg]();

按照这样的方法实例化对象时候,lst.Add(lockStockArgs)就不会报错了

  • **模板类:**把"“改成”[T]",例如,C#中:var lst=new List()。Python插件中写成:lst=List[str]();

  • **反射代理:**C#插件中有时会用到反射代理类。在Python插件中将反射代理的类直接实例化进行使用。例如:

    C#代码中:

    IViewService viewService1 = Kingdee.BOS.Contracts.ServiceFactory.GetService<IViewService>(this.Context);

    Python插件中写成:viewService1 =**ViewService();当然,还需要引入*ViewService*类的命名空间。

  • list转数组,需要用到ToArray()方法,前提是,不要用Python的list,要用C#的List[T](),否则构造的数据调用插件的一些方法是不被识别的

原文链接:https://vip.kingdee.com/article/332534862269551872?productLineId=1

字符串、字典{}包含
  1. 字典包含key:obj.ContainsKey(“MoEntryId”)
  2. string.Contains(“key”)

Reference

原文链接:https://vip.kingdee.com/article/95847781369345280

© 2011 - 2023 lsq 的博客

Powered by Hugo with theme Dream.

avatar
关于我

lsq 的 ❤️ 博客

记录一些 🌈 生活上,财务相关技术上的事

毕业于 🏫 东北财经大学

空闲时间会做分享财务工作上相关技术

主要分享是:

  • VBA & Power Query
  • Excel 图表制作
  • LaTeX

写着玩:

  • Ruby
  • Bash shell
  • Python

目前在深圳工作

– 2021 年 04 月 11 日更新