Crystal Reports 2008:C#:动态编辑日期格式

发布于 2024-07-23 09:40:43 字数 1984 浏览 6 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦亿 2024-07-30 09:40:43

我需要同样的东西,并且终于找到了该怎么做。 您需要使用以下方法将修改后的字段应用到报告中:

reportClientDocument.ReportDefController.ReportObjectController.Modify(fieldObject, fieldObject);

I needed the same thing and FINALLY figured out how to do it. You need to apply the modified field to the report using:

reportClientDocument.ReportDefController.ReportObjectController.Modify(fieldObject, fieldObject);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文