Home Server

Extending Excel Button

edited April 2008 in Server
Hello All, I don't mean to repost but I accidentally posted this as a reply
to a post from many months ago.

I currently have an "excel button" implemented but would like to
extend it somewhat. I have reports that have header and footer bands that
make the reports look good online and as PDFs but make working with the
excel output very tedious. What I would like to accomplish is to either
redirect the excel button to an excel-friendly version of the current
report, forwarding all of the current autosearch values, or to set a boolean
variable or other flag within the report that I can use on
Report.BeforePrint to disable the header and footer bands and move some of
the rows closer together.

Thanks All,
Branden Johnson

Comments

  • edited April 2008

    Simplest solution would be to add some code to the WebModule action handler
    to check the TrsWebRequest.ContentType. When the ContentType is XLS, then
    request a different version of the report, one that has an XLS suffix. The
    server would need to host two versions of the report, for example, myInvoice
    and myInvoiceXLS.

    Something like this...

    procedure TWebModule1.WebModule1waDefaultAction(Sender: TObject; Request:
    TWebRequest; Response: TWebResponse; var Handled: Boolean);
    var
    lWebRequest: TrsWebRequest;
    begin

    {use the incoming request parameters to create a TrsWebRequest}
    lWebRequest := rsWebTier1.CreateWebRequest(Request.QueryFields,
    Request.Content);

    try
    if lWebRequest.ContentType = 'XLS' then
    lWebRequest.ReportName := lWebRequest.ReportName + 'XLS'

    Response.Content := ProcessDefaultRequest(lWebRequest);

    finally
    lWebRequest.Free;
    end;

    end;




    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited April 2008
    Thank you Nard. That is exactly what I was looking for!
  • edited April 2008
    Would there be any way to search for the excel-friendly report and disable
    the excel button if one does not exist, or to only redirect to an
    excel-friendly report if it exists?


  • edited April 2008
    Also, how would I go about changing the file name to include information
    from the report. Currently, my XLS rendered reports are saved as
    report.xls. I would like to include header info that I had to do away with
    like date of printing and customer #.

    Thanks All,
    Brandne Johnson

  • edited April 2008

    Below is an example I created. When a reqest is made for 'xls', it checks
    whether the server contains a special version of the report called
    ReportNameXLS.


    uses
    rsWebRequest,
    rsConnection,
    rsClientReportCatalog,
    rsReportVolumeDirectory;

    procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
    Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
    var
    lWebRequest: TrsWebRequest;
    lsReportName: String;
    lsFormat: string;
    lbReportExists: Boolean;
    begin

    // create a WebRequestObject
    lWebRequest := rsWebTier1.CreateWebRequest(Request.QueryFields,
    Request.Content);

    lsFormat := 'xls';

    // check whether request is for specified format
    if (lWebRequest.ContentType = lsFormat) then
    begin
    lsReportName := lWebRequest.ReportName + lsFormat;

    lbReportExists := CheckReportExists(rsWebTier1.ServerConnection,
    lWebRequest.SessionID, lWebRequest.VolumeName, lsReportName);

    if lbReportExists then
    lWebRequest.ReportName := lsReportName;

    end;


    Response.Content := rsWebTier1.ProcessWebRequest(lWebRequest);

    lWebRequest.Free;

    end;

    function TWebModule1.CheckReportExists(aServerConnection: TrsConnection;
    aSessionID, aVolumeName, aReportName: String): Boolean;
    var
    lReportCatalog: TrsClientReportCatalog;
    lVolumeDirectory: TrsReportVolumeDirectory;
    begin


    // access the report catalog
    lReportCatalog := TrsClientReportCatalog.Create(nil);

    try
    lReportCatalog.ServerConnection := aServerConnection;
    lReportCatalog.SessionID := aSessionID;

    lVolumeDirectory := lReportCatalog.GetVolumeDirectory(aVolumeName);

    Result := (lVolumeDirectory.GetItemNodeForName(aReportName) <> nil);

    finally
    lReportCatalog.Free;

    end;

    end;


    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited April 2008
    Nard, I tried this but I am running into a problem. The default action of
    the webtier is not firing. I have added this code but nothing has changed.
    I added some code to write a text file to see what info was being passed but
    the text file was never generated. I thought maybe the new .dll was not
    being used so I deleted it from the server and the web service no longer
    worked; this confirmed to me that the new .ddl was in fact being used. The
    only thing I could figure was that the default action of the webtier was not
    being used. So I deleted it from the action editor and removed all code
    from the OnAction event, comiled the .dll and put it on the server. This
    ned .dll is being used and is functioning without any problem. I thought
    the Response.Content := RBWebServer.ProcessWebRequest(Request.QueryFields,
    Request.Content) served a purpose but it looks as though it does not. I may
    be way pff base here but I have no clue what is going on.

  • edited April 2008

    As a starting point, try using the WebDebugger app installed to
    RBServer\Demos\WebTier. Get that working. Then add in the custom code and
    test at each step.

    Without a default action firing nothing would ever happen - unless you have
    coded some other actions.

    Without calling WebTier.ProcessWebRequest nothing would ever happen.



    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited April 2008

    Perhaps you can put the description information in the report's title band
    and then generate the information to the xls file.

    Currently there is no way to customize the export file name.


    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited April 2008
    I had forgotten to recycle the application pool so it was still using the
    cached dll. I thought that I was on the wrong train of thought there. The
    code to search for an existing exce-friendly report works brilliantly.
    Thank you very much. I am always amazed by the versatility of Report
    Builder and the support that you give.

This discussion has been closed.