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.
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.
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.
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!
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With