场景
客户要求一眼看清哪些订单要发货了。希望未来七天要发货的每天不同色标识,以免遗漏和方便备货。
一段Python代码搞定,未来七天要发货的黄色背景,字体每天不同色。
其他业务需求可以参考修改源代码。
# 第一步:按照需要添加程序集引用
import clr
clr.AddReference('mscorlib')
from System import *
def OnFormatRowConditions(args):
if (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(1)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#FF0000"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(1)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(2)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#c55a11"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(2)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(3)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#7030a0"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(3)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(4)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#0303fd"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(4)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(5)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#00b0f0"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(5)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(6)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#ec43e4"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(6)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(7)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#002060"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(7)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(8)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#d65db1"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif args.DataRow.DynamicObject["FDeliveryDate"] > DateTime.Now.Date.AddDays(8):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#008f7a"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
import clr
clr.AddReference('mscorlib')
from System import *
def OnFormatRowConditions(args):
if (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(1)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#FF0000"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(1)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(2)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#c55a11"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(2)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(3)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#7030a0"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(3)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(4)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#0303fd"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(4)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(5)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#00b0f0"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(5)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(6)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#ec43e4"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(6)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(7)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#002060"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif (args.DataRow.DynamicObject["FDeliveryDate"] >= DateTime.Now.Date.AddDays(7)and args.DataRow.DynamicObject["FDeliveryDate"] < DateTime.Now.Date.AddDays(8)):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#d65db1"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
elif args.DataRow.DynamicObject["FDeliveryDate"] > DateTime.Now.Date.AddDays(8):
fc = FormatCondition()
fc.ApplayRow = True
fc.ForeColor = "#008f7a"
fc.BackColor = "#fefedf"
args.FormatConditions.Add(fc);
列表上添加以上Python格式化代码:
暂无评论