In the previous part, we discussed how to create and modify the XSL Transformation using T code XSLT_TOOL.
Part 1: http://scn.sap.com/people/manikandan.jeyaram/blog/2013/09/11/download-ms-excel-with-formatting-optio...
Now we are going to call this XSLT in our program.
Create a program in SE38 (ZEXCEL_DOWNLOAD). The algorithm of this program is explained below:
- Populate the internal table.
- Pass the internal table contents to the transformation which is created in XSLT_TOOL (Z_EXCEL_DOWNLOAD).
- The output of the transformation will be an XML string. Put this string in an XML table.
- CALL METHOD cl_gui_frontend_services=>file_save_dialog to open the dialog box to identify the location for saving the file.
- Pass the XML table to GUI_DOWNLOAD. The excel sheet gets downloaded in the desired path.
Step 7:
Execute the program.
Save the Excel sheet. Here is the output of this program:
Please note that the conditional formatting is applied only to cell G2. If we want to extend the range for this conditional formatting, we need to make one more adjustment in the XSLT.
As you can see, in the self-generated code, the conditional formatting was applied only to Row 2, Column 7. I have changed the range manually here up to 100 rows. Now the conditional formatting is applied to 100 rows. You can see the excel output below:
Pros:
- Faster download
- Download at one shot
- Minimal coding effort. We use auto-generatedcode and do minimal changes to it.