从Crystal Reports导出到Excel而没有页眉/页脚

时间:2021-12-23 00:27:08

Just wondering if anybody had working code example (in c#) for exporting a crystal report to Excel from a .NET application without the report's page headers and footer's.

只是想知道是否有人有工作代码示例(在c#中)从.NET应用程序导出水晶报表到Excel而没有报表的页眉和页脚。

I am using crystal reports v9 runtime.

我正在使用水晶报告v9运行时。

2 个解决方案

#1


1  

To accomplish this you actually need to do it in the Crystal Report. My recommendation is to add a parameter to it, and then edit the header and footer suppress formulas to check the parameter. That was how we accomplished it. If there is way to do it from your code I would be interested in knowing it also.

要实现此目的,您实际上需要在Crystal Report中执行此操作。我的建议是添加一个参数,然后编辑页眉和页脚抑制公式来检查参数。这就是我们完成它的方式。如果有办法从你的代码中做到这一点,我也有兴趣了解它。

Good luck!

#2


1  

Here my extension method for ReportDocument to supress all headers/footers. I use it for Excel export.

这里是ReportDocument的扩展方法,用于压缩所有页眉/页脚。我用它来Excel导出。

/// <summary>
/// Clears header/footer.
/// </summary>
/// <param name="rpt">The reportdocument</param>
public static void ClearReportHeaderAndFooter(this ReportDocument rpt)
{
    foreach (Section section in rpt.ReportDefinition.Sections)
    {
        if (section.Kind == AreaSectionKind.ReportHeader || section.Kind == AreaSectionKind.ReportFooter || section.Kind == AreaSectionKind.PageFooter || section.Kind == AreaSectionKind.PageHeader)
        {
            section.SectionFormat.EnableSuppress = true;
            section.SectionFormat.BackgroundColor = Color.White;
            foreach (var repO in section.ReportObjects)
            {
                if (repO is ReportObject)
                {
                    var reportObject = repO as ReportObject;
                    reportObject.ObjectFormat.EnableSuppress = true;

                    reportObject.Border.BorderColor = Color.White;
                }
            }
        }
    }
}

Use it like this:

像这样用它:

myReportDocument.ClearReportHeaderAndFooter();

#1


1  

To accomplish this you actually need to do it in the Crystal Report. My recommendation is to add a parameter to it, and then edit the header and footer suppress formulas to check the parameter. That was how we accomplished it. If there is way to do it from your code I would be interested in knowing it also.

要实现此目的,您实际上需要在Crystal Report中执行此操作。我的建议是添加一个参数,然后编辑页眉和页脚抑制公式来检查参数。这就是我们完成它的方式。如果有办法从你的代码中做到这一点,我也有兴趣了解它。

Good luck!

#2


1  

Here my extension method for ReportDocument to supress all headers/footers. I use it for Excel export.

这里是ReportDocument的扩展方法,用于压缩所有页眉/页脚。我用它来Excel导出。

/// <summary>
/// Clears header/footer.
/// </summary>
/// <param name="rpt">The reportdocument</param>
public static void ClearReportHeaderAndFooter(this ReportDocument rpt)
{
    foreach (Section section in rpt.ReportDefinition.Sections)
    {
        if (section.Kind == AreaSectionKind.ReportHeader || section.Kind == AreaSectionKind.ReportFooter || section.Kind == AreaSectionKind.PageFooter || section.Kind == AreaSectionKind.PageHeader)
        {
            section.SectionFormat.EnableSuppress = true;
            section.SectionFormat.BackgroundColor = Color.White;
            foreach (var repO in section.ReportObjects)
            {
                if (repO is ReportObject)
                {
                    var reportObject = repO as ReportObject;
                    reportObject.ObjectFormat.EnableSuppress = true;

                    reportObject.Border.BorderColor = Color.White;
                }
            }
        }
    }
}

Use it like this:

像这样用它:

myReportDocument.ClearReportHeaderAndFooter();