Thursday, February 28, 2008
OLE AUTOMATION IN ABAP PART 3
In this post we will see the Color code for Excel Cells by using SAP OLE.
Color code for ABAP is shown below, please use the numeric value as given in the figure below. For example if you want the interior color of the Excel cell to be of the color Cyan then use the code 8.
OLE AUTOMATION IN ABAP PART 2
DownLoad PDF
The following ABAP key words control the applications:
CREATE OBJECT
SET PROPERTY
GET PROPERTY
CALL METHOD
FREE OBJECT
The Desktop application serves as the OLE server to the calling ABAP program. For example when the ABAP program makes calls to the OLE application the SAPGUI servers as the client.
The create statement generates the object of this class. The following return code values can be encountered.
SY-SUBRC = 0:
Object successfully generated.
SY-SUBRC = 1:
SAPGUI communication error.
SY-SUBRC = 2:
SAPGUI function call error. The frontend ports of SAP’s OLE implementation modules
are implemented only under Windows and Apple Macintosh.
SY-SUBRC = 3:
The OLE-API call resulted in an error - possibly a storage space problem.
SY-SUBRC = 4:
The object is not registered with SAP.
Note that for each OLE object there has to be a variable holding handle data for that object. The type-pool “ole2” defines the handle variable data of the type ole2_object. For all the OLE automation programs “OLE2INCL” include should be used.
Please find below some examples of setting the properties of fonts, cell borders and colors.
Font Properties.
SET PROPERTY OF name_font 'Name' = 'Times New Roman' .
SET PROPERTY OF size_font 'Size' = '12' .
SET PROPERTY OF bold_font 'Bold' = '0' . "Not bold
SET PROPERTY OF Italic_font 'Italic' = '0' . "Not Italic
SET PROPERTY OF underline_font 'Underline' = '0' . "Not underlined
Paragraph Formatting
SET PROPERTY OF allignment_parformat 'Alignment' = '3' . "Justified
Similarly for EXCEL
DATA: d_excel TYPE ole2_object ,
d_cell1 TYPE ole2_object ,
d_cell2 TYPE ole2_object ,
d_cells TYPE ole2_object ,
d_range TYPE ole2_object ,
d_font TYPE ole2_object ,
d_interior TYPE ole2_object ,
d_columns TYPE ole2_object ,
d_charts TYPE ole2_object ,
d_chart TYPE ole2_object ,
d_charttitle TYPE ole2_object ,
d_charttitlech TYPE ole2_object ,
d_chartob TYPE ole2_object .
Sample code
CREATE OBJECT d_excel 'EXCEL.APPLICATION' .
SET PROPERTY OF d_excel 'Visible' = 1 .
GET PROPERTY OF d_excel 'Workbooks' = gs_wbooklist .
Formatting the Excel Cells
GET PROPERTY OF d_cell1 'Font' = d_font .
SET PROPERTY OF d_font 'Underline' = 2 .
SET PROPERTY OF d_font 'Bold' = 1 .
SET PROPERTY OF d_cell1 'HorizontalAlignment' = -4108 .
GET PROPERTY OF d_cell1 'Interior' = d_interior .
SET PROPERTY OF d_interior 'ColorIndex' = 15 . >>>>>>>>>> Check Ole Automation part 3
SET PROPERTY OF d_interior 'Pattern' = -4124 .
SET PROPERTY OF d_interior 'PatternColorIndex' = -4105 .
Folor Color Code
ABAP TIPS
|
Always use Pretty Printer and Extended Program Check before releasing the code. Do not leave unused code in the program. Comment the code thoroughly. Align the comments and the Code. Follow the SAP Standards and SAP Best Practices guidelines. It’s a good practice to take a dump of the code on your local drive. |