Bearbeiten

Freigeben über


TestRequestPage.SaveAsExcel(Text) Method

Version: Available or changed with runtime version 1.0.

Saves a report as a Microsoft Excel (.xls) file.

Note

This method is supported only in Business Central on-premises.

Syntax

 TestRequestPage.SaveAsExcel(FileName: Text)

Parameters

TestRequestPage
 Type: TestRequestPage
An instance of the TestRequestPage data type.

FileName
 Type: Text
The path and file name to which the report is saved. The file name extension should be .xls.

Remarks

All filters and options that have been set on the TestRequestPage are respected in the saved report.

After you run this method, you cannot continue to interact with the TestRequestPage. If you want to continue to use the TestRequestPage variable, you must run a report again.

Example

The following example shows the code for a test method to run a report and a request page handler method to test the request page. This example requires that you create the following:

  • A test codeunit called SaveAsExcel.
  • A test method in the test codeunit called TestSaveAsExcel.
  • A handler method of type RequestPageHandler called ReqPageHandler. This handler method has one parameter called RequestPage of Type TestRequestPage and Subtype Customer – Top 10 List. The RequestPage parameter is specified as VAR and is passed by reference to the handler method.
var
    Filename: Text;
begin
    //Test method: TestSaveAsExcel  
    Filename := TemporaryPath + 'MyRep.xls';  
    Message(Filename);  
    if not File.Erase(Filename) then  
      Error('Cannot erase %1',Filename);  
    Report.Run(111);  
    if not File.Exists(Filename) then  
      Error('File should exist!');  
      
    //Request Page Handler method  
    RequestPage.Customer.SetFilter("No.", '20000');  
    RequestPage.ChartType.Value('Pie chart');  
    RequestPage.SaveAsExcel(Filename);  
end;
  

TestRequestPage Data Type
Get Started with AL
Developing Extensions