XLSReport Hide headers and footers

edited February 2013 in Devices
Using XE2 with RB 14.08

I'm trying to hide the header band when the user exports the report to Excel
to the don't have to deal with the column headings, etc.
The code below doesn't work because the DeviceType is never set to
XLSReport. Is there another way to do this?

procedure TfrmPHHISTRS.rptPHHISTRFADHeaderBandBeforePrint(Sender: TObject);
begin
inherited;
if (uppercase(rptPHHISTRFAD.DeviceType) = 'XLSREPORT')
and (rptPHHISTRFAD.AbsolutePageNo <> 1) then
rptPHHISTRFADHeaderBand.Visible:=False
else
rptPHHISTRFADHeaderBand.Visible:=True;
end;

Thanks,
Perry Jacobs

Comments

  • edited February 2013
    Hi Perry,

    The DeviceType is not updated by the print dialog. Try using the
    Report.FileDevice property instead. Also, the Band.BeforePrint event
    fires too late to hide the entire band. Try using the StartPage or
    FileDeviceCreate event.

    uses
    ppXLSDevice;

    procedure TForm1.ppReport1StartPage(Sender: TObject);
    begin
    if (ppReport1.FileDevice <> nil) and (ppReport1.FileDevice is
    TppXLSReportDevice) then
    ppReport1.HeaderBand.Visible := False
    else
    ppReport1.HeaderBand.Visible := True;
    end;

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2013
    That work great!

    Here is the final code. I was pleasantly suprised when Sender worked in the
    StartPage event to make this a generic function.

    if (TppReport(Sender).FileDevice <> nil)
    and (TppReport(Sender).FileDevice is TppXLSReportDevice) then
    begin
    TppReport(Sender).Footer.Visible:=False;
    if (TppReport(Sender).AbsolutePageNo <> 1) then
    TppReport(Sender).Header.Visible:=False
    else
    TppReport(Sender).Header.Visible:=True;
    end
    else
    begin
    TppReport(Sender).Header.Visible:=True;
    TppReport(Sender).Footer.Visible:=True;
    end;

    Another piece that I needed was
    TppReport(Sender).CachePages:=False;
    This is because I made a button in the Preview Form and this forces the
    report to regenerate with the new device (I'm guessing).

    Are there any plans to add Header and Footer to the list of
    XLSSettings.ExportComponents option?

    Thanks,
    Perry Jacobs

  • edited February 2013
    I found a problem with this that also happened when I used Waler ExtraDev
    Excel device. When I generate the XLSReport from the Preview window, it
    duplicates the 4-5 lines that would have been at the bottom of each page.
    When I generate the XLSReport directly from Report.Print then the lines are
    not duplicated. I tried doing a Viewer.Report.Reset but no luck.

    TppReport(Viewer.Report).Reset;
    TppReport(Viewer.Report).CachePages:=False;
    Viewer.Report.DeviceType:=dtXLSReport;
    Viewer.Report.TextFileName:=strFileName;
    Viewer.Report.ShowPrintDialog:=False;
    Viewer.Report.ShowCancelDialog:=False;
    Viewer.Report.XLSSettings.MergeAdjacentCells:=False;
    Viewer.Report.XLSSettings.ScaleToPageWidth:=True;
    Viewer.Report.XLSSettings.ExportComponents:=[ecText,ecImage,ecRichText,ecBarCode,ecOther];
    Viewer.Report.Print;

    Thanks,
    Perry
  • edited February 2013
    Hi Perry,

    Please create a minimal example of this and send it in .zip format to
    support@digital-metaphors.com and we'll take a look at it for you.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.