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

regarding OLE Excel

Former Member
0 Likes
701

Hi gurus,

I am creating Excel file passing values to different sheets A,B,C from internal table.

But when my program is under execution, if i try open new excel sheet then datas are getting written into new sheet. so the out put of real excel sheet is different from as expected.

Do i have to maintain any property in OLE excel to avoid this situation. because i want to open some other excel file, while my program is executing with OLE excel creation.

Regards

Ambichan

Hi gurus,

I am creating Excel file passing values to different sheets A,B,C from internal table.

But when my program is under execution, if i try open new excel sheet then datas are getting written into new sheet. so the out put of real excel sheet is different from as expected.

Do i have to maintain any property in OLE excel to avoid this situation. because i want to open some other excel file, while my program is executing with OLE excel creation.

Regards

Ambichan

4 REPLIES 4
Read only

Former Member
0 Likes
664

INCLUDE ole2incl.

DATA: application TYPE ole2_object,

workbook TYPE ole2_object,

sheet TYPE ole2_object,

cells TYPE ole2_object,

gs_chart TYPE ole2_object.

CONSTANTS: row_max TYPE i VALUE 256.

DATA index TYPE i.

CREATE OBJECT application 'excel.application'.

SET PROPERTY OF application 'visible' = 1.

CALL METHOD OF application 'Workbooks' = workbook.

*CALL METHOD OF workbook 'Add'. "if you want to create a file

CALL METHOD OF workbook 'Open'

EXPORTING

#1 = p_file.

  • #1 = 'C:\Temp\XXX0099_Support_20XX.xls'. "your excel file

    • name here

  • Create second Excel sheet "Timesheets

CALL METHOD OF application 'Worksheets' = sheet

EXPORTING

#1 = 2.

SET PROPERTY OF sheet 'Name' = 'Timesheets'.

CALL METHOD OF sheet 'Activate'.

CLEAR: w_index.

SORT itab BY budat hiden.

LOOP AT itab.

w_index = sy-tabix + w_lin.

CALL METHOD OF application 'Cells' = cells

EXPORTING

#1 = w_index " line

#2 = 1. " column

SET PROPERTY OF cells 'Value' = itab-hiden . "need to be changed

  • Save excel spreadsheet to particular filename

CALL METHOD OF sheet 'Save' "'Save'

EXPORTING

  • #1 = p_file

#1 = p_file

#2 = 1."filename

"fileFormat

  • Closes excel window, data is lost if not saved

  • SET PROPERTY OF application 'visible' = 0.

reward points if its helpful

Read only

0 Likes
664

hi antonis,

Can you tell me exactly which stmt will give me a solution for my problem.

regards

Ambichan

Read only

Former Member
0 Likes
664

Hi,

see oss-note 124658

and here:

http://www.abapforum.com/forum/viewtopic.php?t=693&highlight=free+excel

<b>Reward points</b>

Regards

Read only

former_member189059
Active Contributor
0 Likes
664

Hellom

first you create all the sheets you require as follows

* creating sheets
  DO 3 TIMES.
    IF sy-index GT 1.
      CALL METHOD OF excel 'WORKSHEETS' = sheet.
      CALL METHOD OF sheet 'ADD'.
      FREE OBJECT sheet.
    ENDIF.
  ENDDO.

then you activate a sheet and use it as follows

DO 3 TIMES.

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

    CASE count.
      WHEN '1'.
      "code
      WHEN '2.
      "code
      WHEN '3'.
      "code

   endcase.
enddo.