How can I get an ABAP program displaying Excel data to wrap text?

How can I get an ABAP program displaying Excel data to wrap text?

I am developing an SAP ABAP program (using an SAP R/3 4.7 system), in which I want to display details from a database table in Mircrosoft Excel.

Looking at the various demo programs that SAP has provided, I found one that seems to meet my needs. This program (saprdemo_tables_in_excel) allows you to load data from internal tables into a worksheet (shown in-place in the program's screen) and also allows the program to extract the data from the worksheet so that the internal tables can be updated. This program makes use of Desktop Office Integration and is quite easy to follow and understand.

I've created my own program based on the SAP program and have been able to develop it so that it meets my needs. However, there is one requirement (probably the main requirement) that I've found I can't satisfy.

I need some of the cells to have the "Wrap Text" option enabled but cannot see how to do that. None of the methods from the I_OI_SPREADSHEET interface allow me to change this. There are methods that allow me to change the font size and color and background color, as well as properties such as Bold, Italic and Justified, but nothing that relates to the Wrap Text option.

I've been able to find information that seems to indicate that the Wrap Text property can be set if the program was written around OLE2 objects such as with the following code:

 

CREATE OBJECT o_wks 'Excel.Application' NO FLUSH. GET PROPERTY OF o_wks 'Range' = o_rng1 NO FLUSH exporting #1 = 'D:D'. SET PROPERTY OF o_rng1 'WrapText' = '1'.

    Requires Free Membership to View

    When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSAP.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSAP.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

However, since I am using the I_OI_SPREADSHEET interface, I'm struggling to see how I can make use of this approach. Is there some way that I can set the Wrap Text property of a cell in my program given that it is based around the saprdemo_tables_in_excel program?

Rather than create a new Excel workbook directly, have this read in a template workbook, with an embedded macro to set the Wrap Text property. Add your data to this template and run the macro. Then use Save As to make your new document. I've often used this technique for problematic OLE programming -- it's a lot easier to write a macro.

This was first published in May 2009