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

List in Excel

Former Member
0 Likes
614

Hi all,

Can any one tell me the function module to display

my output list in Excel.

and

How can i set the path for excel sheet globally.i.e.,where ever may be the excel sheet but the

data should get into that.

Thanks,

-Reddy.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
582

Hi,

check this sample code...

REPORT  ZTEST_EXCEL                   .

 

INCLUDE ole2incl.

DATA: application TYPE ole2_object,

       workbook TYPE ole2_object,

       sheet TYPE ole2_object,

       cells TYPE ole2_object.

CONSTANTS: row_max TYPE i VALUE 256.

DATA index TYPE i.

 

DATA: BEGIN OF itab1 OCCURS 0,

 first_name(10),

 last_name(10),

 END OF itab1.

 

 

START-OF-SELECTION.
 itab1-first_name = '123445'.
 itab1-last_name = 'tesst'.
 append itab1.
 clear itab1.

 

 itab1-first_name = '123446'.
 itab1-last_name = 'tesst'.
 append itab1.
 clear itab1.

 

  CREATE OBJECT application 'excel.application'.
  SET PROPERTY OF application 'visible' = 1.
  CALL METHOD OF application 'Workbooks' = workbook.
  CALL METHOD OF workbook 'Add'.

 

* Create first Excel Sheet

  CALL METHOD OF application 'Worksheets' = sheet

                               EXPORTING #1 = 1.

  CALL METHOD OF sheet 'Activate'.
  SET PROPERTY OF sheet 'Name' = 'Sheet1'.

  LOOP AT itab1.
    index = row_max * ( sy-tabix - 1 ) + 1. " 1 - column name
    CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
    SET PROPERTY OF cells 'Value' = itab1-first_name.
        index = index + 1. " 1 - column name
    CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
    SET PROPERTY OF cells 'Value' = itab1-last_name.
  ENDLOOP.


* Save excel speadsheet to particular filename

  CALL METHOD OF sheet 'SaveAs'

                  EXPORTING #1 = 'c:tempexceldoc1.xls'     "filename

                            #2 = 1.                          "fileFormat

Regards

vijay

6 REPLIES 6
Read only

Former Member
0 Likes
582

go though this link u got lots of idea....

Read only

Former Member
0 Likes
582

chk this

RH_START_EXCEL_WITH_DATA

Read only

Former Member
0 Likes
582

Try GUI_DOWNLOAD

Read only

Former Member
0 Likes
583

Hi,

check this sample code...

REPORT  ZTEST_EXCEL                   .

 

INCLUDE ole2incl.

DATA: application TYPE ole2_object,

       workbook TYPE ole2_object,

       sheet TYPE ole2_object,

       cells TYPE ole2_object.

CONSTANTS: row_max TYPE i VALUE 256.

DATA index TYPE i.

 

DATA: BEGIN OF itab1 OCCURS 0,

 first_name(10),

 last_name(10),

 END OF itab1.

 

 

START-OF-SELECTION.
 itab1-first_name = '123445'.
 itab1-last_name = 'tesst'.
 append itab1.
 clear itab1.

 

 itab1-first_name = '123446'.
 itab1-last_name = 'tesst'.
 append itab1.
 clear itab1.

 

  CREATE OBJECT application 'excel.application'.
  SET PROPERTY OF application 'visible' = 1.
  CALL METHOD OF application 'Workbooks' = workbook.
  CALL METHOD OF workbook 'Add'.

 

* Create first Excel Sheet

  CALL METHOD OF application 'Worksheets' = sheet

                               EXPORTING #1 = 1.

  CALL METHOD OF sheet 'Activate'.
  SET PROPERTY OF sheet 'Name' = 'Sheet1'.

  LOOP AT itab1.
    index = row_max * ( sy-tabix - 1 ) + 1. " 1 - column name
    CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
    SET PROPERTY OF cells 'Value' = itab1-first_name.
        index = index + 1. " 1 - column name
    CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
    SET PROPERTY OF cells 'Value' = itab1-last_name.
  ENDLOOP.


* Save excel speadsheet to particular filename

  CALL METHOD OF sheet 'SaveAs'

                  EXPORTING #1 = 'c:tempexceldoc1.xls'     "filename

                            #2 = 1.                          "fileFormat

Regards

vijay

Read only

0 Likes
582

thank u for your source code vijay.