从不带页眉/页脚的Crystal Reports导出到Excel

本文关键字:Reports Crystal Excel | 更新日期: 2023-09-27 17:47:24

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

我使用的是crystal reports v9运行时。

从不带页眉/页脚的Crystal Reports导出到Excel

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

祝你好运!

这里是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;
                }
            }
        }
    }
}

这样使用:

myReportDocument.ClearReportHeaderAndFooter();