diff --git a/docs/FAQ.md b/docs/FAQ.md index 057b38e..539a3a0 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -22,11 +22,6 @@ Implement SAP OSS Notes: [Note 1385713 - SUBMIT: Allowing parameter of type STRING](https://service.sap.com/sap/support/notes/1385713) -* Macro-Enabled workbook - -Run report ZDEMO_EXCEL29 and use as VBA source file [TestMacro.xlsm](https://github.com/abap2xlsx/abap2xlsx/blob/master/resources/TestMacro.xlsm) attached. -Basically abap2xlsx works using an existing VBA binary (we do not want to create a VBA editor). - * Download XLSX files in Background Run report ZDEMO_EXCEL25. diff --git a/resources/TestMacro.xlsm b/resources/TestMacro.xlsm deleted file mode 100644 index 461bed8..0000000 Binary files a/resources/TestMacro.xlsm and /dev/null differ diff --git a/src/demos/zdemo_excel29.prog.abap b/src/demos/zdemo_excel29.prog.abap index fe9e8c9..c5a092d 100644 --- a/src/demos/zdemo_excel29.prog.abap +++ b/src/demos/zdemo_excel29.prog.abap @@ -1,5 +1,5 @@ *&---------------------------------------------------------------------* -*& Report ZDEMO_EXCEL26 +*& Report ZDEMO_EXCEL29 *& *&---------------------------------------------------------------------* *& @@ -19,18 +19,35 @@ DATA: lv_file TYPE xstring, DATA: lv_full_path TYPE string, lv_filename TYPE string, lv_workdir TYPE string. +DATA: lv_separator TYPE c LENGTH 1. -PARAMETERS: p_path TYPE zexcel_export_dir OBLIGATORY. +SELECTION-SCREEN COMMENT /1(83) p_text1. +SELECTION-SCREEN COMMENT /1(83) p_text2. +SELECTION-SCREEN SKIP 1. + +PARAMETERS: p_smw0 RADIOBUTTON GROUP rad1 DEFAULT 'X'. +PARAMETERS: p_objid TYPE w3objid OBLIGATORY DEFAULT 'ZDEMO_EXCEL29_INPUT'. + +PARAMETERS: p_file RADIOBUTTON GROUP rad1. +PARAMETERS: p_path TYPE zexcel_export_dir. + +LOAD-OF-PROGRAM. + p_text1 = 'abap2xlsx works with VBA macro by using an existing VBA binary.'. + p_text2 = '(we do not want to create a VBA editor).'. + +AT SELECTION-SCREEN OUTPUT. + IF p_path IS INITIAL. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_separator ). + p_path = lv_workdir && lv_separator && 'TestMacro.xlsm'. + ENDIF. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. DATA: lt_filetable TYPE filetable, lv_rc TYPE i. - cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). - cl_gui_cfw=>flush( ). - p_path = lv_workdir. - CALL METHOD cl_gui_frontend_services=>file_open_dialog EXPORTING window_title = 'Select Macro-Enabled Workbook template' @@ -59,7 +76,12 @@ START-OF-SELECTION. CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_xlsm. CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_xlsm. - lo_excel = lo_excel_reader->load_file( lv_full_path ). +* load template + IF p_file IS NOT INITIAL. + lo_excel = lo_excel_reader->load_file( lv_full_path ). + ELSE. + PERFORM load_smw0 USING lo_excel_reader p_objid CHANGING lo_excel. + ENDIF. lv_file = lo_excel_writer->write_file( lo_excel ). REPLACE '.xlsm' IN lv_full_path WITH 'FromReader.xlsm'. @@ -77,3 +99,65 @@ START-OF-SELECTION. filename = lv_full_path filetype = 'BIN' CHANGING data_tab = lt_file_tab ). + +FORM load_smw0 + USING + io_reader TYPE REF TO zif_excel_reader + iv_w3objid TYPE w3objid + CHANGING + ro_excel TYPE REF TO zcl_excel + RAISING + zcx_excel. + + DATA: lv_excel_data TYPE xstring, + lt_mime TYPE TABLE OF w3mime, + ls_key TYPE wwwdatatab, + lv_errormessage TYPE string, + lv_filesize TYPE i, + lv_filesizec TYPE c LENGTH 10. + +*--------------------------------------------------------------------* +* Read file into binary string +*--------------------------------------------------------------------* + + ls_key-relid = 'MI'. + ls_key-objid = iv_w3objid . + + CALL FUNCTION 'WWWDATA_IMPORT' + EXPORTING + key = ls_key + TABLES + mime = lt_mime + EXCEPTIONS + OTHERS = 1. + IF sy-subrc <> 0. + lv_errormessage = 'A problem occured when reading the MIME object'(004). + zcx_excel=>raise_text( lv_errormessage ). + ENDIF. + + CALL FUNCTION 'WWWPARAMS_READ' + EXPORTING + relid = ls_key-relid + objid = ls_key-objid + name = 'filesize' + IMPORTING + value = lv_filesizec. + + lv_filesize = lv_filesizec. + CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' + EXPORTING + input_length = lv_filesize + IMPORTING + buffer = lv_excel_data + TABLES + binary_tab = lt_mime + EXCEPTIONS + failed = 1 + OTHERS = 2. + +*--------------------------------------------------------------------* +* Parse Excel data into ZCL_EXCEL object from binary string +*--------------------------------------------------------------------* + ro_excel = io_reader->load( i_excel2007 = lv_excel_data ). + +ENDFORM. diff --git a/src/demos/zdemo_excel29.prog.xml b/src/demos/zdemo_excel29.prog.xml index 5bc8a56..70525a5 100644 --- a/src/demos/zdemo_excel29.prog.xml +++ b/src/demos/zdemo_excel29.prog.xml @@ -13,15 +13,33 @@ R - abap2xlsx Demo: Marco-Enabled workbook + abap2xlsx Demo: Macro-Enabled workbook 38 + + S + P_FILE + Load template from file + 31 + + + S + P_OBJID + Object ID + 17 + S P_PATH Macro-enabled Workbook 30 + + S + P_SMW0 + Load template from SMW0 + 31 + diff --git a/src/demos/zdemo_excel29_input.w3mi.data.xlsm b/src/demos/zdemo_excel29_input.w3mi.data.xlsm new file mode 100644 index 0000000..f435f3b Binary files /dev/null and b/src/demos/zdemo_excel29_input.w3mi.data.xlsm differ diff --git a/src/demos/zdemo_excel29_input.w3mi.xml b/src/demos/zdemo_excel29_input.w3mi.xml new file mode 100644 index 0000000..ea3cc3b --- /dev/null +++ b/src/demos/zdemo_excel29_input.w3mi.xml @@ -0,0 +1,29 @@ + + + + + ZDEMO_EXCEL29_INPUT + abap2xlsx resources/TestMacro.xlsm + + + MI + ZDEMO_EXCEL29_INPUT + fileextension + .xlsm + + + MI + ZDEMO_EXCEL29_INPUT + filename + TestMacro.xlsm + + + MI + ZDEMO_EXCEL29_INPUT + mimetype + application/vnd.ms-excel.sheet.macroEnabled + + + + +