Crystal Reports 2008:C#:动态编辑日期格式
我正在使用 Crystal Reports 2008 在 c# .Net 中的运行时修改报表。
我在修改日期字段格式时遇到问题。 我已访问 DateFieldFormat 对象并修改了属性,但只有 SystemDefaultType 属性似乎有任何影响。
如果在可视化报表设计器中设置了日期格式,我可以在 DateFieldObject 中看到格式的详细信息,但编辑这些值不会对显示的报表产生任何影响。
这是我正在使用的代码示例:
using statements:
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.DataDefModel;
using CrystalDecisions.ReportAppServer.ReportDefModel;
using CrystalDecisions.ReportAppServer.CommonObjectModel;
using CrystalDecisions.ReportAppServer.ObjectFactory;
Code:
public Form1()
{
InitializeComponent();
CrystalDecisions.CrystalReports.Engine.ReportDocument reportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
ISCDReportClientDocument reportClientDocument;
// Load Report
reportDocument.Load(@"C:\myReport.rpt");
reportClientDocument = reportDocument.ReportClientDocument;
// Access Field
FieldObject fieldObject = (FieldObject)reportClientDocument.ReportDefinition.DetailArea.Sections[0].ReportObjects["DateField1"];
// These work, if I want to use one of the default formats
// fieldObject.FieldFormat.DateFormat.SystemDefaultType = CrDateSystemDefaultTypeEnum.crDateSystemDefaultTypeUseLongDate;
// fieldObject.FieldFormat.DateFormat.SystemDefaultType = CrDateSystemDefaultTypeEnum.crDateSystemDefaultTypeUseShortDate;
// I don't want to use one of the defaults.
fieldObject.FieldFormat.DateFormat.SystemDefaultType = CrDateSystemDefaultTypeEnum.crDateSystemDefaultTypeNotUsingDefaults;
// I want to change the order of the values
fieldObject.FieldFormat.DateFormat.DateOrder = CrDateOrderEnum.crDateOrderDayMonthYear;
// Display the report in the viewer
crystalViewer.ReportSource = rpt.rcd.ReportSource;
}
我假设我在这里遗漏了有关对象模型的一些内容,但我找不到任何好的参考。 有人可以帮我吗?
谢谢!
I'm modifying a report at runtime in c# .Net using Crystal Reports 2008.
I'm having trouble modifying a date fields format. I have accessed the DateFieldFormat object, and modified the properties, but only the SystemDefaultType property seems to have any affect.
If the Date format is set in the Visual Report Designer I can see the details of the format in DateFieldObject, but editing these values doesn't have any affect on the report once displayed.
Here is a sample of the code i'm using:
using Statements:
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.DataDefModel;
using CrystalDecisions.ReportAppServer.ReportDefModel;
using CrystalDecisions.ReportAppServer.CommonObjectModel;
using CrystalDecisions.ReportAppServer.ObjectFactory;
Code:
public Form1()
{
InitializeComponent();
CrystalDecisions.CrystalReports.Engine.ReportDocument reportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
ISCDReportClientDocument reportClientDocument;
// Load Report
reportDocument.Load(@"C:\myReport.rpt");
reportClientDocument = reportDocument.ReportClientDocument;
// Access Field
FieldObject fieldObject = (FieldObject)reportClientDocument.ReportDefinition.DetailArea.Sections[0].ReportObjects["DateField1"];
// These work, if I want to use one of the default formats
// fieldObject.FieldFormat.DateFormat.SystemDefaultType = CrDateSystemDefaultTypeEnum.crDateSystemDefaultTypeUseLongDate;
// fieldObject.FieldFormat.DateFormat.SystemDefaultType = CrDateSystemDefaultTypeEnum.crDateSystemDefaultTypeUseShortDate;
// I don't want to use one of the defaults.
fieldObject.FieldFormat.DateFormat.SystemDefaultType = CrDateSystemDefaultTypeEnum.crDateSystemDefaultTypeNotUsingDefaults;
// I want to change the order of the values
fieldObject.FieldFormat.DateFormat.DateOrder = CrDateOrderEnum.crDateOrderDayMonthYear;
// Display the report in the viewer
crystalViewer.ReportSource = rpt.rcd.ReportSource;
}
I'm assuming I'm missing something about the object model here, but I can't find any good reference to it. Can someone help me out?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我需要同样的东西,并且终于找到了该怎么做。 您需要使用以下方法将修改后的字段应用到报告中:
I needed the same thing and FINALLY figured out how to do it. You need to apply the modified field to the report using: