Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export to Excel from Crystal Reports without page headers/footers

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.

I am using crystal reports v9 runtime.

like image 847
chinna Avatar asked Oct 13 '08 05:10

chinna


People also ask

How do I export Crystal Reports to Excel in proper format?

When viewing the Crystal Report in Acctivate, you can select the Export button on the toolbar of the Report window. Click the Format: drop down list and select the Microsoft Excel 97-2000 - Data only (XLS) format. Destination Dropdown should remain set to Disk File. Click OK.

How do I export Crystal reports to Excel with lines and boxes?

Line and boxes are not exported to Excel. So you will need to Right Click the TextBox -> Format Object. In Border tab set the Line Style. Then Report design look like below.


2 Answers

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.

Good luck!

like image 161
Jacob Schoen Avatar answered Oct 05 '22 03:10

Jacob Schoen


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

/// <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();
like image 37
CodingYourLife Avatar answered Oct 05 '22 01:10

CodingYourLife