Skip to Content

Excel OLE Problem with file creation

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Aug 28, 2006 at 09:02 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 28, 2006 at 09:05 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • 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

  • author's profile photo Former Member
    Former Member
    Posted on Aug 28, 2006 at 09:01 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.