Skip to Content

How to save a EXCEL as PDF by ole coding?

Experts,

Yesterday I tried to save a file.xlsx as file.pdf by ole coding and failed,

then i did the same thing on file.docx and succeeded.

So i 'm confused now and hope to make it clear whether it's possible to save a EXCEL as PDF by ole coding....

Below is my test coding of saving file.docx.

Any help will be appreciated *_*.

CREATE OBJECT lv_wordapp 'word.application'.
SET PROPERTY OF lv_wordapp 'Visible' = 0.
CALL METHOD OF lv_wordapp 'Documents' = lv_worddoc.
CALL METHOD OF lv_worddoc 'Open'
  EXPORTING
    #1 = 'C:\Users\Administrator\Desktop\test.docx'.
CALL METHOD OF lv_wordapp 'ActiveDocument' = lv_wordadoc.
CALL METHOD OF lv_wordadoc 'Content' = lv_wordcont.


CALL METHOD OF lv_wordadoc 'SaveAs'
  EXPORTING
    #1 = 'C:\Users\Administrator\Desktop\test.pdf'
    #2 = 17. "save as a PDF file


CALL METHOD OF lv_wordapp 'Quit'.
FREE OBJECT lv_wordapp .

Best Regards

Panda

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Sep 02, 2016 at 08:55 PM

    Hi Panda,

    I took your code and test creating from XLSX to PDF extension and works fine! Check code.

    DATA: lv_wordapp TYPE ole2_object,

    lv_worddoc TYPE ole2_object,

    lv_wordadoc TYPE ole2_object,

    lv_wordcont TYPE c LENGTH 8.

    CREATE OBJECT lv_wordapp 'word.application'.

    SET PROPERTY OF lv_wordapp 'Visible' = 0.

    CALL METHOD OF lv_wordapp 'Documents' = lv_worddoc.

    CALL METHOD OF lv_worddoc 'Open'

    EXPORTING

    #1 = 'E:\Test\documento.xlsx'.

    CALL METHOD OF lv_wordapp 'ActiveDocument' = lv_wordadoc.

    CALL METHOD OF lv_wordadoc 'Content' = lv_wordcont.

    CALL METHOD OF lv_wordadoc 'SaveAs'

    EXPORTING

    #1 = 'E:\Test\documento.pdf'

    #2 = 17. "save as a PDF file

    CALL METHOD OF lv_wordapp 'Quit'.

    FREE OBJECT lv_wordapp .


    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.