In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "what are the methods of using ABAP to operate Excel". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
By searching for the keyword OLE in SAPGUI, you can find a way to manipulate Excel through ABAP:
This document makes it clear that Microsoft's Office applications such as Word and Excel provide a so-called automation interface that exposes public class methods and properties that can be consumed by other applications.
As ABAP application developers, we access the automation interfaces of Microsoft Word and Excel by calling OLE object methods CALL METHOD, GET PROPERTY,SET PROPERTY, and so on. The code looks like this:
The above function RH_START_EXCEL_DATA_OLE calls the automation interface of Microsoft Excel, creates a new Excel workbook, and then prepares to write the data in the table in ABAP to Excel.
You may ask, how do I know which public classes and methods in Excel can be called by ABAP?
Right-click in Excel and select View Code:
Open Microsoft Visual Basic Object Brower, and all the available classes and methods are listed here, and the open method of workbook called by line 218 of ABAP code above can also be found in the list.
This solution works only on the windows platform and requires Microsoft's Excel application to be installed on the Presentation Server running SAPGUI.
When we use OLE to operate Excel, when we open the task manager of the Windows operating system, we will find an Excel process started with the / automation-Embedding parameter.
The-Embedding parameter here comes from the full name of OLE: part of Object Linking and Embedding. OLE is a very old technology of Microsoft.
Photos of Microsoft and SAP, Bill Gates and Hasso Plattner in 1993:
That's all we know about OLE,Jerry. In SAP Research, we still deal with Microsoft technologies, such as Microsoft's Azure.
If Jerry is correct, Microsoft Office, starting with version 2007, uses a new format that supports the Office Open XML standard to manage files such as Excel and Word. Jerry was in charge of the CRM Document Builder module at the CRM development team of SAP Chengdu Research Institute in 2014, when he wrote code to manipulate Word documents using ABAP.
Taking Word as an example, the following figure shows the simplest Word document I have created, which contains a Header area, a paragraph of three lines of colored text, and a picture.
Let's change the extension of the Word document from .docx to .zip, then double-click and open it with an unzipped software such as winrar.
It is found that the simplest Word document implemented according to the Office Open XML protocol is actually made up of so many xml and folders.
Read the contents of the Word file using the SAP standard class CL_DOCX_DOCUMENT:
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 this 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 the reference of "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) the binary content of the image inserted in the Word document can also be read out. How to use: lo_image_parts- > get_part returns.
I have not done the example of Excel, but the principle is similar. You can use CL_XLSX_DOCUMENT in S_OOXML_CORE to manipulate Excel documents in xlsx format.
In addition, there is a famous open source project, abap2xlsx, Jerry has not tried, interested friends can try.
Finally, you use the keywords XSLX in SE24 and search for _ OLE in SE38
You can select some points from the search list and refer to how SAP standard procedures manipulate Excel documents.
This is the end of the content of "what are the methods of using ABAP to operate Excel". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.