Skip to Content
Author's profile photo Zafer Onbaş

ABAP OLE2 Object Utility Class

OLE2Object – ABAP OLE2 Object Utility Class

As we all know, sometimes comprehensive dynamic Excel automation developments can be a little bit complicated with OLE2_OBJECT methods. You have to record a macro and find out what’s going on in VBA (Visual Basic for Applications) codes for each specific process, if you don’t know it backwards .)

Hence, about a year ago I wrote a simple utility class for mostly needed common processes (e.g. set/get values, formatting options etc.) in Excel automation. You can simply create a new Excel sheet or open an existing one and manipulate it as you want.

You can just copy and paste the code in “Source Code-Based” class builder editor of a global usual ABAP Class.

Source code on GitHub:
https://goo.gl/axI0qO
(Fork me on GitHub if you want to contribute)

Originally published at – ABAP OLE2 Object Utility Class

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Zafer,

      Thanks for the wonderful blog.

      I have copied the code and tested. It is working fine and generating an excel file in ".XLS" format. So my question is: Can we create an excel file with ".XLSX" format uisng OLE2? if so please guide me to achieve that.

      Thanks,

      Shashi

       

       

      Author's profile photo Zafer Onbaş
      Zafer Onbaş
      Blog Post Author

      Hi Shashi,

      I'm glad you like it. Sure we can create it with "XLSX" format. Actually it's a better practise .) so I've just committed the change in GitHub for Excel create and open modes.

      Thanks,
      Zafer

      Author's profile photo Paul Hardy
      Paul Hardy

      I would suggest doing as Google search on ABAP2XLSX.

      Every few months someone comes up with a new way to export SAP data to Excel, but in my opinion ABAP2XLSX takes some beating.

       

      Author's profile photo Zafer Onbaş
      Zafer Onbaş
      Blog Post Author

      Hi Paul,

      I knew "ABAP2XLSX" before I wrote my own class. I think, it's a perfect tool for advanced level apps, but so detailed for basic and ITM Excel manipulations.You should use STMS or SAPLink to install dozens of Classes, DDIC Objects etc. to your system even though you don't need them. It's more trouble than it's worth if you just develop an app that I mentioned above.

      Thanks,
      Zafer

      Author's profile photo Maria Leousi
      Maria Leousi

      hi,

      Congrats for the blog. It is very helpful.

      I have used the "ole2_object " to create and format an excel file. The program is 100% functional when I access it via SAPLogon. However when the business users access it through Fiori it doesn't work.

      The problem is probable caused because the excel file is exported locally (path: C:/....) in my PC through SAPLogon via the use of the excel application which is available,

      " CREATE OBJECT application 'Excel.Application'."

      whereas the excel is exported in SAP (path: z:/...) through Fiori. In sap server there is no excel application installed.

      Is there any solution for this issue?

      Thanks and regards,

      Maria L.

       

       

      Author's profile photo Zafer Onbaş
      Zafer Onbaş
      Blog Post Author

      Hi Maria,

      AFAIK, OLE2 Automation object requires a front-end session to get its work done. Because Fiori/WebGUI apps are stateless (working externally), you can't use OLE2 Automation from web browser (in case of Creation/Upload etc.). Instead you can use xml based ABAP2XLSX for your case.

      Thanks,
      Zafer

       

      Author's profile photo Maria Leousi
      Maria Leousi

      The ABAP2XLSX works. Thanks!