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: 

Excel OLE Problem with file creation

former_member246786
Participant
0 Kudos
1,039

Hi,

I have problems trying to create excel files from SAP using OLE automation.

The purpose of the development is to create 3 generate 3 excel files from SAP, to format these file, save these files on the user's 'c:\temp\' directory and to display all these files at once (open and show Excel application and display the created files).

Ar the begining I tried something that created a unique file and open it. That worked ( there was no CALL mthod 'Close ' and 'Quit').

Probleme was that it's necessary for me to create the files, save the files, close excel application, reopen the 3 files later. Since i try to do it I encounter the following problems :

- file is created but format disappear ( I only have a simple file with blanck cells)

- Excel process stay in Windows task manager after the call to 'Close' and 'Quit'

What can be wrong with my code?

Please help, i'm looking for a solution since more than 2 weeks.

1 ACCEPTED SOLUTION

athavanraja
Active Contributor
0 Kudos
331
4 REPLIES 4

Former Member
0 Kudos
331

U shud work in following Steps while opening a excel file

I have also given code for Creating Document and Closing the document.With some changes it will work..

*STEP 1 - ASSIGN dOCUMENT TYPE

document_type = 'Excel.Sheet.5'.

IF NOT document IS INITIAL.

CALL METHOD document->close_document.

ENDIF.

*STEP 2 - CREATE DOC OBJECT

CREATE OBJECT document

EXPORTING control = control

document_type = document_type

document_format = soi_docformat_compound.

*STEP 3 - CREATE DOCUMENT FROM THAT OBJECT WITH METHOD

CALL METHOD document->create_document

EXPORTING

open_inplace = 'X'

IMPORTING

retcode = retcode.

*STEP 4 - CHECK FOR ANY ERROR

CALL METHOD c_oi_errors=>raise_message

EXPORTING

type = 'E'.

is_open_inplace = 1. is_open_for_edit = 1.

ENDIF.

*Close Doc method

METHOD close_document.

DATA: has_changed TYPE i, is_closed TYPE i.

DATA: save_error TYPE REF TO i_oi_error.

IF NOT proxy IS INITIAL.

CALL METHOD proxy->is_destroyed

IMPORTING

ret_value = is_closed.

*Close the doc proxy

IF is_closed IS INITIAL.

CALL METHOD proxy->close_document

EXPORTING

do_save = do_save

IMPORTING

has_changed = has_changed

retcode = retcode

error = error.

IF retcode NE c_oi_errors=>ret_ok.

EXIT.

ENDIF.

ENDIF.

*Release the proxy

CALL METHOD proxy->release_document

IMPORTING

retcode = retcode

error = error.

IF NOT save_error IS INITIAL.

IF save_error->error_code NE c_oi_errors=>ret_ok.

CALL METHOD save_error->flush_error.

retcode = save_error->error_code.

error = save_error.

ENDIF.

ENDIF.

CLEAR: has_changed_at_reopen.

ELSE.

retcode = c_oi_errors=>ret_document_not_open.

ENDIF.

ENDMETHOD. "close_document

*Close Doc method Ends

*Create Document method

METHOD create_document.

IF NOT proxy IS INITIAL.

CALL METHOD me->close_document.

ENDIF.

*Method to get proxy for the document

CALL METHOD control->get_document_proxy

EXPORTING

document_type = document_type

document_format = document_format

IMPORTING

document_proxy = proxy

retcode = retcode.

IF retcode NE c_oi_errors=>ret_ok.

EXIT.

ENDIF.

*Method to create and open document with that proxy

CALL METHOD proxy->create_document

EXPORTING

create_view_data = 'X'

open_inplace = open_inplace

IMPORTING

retcode = retcode.

IF retcode NE c_oi_errors=>ret_ok.

EXIT.

ENDIF.

  • SET HANDLER me->on_close_document FOR proxy.

ENDMETHOD. "create_document

*Create Document method Ends

Please Reward If Helpful

REGARDS

athavanraja
Active Contributor
0 Kudos
332

andreas_mann3
Active Contributor
0 Kudos
331

plesae free all objects after method 'quit'

  • disconnect from Excel

FREE OBJECT H_EXCEL.

FREE OBJECT H_mapl.

FREE OBJECT H_zl .

FREE OBJECT H_f.

FREE OBJECT H_save.

A.

0 Kudos
331

thanks for your help but unfortunately; it doesn't solve the problem.

I already create the excel file so I'm not looking for a method to do it. However, i have problem trying to Save and Close properly my work. (Save The Excel File, and End Excel process Started using th CREATE OBJECT 'Excel.application' Statement).

I free all object. I use a Save or a SaveAS method on Workbook to save or on Workbokks collection ( I tried the 2 solution).

I Call the quit method on Excel Application object.

But each time, the problem stay.

Does anyone have an exemple where he create an excel file, save it, close Excel application, open a new excel application, open the created file, and display it?

Thanks very Much