Application Development 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: 

Creating a excel file with data in internal table

Former Member
0 Kudos

Hi geeks,

I have a internal table with data .

This internal table i have read from a excel file using ole method .All the data in from the excel file are read properly in the internal table .

Now i have modified these data in the Internal table .

Now i need to create a new excel file with the modified internal table .

I tried this with ole, but could not get the correct output , can any one help me out with this

Moderator message : Not enough re-search before posting, discussion locked.

Message was edited by: Vinod Kumar

3 REPLIES 3

Former Member
0 Kudos

Hello,

You can generate excel files with this scn project http://wiki.sdn.sap.com/wiki/display/ABAP/abap2xlsx

Regards

Javi

Abhijit74
Active Contributor

Hello,

Could you please check this wiki : http://wiki.sdn.sap.com/wiki/display/ABAP/Downloading+internal+tables+to+Excel  or for OLE  http://wiki.sdn.sap.com/wiki/display/Snippets/ABAP+OLE+-+Download+tables+to+multiple+worksheets+in+E... or http://sandeepjetty.blogspot.fi/2012/06/to-download-intertables-dato-multiple.html

use below function module to create xls file.

DATA: t100_lines TYPE STANDARD TABLE OF t001 WITH DEFAULT KEY.

PARAMETERS: p_file LIKE rlgrap-filename DEFAULT 'c:\tmp\test.xls'.

SELECT * FROM t001

INTO TABLE t100_lines.

CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'

EXPORTING

i_filename     = p_file

TABLES

i_tab_sap_data = t100_lines.

Thanks,

Abhijit

yogendra_bhaskar
Contributor
0 Kudos

hi HIMA MINJI ,

go through the following code :

REPORT zole .

TABLES: mara.

INCLUDE ole2incl.

DATA: BEGIN OF itab OCCURS 0,

    matnr LIKE mara-matnr,

   mtart LIKE mara-mtart,

    ersda LIKE mara-ersda,

    datab LIKE mara-datab,

   END OF itab.

DATA: str(20),ndate(10).

DATA: row TYPE i VALUE 1, col TYPE i VALUE 1.

DATA obj TYPE ole2_object.

DATA workbook TYPE ole2_object.

DATA sh TYPE ole2_object.

DATA cell TYPE ole2_object.

DATA range TYPE ole2_object.

DATA app TYPE ole2_object.

DATA sel TYPE ole2_object.

DATA columns TYPE ole2_object.

SELECT *

   INTO CORRESPONDING FIELDS OF TABLE itab

   FROM mara.

CREATE OBJECT obj 'exc el.application'.

*sET PROPERTY OF OBJ 'SheetsInNewWorkbook' = 1.

SET PROPERTY OF obj 'visible' = 1.

CALL METHOD OF obj 'Workbooks' = workbook.

WRITE :/ 'workbook', sy-subrc.

CALL METHOD OF workbook 'add'.

CALL METHOD OF obj 'Worksheets' = sh EXPORTING #1 = 1.

CALL METHOD OF sh 'Activate'.

PERFORM insterdata USING row col 'Material No.'.

col = col + 1.

PERFORM insterdata USING row col 'Material Type'.

col = col + 1.

PERFORM insterdata USING row col 'Creation Date'.

col = col + 1.

PERFORM insterdata USING row col 'Valid From'.

row = row + 1.

LOOP AT itab TO 100.

   col = 1.

   PERFORM insterdata USING row col itab-matnr.

   col = col + 1.

   PERFORM insterdata USING row col itab-mtart.

   col = col + 1.

   WRITE itab-ersda DD/MM/YYYY TO ndate.

   PERFORM insterdata USING row col ndate.

   col = col + 1.

   WRITE itab-datab DD/MM/YYYY TO ndate.

   PERFORM insterdata USING row col ndate.

   row = row + 1.

ENDLOOP.

str = row.

CONCATENATE 'D1:D' str INTO str.

WRITE:/ str.

CALL METHOD OF sh 'range' = range EXPORTING #1 = 'A1:A32'.

PERFORM autofit.

CALL METHOD OF sh 'range' = range EXPORTING #1 = 'B1:B32'.

PERFORM autofit.

CALL METHOD OF sh 'range' = range EXPORTING #1 = 'C1:C32'.

PERFORM autofit.

CALL METHOD OF sh 'range' = range EXPORTING #1 = 'D1:D32'.

PERFORM autofit.

*&---------------------------------------------------------------------*

*&

*Form INSTERDATA

*&---------------------------------------------------------------------*

* text *----------------------------------------------------------------------*

* --> p1 text * <-- p2 text *----------------------------------------------------------------------*

FORM insterdata USING row col value.

   CALL METHOD OF sh 'Cells' = cell

     EXPORTING #1 = row #2 = col.

   SET PROPERTY OF cell 'value' = value.

ENDFORM.                    "INSTERDATA

" INSTERDATA *&---------------------------------------------------------------------*

*& Form AUTOFIT *&---------------------------------------------------------------------*

* text *----------------------------------------------------------------------*  * --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM autofit.

   CALL METHOD OF range 'Select'.

   WRITE:/ 'autofit',

sy-subrc.

   CALL METHOD OF sh 'application' = app.

   CALL METHOD OF app 'selection' = sel.

   CALL METHOD OF sel 'Columns' = columns.

   CALL METHOD OF columns 'autofit'.

ENDFORM. " AUTOFITREPORT ZOLE.

regards ,

Yogendra Bhaskar