账表开发-设置日期格式原创
金蝶云社区-eris
eris
5人赞赏了该文章 1559次浏览 未经作者许可,禁止转载编辑于2022年01月20日 09:07:03

一、设置长日期格式

  1. 账表中的日期字段显示的都是短日期,如果要显示为长日期有两种方式:

    1) 把日期字段改成文本字段

    2)使用插件把长短日期转换格式设置为true

下面以销售订单执行明细为例,使用C#插件代码或python插件代码把长日期改成短日期

  1、插件代码如下

using System;
using System.Text;
using System.ComponentModel;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Report.PlugIn;
namespace Kingdee.BOS.TestPlugIn.Report
{
     [HotUpdate]
     [Description("销售订单明细报表插件2")]
    public class SalReportServicePlugIn1 : AbstractSysReportPlugIn
    {
         public override void OnInitialize(InitializeEventArgs e)
         {
             base.OnInitialize(e);
             //订单日期
             var fDate = this.View.BillBusinessInfo.GetField("FDate") as DateTimeField;
             fDate.IsConvertDate = true;
             //出库日期
             var fDate2 = this.View.BillBusinessInfo.GetField("FOUTSTOCKDATE") as DateTimeField;
             fDate2.IsConvertDate = true;
         }
    }
}


  2、 python插件代码:

	import clr
clr.AddReference("Kingdee.BOS.Core")
from Kingdee.BOS.Core.Metadata.FieldElement import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.Args import *
from Kingdee.BOS.Core.Report.PlugIn import *
from System import *

def OnInitialize(e):
    fDate = this.View.BillBusinessInfo.GetField("FDate")
    fDate.IsConvertDate = True
    fDate2 = this.View.BillBusinessInfo.GetField("FOUTSTOCKDATE")
    fDate2.IsConvertDate = True

  3、注册插件

image.png

4. 运行效果:

image.png

二、使用格式化把日期显示为短日期

import clr
clr.AddReference("Kingdee.BOS")
clr.AddReference("Kingdee.BOS.Core")
from Kingdee.BOS.Util import *
from Kingdee.BOS import *
from Kingdee.BOS.Core.Report.PlugIn.Args import *
from System import *
def FormatCellValue(args):
    if args.Header.Key=="F_FZRQ" and args.FormateValue.strip() !='':
        oldValue = Convert.ToDateTime(args.FormateValue)
        newValue = oldValue.ToShortDateString()
        args.FormateValue = newValue


赞 5