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: 

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

1 ACCEPTED SOLUTION

former_member235395
Contributor
0 Kudos

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,

3 REPLIES 3

former_member235395
Contributor
0 Kudos

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,

0 Kudos

I think the OP question was to convert the Excel file into a PDF via the excel.application, but it's fun if it works using Word 😛

0 Kudos

Hi David,

The case with 'Word.application' is ok.

I just want to do the same thing with 'Excel.application'.

However, the PDF file which is generated from EXCEL is not available to open.

This is my question and i hope somebody could give me a successful example.