In July 2010, SAP Mentor Ivan Femia released the first version of the open source project abap2xlsxthat allowed ABAP developers to generate professional spreadsheets from scratch with all theadvanced features that stand alone Excel editorsprovide like: style and cell data formats, drawings support, conditional formatting, formulas, and so on.
This project has improvedthe user experiencecompared toexcelgenerated usingSAP standardcomponents (such as ABAP ALV, WebDynpro ALV, System menu, etc.) and ithas made ABAP developersmore freedomadding, for example, the ability to generatean excel from non dialog processes and to include the generatedexcelas email attachment. At last but not least, this framework allows the use ofspreadsheetsin an interactive way, making possible toread themviaABAPforfurther processing.
Time after time, more and more SDN community members joined into the project and improved its functionalities. The abap2xlsx project reachesalarge number of contributors, so today it is almost timefor the newrelease that will include many new features such as the use of template files for charts, very hidden sheet, many bug fixes and so on. In this blog we will focus on one of the most importantnews: the ability to createcustom chartsfrom scratch!
Yes,that's right:with just a fewsimple ABAP code lines,you can createbusiness graphicswithin theexcel fileand send it, for example, to many iPhone/iPadvia apush notificationor via anhtmlemail (asweekly summary for example).
Another interesting way to use abapxlsx charts is to generate them using abap and then catch them as an image in order to show the chart in a WebDynpro or to send it directly to a mobile device! You believe thatthis is not possible? It is not easy, but you can do it following these steps:
- Generate the excel file with the chart as you wish via ABAP using abap2xlsx
- Add a simple macro to the excel via ABAP using abap2xlsx in order to enable the excel to export the chart in an image file like this:
- Write a simple vbs file via ABAP in order to run the image generation like this:
- Save the excel file and the vbs on the SAP NetWeaver Application Server filesystem via ABAP
* Opening the File
OPEN DATASET lv_filename FOR OUTPUT IN TEXT MODE
MESSAGE lv_msgtxt.
IF SY-SUBRC NE 0.
WRITE: 'File cannot be opened. Reason:', lv_msgtxt.
EXIT.
ENDIF.* Transferring Data
LOOP AT lt_table.
TRANSFER lt_table-line TO FILENAME.
ENDLOOP.* Closing the File
CLOSE DATASET lv_filename. Run the saved VBScript file via ABAP
v_command = 'cscript.exe test.vbs'.
CALL 'SYSTEM' ID 'COMMAND' FIELD v_command.
The chart image has been generated! Get it from the Application Server filesystem via ABAP and display or send it!