{"id":13698346,"url":"https://github.com/AntonSikidin/zcl_docx","last_synced_at":"2025-05-04T03:31:22.039Z","repository":{"id":210554887,"uuid":"135445941","full_name":"AntonSikidin/zcl_docx","owner":"AntonSikidin","description":"Best way to create Microsoft Word docx from abap","archived":false,"fork":false,"pushed_at":"2024-01-26T08:20:41.000Z","size":13885,"stargazers_count":41,"open_issues_count":7,"forks_count":14,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T21:51:45.977Z","etag":null,"topics":["abap"],"latest_commit_sha":null,"homepage":"","language":"ABAP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AntonSikidin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-30T13:22:09.000Z","updated_at":"2024-11-25T12:23:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"12f646ab-f398-4240-9655-073d0a240575","html_url":"https://github.com/AntonSikidin/zcl_docx","commit_stats":null,"previous_names":["antonsikidin/zcl_docx"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntonSikidin%2Fzcl_docx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntonSikidin%2Fzcl_docx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntonSikidin%2Fzcl_docx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntonSikidin%2Fzcl_docx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AntonSikidin","download_url":"https://codeload.github.com/AntonSikidin/zcl_docx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252283595,"owners_count":21723505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abap"],"created_at":"2024-08-02T19:00:44.548Z","updated_at":"2025-05-04T03:31:17.023Z","avatar_url":"https://github.com/AntonSikidin.png","language":"ABAP","funding_links":[],"categories":["Categories"],"sub_categories":["🗒️ eMail \u0026 Document Processing"],"readme":"# Best way to create Microsoft Word docx from ABAP.\n\nMaybe, this video instruction explain better than me.\n\nWatch in 1080p.\n\n[![IMAGE ALT TEXT](http://img.youtube.com/vi/iScstHjoQ4U/0.jpg)](http://www.youtube.com/watch?v=iScstHjoQ4U \"Best way to create Microsoft Word docx from ABAP.\")\n\n\nInstallation:\nInstall package via ABAPGIT  https://docs.abapgit.org/guide-install.html\n\n \n![alt_text](images/z002_01.png \"image_tooltip\") \n\n\n \n![alt_text](images/z002_02.png \"image_tooltip\") \n\n \n![alt_text](images/z002_03.png \"image_tooltip\") \n\n \n![alt_text](images/z002_04.png \"image_tooltip\") \n\n\n \n![alt_text](images/z002_05.png \"image_tooltip\") \n\n\nFor example, the following document should be created:\n \n![alt_text](images/z002_06.png \"image_tooltip\") \n\n\nAt first toggle developer toolbar.\nFile -\u003e Options -\u003e Customize ribbon\n\n \n\n![alt_text](images/z002_07.png \"image_tooltip\") \n\nGo to developer tab, turn on “design mode”.\n \n![alt_text](images/z002_08.png \"image_tooltip\") \n\nSelect text that will be replaced.\n \n![alt_text](images/z002_09.png \"image_tooltip\") \n\n Make tag.\n \n![alt_text](images/z002_10.png \"image_tooltip\") \n\n\nClick properties.\n \n![alt_text](images/z002_11.png \"image_tooltip\") \n\n\nEnter tag name.\n\n \n![alt_text](images/z002_12.png \"image_tooltip\") \n\n\n\nRepeat for all variable.\nFor repeated rows or text fragment - select row or text fragment, make repeated control.\n\n\n \n![alt_text](images/z002_13.png \"image_tooltip\") \n\nTo enter properties of repeated control place cursor in the begin or end control.\n\n \n![alt_text](images/z002_14.png \"image_tooltip\") \n\nTag all variables and repeated part.\nSave document. Go to transaction smw0 Select Binary data, enter.\n\n\n \n![alt_text](images/z002_15.png \"image_tooltip\") \n\nObject name zdocx_example\n \n![alt_text](images/z002_16.png \"image_tooltip\") \n\n \n![alt_text](images/z002_17.png \"image_tooltip\") \n\n\n \n![alt_text](images/z002_18.png \"image_tooltip\") \n\n\n \n![alt_text](images/z002_19.png \"image_tooltip\") \n\n\nGo to se38.\nProgram ZDOCX_GET_TYPES.\nNavigate to your template.\n\n \n![alt_text](images/z002_20.png \"image_tooltip\") \n\n\nRun.\nProgram generate data types, based on your document structure.\n\n \n![alt_text](images/z002_21.png \"image_tooltip\") \n\nCopy to your program.\nDefine variable.\n\n```\nData\n: gs_templ_data TYPE t_data\n.\n```\n\nFill structure with your data.\nThen get document.\n\n```\n\nzcl_docx3=\u003eget_document(\n    iv_w3objid    = 'ZDOCX_EXAMLE'   \" name of our template\n*      iv_template   = ''            \" you can feed template as xstring instead of load from smw0\n*      iv_folder     = 'report'      \" in folder by default 'report'\n*      iv_path       = ''            \" IF iv_path IS INITIAL  save on desctop or sap_tmp folder\n*      iv_file_name  = 'report.docx' \" file name by default\n*      iv_no_execute = ''            \" if filled -- just get document no run office\n*      iv_protect    = ''            \" if filled protect document from editing, but not protect from sequence\n                                   \" ctrl+a, ctrl+c, ctrl+n, ctrl+v, edit\n    iv_data       = gs_templ_data  \" root of our data, obligatory\n*      iv_no_save    = ''            \" just get binary data not save on disk\n    ).\n```\n\n \nWhole program “ZDOCX_EXAMPLE”:\n```\n*\u0026---------------------------------------------------------------------*\n*\u0026 Report ZDOCX_EXAMPLE\n*\u0026---------------------------------------------------------------------*\n*\u0026\n*\u0026---------------------------------------------------------------------*\nREPORT zdocx_example.\n\n*describe types\n\nTYPES\n: begin of t_TABLE3\n,       PERSON type string\n,       SALARY type string\n, end of t_TABLE3\n\n, tt_TABLE3 type table of t_TABLE3 with empty key\n\n\n, begin of t_T2\n,       F1 type string\n,       F2 type string\n,       F3 type string\n, end of t_T2\n\n, tt_T2 type table of t_T2 with empty key\n\n\n, begin of t_T1\n,       H1 type string\n, T2 type tt_T2\n, end of t_T1\n\n, tt_T1 type table of t_T1 with empty key\n\n\n, begin of t_LINE1\n,       FIELD1 type string\n,       FIELD2 type string\n,       FIELD3 type string\n,       FIELD4 type string\n, end of t_LINE1\n\n, tt_LINE1 type table of t_LINE1 with empty key\n\n\n, begin of t_TAB1\n,       TITLE1 type string\n, LINE1 type tt_LINE1\n, end of t_TAB1\n\n, tt_TAB1 type table of t_TAB1 with empty key\n\n\n, begin of t_LINE2\n,       FIELD1 type string\n,       FIELD2 type string\n,       FIELD3 type string\n, end of t_LINE2\n\n, tt_LINE2 type table of t_LINE2 with empty key\n\n\n, begin of t_TAB2\n,       TITLE2 type string\n, LINE2 type tt_LINE2\n, end of t_TAB2\n\n, tt_TAB2 type table of t_TAB2 with empty key\n\n\n, begin of t_data\n,       SH01 type string\n,       DATE type string\n,       TIME type string\n,       USER type string\n, TABLE3 type tt_TABLE3\n, T1 type tt_T1\n, TAB1 type tt_TAB1\n, TAB2 type tt_TAB2\n, end of t_data\n\n, tt_data type table of t_data with empty key\n\n\n.\n\n\n\n*some variable\nDATA\n      : gs_templ_data TYPE t_data\n      , lv_index TYPE i\n      , lv_index2 TYPE i\n      , lv_index3 TYPE i\n      .\n\n\n*fill data\n\ngs_templ_data-DATE = |{ sy-datum date = environment }|.\ngs_templ_data-TIME = |{ sy-uzeit   TIME = ENVIRONMENT }|.\ngs_templ_data-USER  = sy-uname.\n\n\n*1.  Lurch Schpellchek: 1200 usd\n*2.  Russell Sprout: 1300 usd\n*3.  Fergus Douchebag: 3000 usd\n*4.  Bartholomew Shoe: 100 usd\n\nAPPEND INITIAL LINE TO gs_templ_data-table3 ASSIGNING FIELD-SYMBOL(\u003cls_3\u003e).\n\u003cls_3\u003e-person = 'Lurch Schpellchek'.\n\u003cls_3\u003e-salary = '1200'.\n\nAPPEND INITIAL LINE TO gs_templ_data-table3 ASSIGNING \u003cls_3\u003e.\n\u003cls_3\u003e-person = 'Russell Sprout'.\n\u003cls_3\u003e-salary = '1300'.\n\nAPPEND INITIAL LINE TO gs_templ_data-table3 ASSIGNING \u003cls_3\u003e.\n\u003cls_3\u003e-person = 'Fergus Douchebag'.\n\u003cls_3\u003e-salary = '3000'.\n\nAPPEND INITIAL LINE TO gs_templ_data-table3 ASSIGNING \u003cls_3\u003e.\n\u003cls_3\u003e-person = 'Bartholomew Shoe'.\n\u003cls_3\u003e-salary = '100'.\n\n\n\ngs_templ_data-sh01 = 'test aaa'.\n\nDO 3 TIMES.\n  lv_index = sy-index.\n\n  APPEND INITIAL LINE TO gs_templ_data-tab1 ASSIGNING FIELD-SYMBOL(\u003cls_tab1\u003e).\n  \u003cls_tab1\u003e-title1 = |table 1 subtable { lv_index }|.\n\n\n  DO 3  TIMES.\n    lv_index2 = sy-index.\n    APPEND INITIAL LINE TO \u003cls_tab1\u003e-line1 ASSIGNING FIELD-SYMBOL(\u003cls_line1\u003e).\n\n    DO 4 TIMES.\n      lv_index3 = sy-index.\n\n      ASSIGN COMPONENT lv_index3 OF STRUCTURE \u003cls_line1\u003e TO FIELD-SYMBOL(\u003cfs_any\u003e).\n\n      \u003cfs_any\u003e = |Line { lv_index2  } field { lv_index3 }|.\n\n    ENDDO.\n\n\n  ENDDO.\n\n\nENDDO.\n\n\nDO 3 TIMES.\n  lv_index = sy-index.\n\n  APPEND INITIAL LINE TO gs_templ_data-tab2 ASSIGNING FIELD-SYMBOL(\u003cls_tab2\u003e).\n  \u003cls_tab2\u003e-title2 = |Table 2 subtable { lv_index }|.\n\n\n  DO 3  TIMES.\n    lv_index2 = sy-index.\n    APPEND INITIAL LINE TO \u003cls_tab2\u003e-line2 ASSIGNING FIELD-SYMBOL(\u003cls_line2\u003e).\n\n    DO 3 TIMES.\n      lv_index3 = sy-index.\n\n      ASSIGN COMPONENT lv_index3 OF STRUCTURE \u003cls_line2\u003e TO \u003cfs_any\u003e.\n\n      \u003cfs_any\u003e = |Line { lv_index2  } field { lv_index3 }|.\n\n    ENDDO.\n\n\n  ENDDO.\n\n\nENDDO.\n\ngs_templ_data = VALUE #( BASE gs_templ_data\n  t1 = VALUE #(\n    ( h1 = |1| t2 = VALUE #(\n        ( f1 = 'F1' f2 = 'F2' f3 = 'f3' )\n        ( f1 = 'F1' f2 = 'F2' f3 = 'f3' )\n      )\n    )\n    ( h1 = |2| t2 = VALUE #(\n        ( f1 = 'F1' f2 = 'F2' f3 = 'f3' )\n        ( f1 = 'F1' f2 = 'F2' f3 = 'f3' )\n        ( f1 = 'F1' f2 = 'F2' f3 = 'f3' )\n      )\n    )\n    ( h1 = |3| t2 = VALUE #(\n        ( f1 = 'F1' f2 = 'F2' f3 = 'f3' )\n        ( f1 = 'F1' f2 = 'F2' f3 = 'f3' )\n        ( f1 = 'F1' f2 = 'F2' f3 = 'f3' )\n        ( f1 = 'F1' f2 = 'F2' f3 = 'f3' )\n      )\n    )\n  )\n).\n\n\n*get document\n\nDATA\n       : lv_document TYPE xstring  \" variable to hold generated document, can be omitted\n       .\n\n*first case:  send document as attachment\n\nlv_document = zcl_docx3=\u003eget_document(\n    iv_w3objid    = 'ZDOCX_EXAMLE'\n    iv_data       = gs_templ_data\n    iv_no_save    = 'X'   ).\n\nPERFORM send_document_as_attachment USING lv_document.\n\n\n\n*second case: save on desctop and open document\n\nzcl_docx3=\u003eget_document(\n    iv_w3objid    = 'ZDOCX_EXAMLE'   \" name of our template\n*      iv_template   = ''            \" you can feed template as xstring instead of load from smw0\n*      iv_on_desktop = 'X'           \" by default save document on desktop\n*      iv_folder     = 'report'      \" in folder by default 'report'\n*      iv_path       = ''            \" IF iv_path IS INITIAL  save on desctop or sap_tmp folder\n*      iv_file_name  = 'report.docx' \" file name by default\n*      iv_no_execute = ''            \" if filled -- just get document no run office\n*      iv_protect    = ''            \" if filled protect document from editing, but not protect from sequence\n                                   \" ctrl+a, ctrl+c, ctrl+n, ctrl+v, edit\n    iv_data       = gs_templ_data  \" root of our data, obligatory\n*      iv_no_save    = ''            \" just get binary data not save on disk\n    ).\n\n\nFORM send_document_as_attachment USING iv_doc TYPE xstring.\n\n*  implement sending here\n  MESSAGE 'Doc sended' TYPE 'S'.\nENDFORM.\n```\n\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAntonSikidin%2Fzcl_docx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAntonSikidin%2Fzcl_docx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAntonSikidin%2Fzcl_docx/lists"}