Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Data from internal table to separate Excel sheets

hi All,

I have to write a program which saves data from an internal table to separate Excel sheets (of one Excel Workbook) - broken by Controlling Area. If any of you did this before, pls. copy sample programs here. Any piece of valuable information of handling Excel in ABAP is welcome as well. Pls. do not copy external links, as I am not able to acces the Internet (except SDN).

thanks in advance for all answers

ec

Tags:
Former Member replied

Hi,

Then go through the below code

DATA : EXCEL TYPE OLE2_OBJECT,

WORKBOOKS TYPE OLE2_OBJECT,

WORKBOOK TYPE OLE2_OBJECT,

CELLS TYPE OLE2_OBJECT,

SHEET TYPE OLE2_OBJECT,

FONT TYPE OLE2_OBJECT,

H_COM1 TYPE OLE2_OBJECT,

F TYPE RLGRAP-FILENAME,

FILEP TYPE DRAW-FILEP,

G_FILE_DEST TYPE STRING,

G_FILE_TEMP TYPE STRING,

G_SYSUBRC TYPE SY-SUBRC,

G_FILE_SRC TYPE DRAW-FILEP.

  • START THE EXCEL APPLICATION

CREATE OBJECT EXCEL 'EXCEL.APPLICATION'.

CALL METHOD OF EXCEL 'WORKBOOKS' = workbooks.

SET PROPERTY OF EXCEL 'VISIBLE' = 0.

CALL METHOD OF WORKBOOKS 'OPEN' EXPORTING

#1 = filep.

  • For Sheet1

CALL METHOD OF excel 'Worksheets' = sheet

EXPORTING #1 = 1.

CALL METHOD OF sheet 'Activate'.

FREE OBJECT sheet.

CALL METHOD OF EXCEL 'CELLS' = cells

exporting #1 = 1

#2 = 15.

SET PROPERTY OF CELLS 'VALUE' = 'ABCD'.

CALL METHOD OF CELLS 'FONT' = font.

set property of font 'SIZE' = '20'.

free OBJECT cells.

GET PROPERTY OF EXCEL 'ACTIVESHEET' = sheet.

  • For Sheet2

CALL METHOD OF excel 'Worksheets' = sheet

EXPORTING #1 = 2.

CALL METHOD OF sheet 'Activate'.

FREE OBJECT sheet.

CALL METHOD OF EXCEL 'CELLS' = cells

exporting #1 = 1

#2 = 6.

SET PROPERTY OF CELLS 'VALUE' = 'XYZ'.

CALL METHOD OF CELLS 'FONT' = font.

set property of font 'SIZE' = '20'.

GET PROPERTY OF EXCEL 'ACTIVESHEET' = sheet.

CALL METHOD OF SHEET 'SAVEAS' EXPORTING

#1 = g_file_dest

#2 = 1.

CALL METHOD OF WORKBOOKS 'CLOSE'.

CALL METHOD OF EXCEL 'QUIT'.

FREE OBJECT EXCEL.

Thanks!

Brunda

'Reward if useful'

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question