Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

OLE excel

Former Member
0 Likes
2,139

Hello all,

1.

I shoud output a excel file using ABAP development. And my excel file is very complex, it have some fixed headers. i am new to ole excel, so who can give me some examples or some useful website. then i can learn how to do it ?

2.

anther question: in which situation, i can't output a excel file? pls tell me asap.

Thanks in advance.

Hello all,

1.

I shoud output a excel file using ABAP development. And my excel file is very complex, it have some fixed headers. i am new to ole excel, so who can give me some examples or some useful website. then i can learn how to do it ?

2.

anther question: in which situation, i can't output a excel file? pls tell me asap.

Thanks in advance.

3 REPLIES 3
Read only

former_member194669
Active Contributor
0 Likes
958

Hi,


You find SAP OLE programs under development Class 'SOLE'             

  MSTAPPL  Table Maintenance APPL                                     
  RSOLEDOC Document list                                              
  RSOLEIN0 OLE Load Type Information                                  
  RSOLEINT Type Info Loaded                                           
  RSOLETI0 OLE Object Browser                                         
  RSOLETI1 OLE Object Browser                                         
  RSOLETI2 OLE Object Browser                                         
  RSOLETI3 F4 Help For OLE Objects                                    
  RSOLETT1 OLE 2.0 Automation Demo Program                                                                                
Transactions:                                                        
 SOLE                                                                 
 SOLO  - List of OLE applcations with loaded type info   

2. OLE will work only on Presentation server. that means
you cannot able to download your file to Appl server.

aRs

Read only

former_member189059
Active Contributor
0 Likes
958

Hello Ming,

Try this program... i have used lots of excel formatting in it.. revert back incase you need help


*&---------------------------------------------------------------------*
*& Report  ZKRIS_OLE2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zkris_ole2.

TYPE-POOLS ole2 .
DATA:  count TYPE i,
       application TYPE ole2_object,
       workbook TYPE ole2_object,
       excel     TYPE ole2_object,
       sheet TYPE ole2_object,
       cells TYPE ole2_object.
CONSTANTS: row_max TYPE i VALUE 256.
DATA index TYPE i.


DATA:
      h_cell        TYPE ole2_object,        " cell
      h_f           TYPE ole2_object,        " font
      h_range       TYPE ole2_object,
      h_range2      TYPE ole2_object,
      h_merge       TYPE ole2_object,
      h_int         TYPE ole2_object,
      h_int2         TYPE ole2_object,
      h_width       TYPE ole2_object,
      h_columns     TYPE ole2_object,
      h_rows        TYPE ole2_object,
      h_actwindow   TYPE ole2_object,
      h_select      TYPE ole2_object,
      h_select2     TYPE ole2_object,
      h_hyperlink   TYPE ole2_object,
      h_addhyper    TYPE ole2_object,
      h_borderstop  TYPE ole2_object,
      h_entirecol   TYPE ole2_object.
.

CREATE OBJECT excel 'EXCEL.APPLICATION'.

IF sy-subrc NE 0.
  WRITE: / 'No EXCEL creation possible'.
  STOP.
ENDIF.

SET PROPERTY OF excel 'DisplayAlerts' = 0.

CALL METHOD OF excel 'WORKBOOKS' = workbook .

SET PROPERTY OF excel 'VISIBLE' = 1.


* creating workbook
SET PROPERTY OF excel 'SheetsInNewWorkbook' = 1.
CALL METHOD OF workbook 'ADD'.

CALL METHOD OF excel 'WORKSHEETS' = sheet.
CALL METHOD OF sheet 'ADD'.
FREE OBJECT sheet.

CALL METHOD OF excel 'WORKSHEETS' = sheet
  EXPORTING
    #1 = 1.

SET PROPERTY OF sheet 'NAME' = 'Company Codes'.
CALL METHOD OF sheet 'ACTIVATE'.

DATA: col TYPE i VALUE 1,
row TYPE i VALUE 2,
col1 TYPE i VALUE 2,
col_real TYPE i VALUE 1.


  index = row_max * ( row - 2 ) + 1.
  CALL METHOD OF sheet 'Cells' = cells
    EXPORTING
      #1 = index.
  SET PROPERTY OF cells 'Value' = 'thsi is some larger amount of data blahhhh'.

CALL METHOD OF excel 'Rows' = h_rows
  EXPORTING
    #1 = '1:1'.
  SET PROPERTY OF h_rows 'WrapText' = 1.


DO 5 TIMES.

  index = row_max * ( row - 1 ) + col.
  CALL METHOD OF sheet 'Cells' = cells
    EXPORTING
      #1 = index.
*  SET PROPERTY OF cells 'Value' = '=TRIM("1234     2")'.
  SET PROPERTY OF cells 'Value' = 'thsi is some large data'.


  CALL METHOD OF excel 'Cells' = h_cell
    EXPORTING
      #1 = row
      #2 = col.

  SET PROPERTY OF h_cell  'Align' = 'Center'.

  GET PROPERTY OF h_cell 'Interior'   = h_int.
*  SET PROPERTY OF h_int  'ColorIndex' = col_real .
  GET PROPERTY OF h_cell 'Font'    = h_f.
*  SET PROPERTY OF h_f 'ColorIndex' = 1.

get property of h_cell 'Borders' = h_borderstop.
set property of h_borderstop 'LineStyle' = 1.
set property of h_borderstop 'Weight' = 2.

  SET PROPERTY OF h_f 'Bold' = 1.                    "bold
  SET PROPERTY OF h_cell 'HorizontalAlignment' = 2.  "left align
  SET PROPERTY OF h_cell 'Orientation' = 45.         "angled

  col = col + 1.
  col_real = col_real + 1.
  IF col = 16.
    col = 1.
    row = row + 1.
  ENDIF.
  col1 = col_real + 1.
ENDDO.

index = row_max * ( 10 - 1 ) + 1.
CALL METHOD OF sheet 'Cells' = cells
  EXPORTING
    #1 = index.
SET PROPERTY OF cells 'Value' = '123'.

CALL METHOD OF excel 'Cells' = h_cell
  EXPORTING
    #1 = 10
    #2 = 1.


GET PROPERTY OF h_cell 'Interior'   = h_int.
SET PROPERTY OF h_int  'ColorIndex' = 4 .



*range
CALL METHOD OF excel 'Range' = h_range
  EXPORTING
    #1 = 'A10'
    #2 = 'K10'.

CALL METHOD OF h_range 'Merge' = h_merge .


* width or autofit
CALL METHOD OF excel 'Columns' = h_columns
  EXPORTING
    #1 = 'A:E'.
*
*SET PROPERTY OF h_columns 'ColumnWidth' = 17.
GET PROPERTY OF h_columns 'EntireColumn' = h_entirecol.
set property of h_entirecol 'Autofit' = 1.


* hyperlink

** simple method
*get property of sheet 'Hyperlinks' = h_hyperlink.
*call method of h_hyperlink 'Add' = h_addhyper
*  exporting
*  #1 = h_range
*  #3 = '#Sheet1!A1'.

index = row_max * ( 12 ) + 1.
CALL METHOD OF sheet 'Cells' = cells
  EXPORTING
    #1 = index.
SET PROPERTY OF cells 'Value' = 'test data'.

GET PROPERTY OF sheet 'Hyperlinks' = h_hyperlink.
CALL METHOD OF h_hyperlink 'Add' = h_addhyper
  EXPORTING
    #1 = cells
    #3 = '#Sheet1!A1'.


* borders
CALL METHOD OF excel 'Range' = h_range2
  EXPORTING
    #1 = 'A5'
    #2 = 'L28'.
GET PROPERTY OF h_range2 'Select' = h_select2.

*CALL METHOD OF h_hyperlink 'Add' = h_addhyper
*  EXPORTING
*    #1 = h_range2
*    #3 = '#Sheet1!A1'.
*
  GET PROPERTY OF h_select2 'Interior'   = h_int2.
  SET PROPERTY OF h_int2  'ColorIndex' = 6 .

get property of h_range2 'Borders' = h_borderstop.
set property of h_borderstop 'LineStyle' = 1.
set property of h_borderstop 'Weight' = 2.


* freeze panes
CALL METHOD OF excel 'Rows' = h_rows
  EXPORTING
    #1 = '3:3'.

GET PROPERTY OF h_rows 'Select' = h_select.

GET PROPERTY OF excel 'ActiveWindow' = h_actwindow.
SET PROPERTY OF h_actwindow 'FreezePanes' = 1.

Read only

former_member189059
Active Contributor
0 Likes
958

Problems with OLE

1. You must run it on the presentation server

2. You cannot run it in the background

3. Even for sending a simple internal table, lots of coding is required