In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to use ABAP programming to achieve the operation of Microsoft Office Word documents. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
A standard class CL_DOCX_DOCUMENT is provided in SAP ABAP that provides local read and write operations for Microsoft Office word documents ending in ".docx".
Office OpenXML
Starting with Microsoft Office2007, when we created a new word document, the extension changed from ".doc" to ".docx", which is based on an open source specification: Office openXML format.
For example, in the following illustration, I created the simplest word document with a Header area, a paragraph of three lines of colored text, and an image.
Let's save this document locally, change its extension from .docx to .zip, double-click, and open it with an unzipped software such as winrar.
It turns out that the simplest word document is actually made up of so many xml and folders.
Use CL_DOCX_DOCUMENT to read the contents of a word file
The sample code is as follows:
DATA: lv_content TYPE xstring Lo_document TYPE REF TO cl_docx_document.PERFORM get_doc_binary USING 'C:Usersi042416Desktop est.docx' CHANGING lv_content.lo_document = cl_docx_document= > load_document (lv_content). CHECK lo_document IS NOT INITIAL.DATA (lo_core_part) = lo_document- > get_corepropertiespart () .Data (lv_core_data) = lo_core_part- > get_data () .Data (lo_main_part) = lo_document- > get_maindocumentpart (). DATA (lo_image_parts) = lo_main_part- > get_imageparts () .Data (lv_image_count) = lo_image_parts- > get_count (). DO lv_image_count TIMES.DATA (lo_image_part) = lo_image_parts- > get_part (sy-index-1). Data (lv_image_data) = lo_image_part- > get_data () .ENDDO.Data (lo_header_parts) = lo_main_part- > get_headerparts ( ) .Data (lv_header_count) = lo_header_parts- > get_count (). DO lv_header_count TIMES.DATA (lo_header_part) = lo_header_parts- > get_part (sy-index-1). Data (lv_header_data) = lo_header_part- > get_data (). ENDDO. A brief description of the above code
1. Pass the binary content of the word document into the method cl_docx_document= > load_document to get a document object reference, and then you can call various methods with that object reference.
2. The creator, creation time, and last modification time of the word document are all stored in the so-called "Core property part". You can get a reference to "Core property part" through the method lo_document- > get_corepropertiespart, and then use this reference to call the method get_data to get the actual content.
The following figure is an example of the content returned by get_data, which can be seen in xml format.
3. Now we are ready to read the body of the word document. Use the method lo_document- > get_maindocumentpart to get the body of the word document, including the font type and color of the text. As shown in the following figure:
4. Of course, the binary content of the image inserted in the Word document can also be read. How to use: lo_image_parts- > get_part returns.
Similarly, Microsoft Office 2007 and later versions of office documents in other formats, such as Powerpoint and Excel, follow the Office OpenXML standard, so you can also see a large number of xml and folders after changing their suffix to .zip. ABAP also provides standard code to read and write these Office documents, such as CL_PPTX_DOCUMENT, CL_XLSX_DOCUMENT, and so on, as shown in the following figure.
The above is the editor for you to share how to use ABAP programming to achieve the operation of Microsoft Office Word documents, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.