How to export reports to Excel, CSV, PDF with SAP Analytics Designer
In this blog we will be discussing how to export data in the widgets within the analytics application to Excel, CSV, and PDF. This method is the easiest and simplest to apply, and in a subsequent blog we will be discussing an advanced method of exporting to Excel, CSV and PDF that provides further options to end users to configure the content of the output.
For now, lets get started with this easy and quick way to configure our exports.
The first step is to configure the Export to Excel, Export to CSV, and Export to PDF in Scripting before writing Java script
Then we configure the Properties for each of the export Scripting settings.
The below snippet is for the Export to Excel Properties. We name it ExportToExcel to use in java script later, designate an Exported File Name, in our case it is InsightCubes_Excel, then decide if we want to turn on the optionality to Include Metadata, Include Number Formatting, and Keep Hierarchy Indentation.
We also need to select the Included Widgets in the Exported Excel file. In the snippet below we have one widget selected (Table).
Now we will add the Java script to the Export to Excel button on click event.
The below onclick event java script for Export to Excel starts by closing the menu (Line 1), then setting the export to excel widget (Line 2) and populating a local variable member with the entered text in the input field named InputField_ExportExcelOptions_FileName (Line 3). Incase the user did not enter any text in the input field (Line 4), we populate a fixed text named InsightCubes (Line 5), otherwise if the user entered a text (Line 6), we set the file name as entered by the user and stored by the local variable called FileName (Line 7).
Last, the export to Excel is executed (Line 9), and an Application Message of Type Success is shown to the user (Line 10).
The below snippet is for the Export to CSV Properties. We name it ExportToCSV to use in java script later. Select the data source for the exported CSV file, in our case it is the widget (Table). Designate an Exported File Name, in our case it is InsightCubes_CSV, then decide if we want to turn on the optionality to Include Number Formatting. Selecting the Scope either as a Point of View or All and whether to Flatten Data Hierarchy or not.
Now we will add the Java script to the Export to CSV button on click event.
The below onclick event java script for Export to CSV starts by closing the menu (Line 1), then setting the export to CSV widget (Line 2) and populating a local variable member with the entered text in the input field named InputField_ExportCSVOptions_FileName (Line 3). Incase the user did not enter any text in the input field (Line 4), we populate a fixed text named InsightCubes (Line 5), otherwise if the user entered a text (Line 6), we set the file name as entered by the user and stored by the local variable called FileName (Line 7).
Last, the export to CSV is executed (Line 9), and an Application Message of Type Success is shown to the user (Line 10).
The below snippet is for the Export to PDF Properties. We name it ExportToPDF to use in java script later. Chose the desired General Settings. In our case Orientation is Landscape, Paper Size is A4, Page Number Location is set to None, Exported File Name is InsightCubes_PDF. We have Enable export in the background checked, and the Display fully the exported widgets unchecked, this option enables printing the dashboard as a report (note only Tables are currently supported). Then we detail our Header Settings, Footer Settings, Appendix Settings and Comment Settings.
We also need to select the widgets included in the Export to PDF. The Included Widgets for the Export to PDF Properties has a different approach than Export to Excel and CSV. You can select the specific details you want to show in the PDF, in our case we have all elements in the widgets selected.
Now we will add the Java script to the Export to PDF button on click event.
The below onclick event java script for Export to PDF starts by closing the menu (Line 1), then we set a condition as to whether the user clicked on Switch_FullTable or not, which in turn returns whether the export of all included tables in full length (report) is enabled when the analytic application is exported to a PDF file (Line 2 to 6). Then populating a local variable member with the entered text in the input field named Side_Export_PDF_FileName (Line 8). Incase the user did not enter any text in the input field (Line 9), we populate a fixed text named InsightCubes (Line 10), otherwise if the user entered a text (Line 11), we set the file name as entered by the user and stored by the local variable called FileName (Line 12).
Last, the export to PDF is executed (Line 15), and an Application Message of Type Success is shown to the user (Line 16).