Example Code

Save Word or Excel report as a PDF using Report Generation Toolkit and ActiveX

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This is an example that fulfills the function of saving Word or Excel report as a PDF.

 

Description

This VI demonstrates how to use ActiveX methods to save a Word or Excel report as a PDF. This can be useful for generating reports that cannot be edited by the end-viewer. This VI saves the file as "LabVIEW Save.pdf" in the same directory as the source report. You could easily modify this VI to be used as a subVI with the file name of your choice.

 

Requirements

  • LabVIEW 2012(or compatible)
  • Report Generation Toolkit

 

Steps to Implement or Execute Code

 

  1. On the front panel, click the folder to browse for an existing Word or Excel document
  2. Use the "Report Type" control to select the correct file type
  3. Run the VI. It will save the report as a PDF and automatically open your default PDF viewer to display the report.

 

Additional Information or References

VI Snippet

 BD.png

 

 

 

 

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
madoc
Member
Member
on

This is fantastic. Just tried it out once, and seems working. This is solving a huge problem for me. It should be addad to the report generation toolkit. And you should get a fat bonus 🙂  Thanks for posting this!

Martin

"Physician, researcher and programmer wannabe."
Martin_Sveningsson
Member
Member
on

Hi

I just stared to use this as well and it works perfect. However what is the required installations to run this? It works fine for me with Win7, LV2012 and office 2010. However when I build an *.exe and tried to run it on a WinXP and office 2003 my program crashes when it tries to make a word file to a pdf.

Any suggestions?

Regards

/Martin

Daniel_H1
Member
Member
on

Hi Martin,

 

There are a number of reasons this could happen. If you create a post on the LabVIEW discussion forums, I'm sure you'll get some help. Without more details of the crash you're getting, I would guess that the problem is due to one of two things:

1) not including the libraries in your exe build (https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019O6PSAU&l=en-US)

2) The report gen toolkit uses a lot of ActiveX to interface with MS Office. Microsoft may have changed the ActiveX calls between 2003 and 2007. You'll need to test the exe on a computer with Office 2010.

Rajankkrs
Member
Member
on

Hi,

It is really good.  Can anyone tell me how to convert this to use in LabWindows.

-Rajan

lifemore
Member
Member
on

using this method we will be able to generate reports and edit in a simpler way.i am not getting any crashes when save word to pdf c#  using labview. so the above problem can be find in the forum.

hope there are more features in the future.

cathy345
Member
Member
on

Yes, although it can easily convert Word or Excel to PDF file using using Report Generation Toolkit and ActiveX, there is no function in LabWindows that matches. If you find the way, would you please share it with me? Thank you.

chetuchetan
Member
Member
on

can anyone tell me how to create VI that saves a file in PDF format plz...

Daniel_H1
Member
Member
on

chetuchetan, you should try posting your question on the forums:
https://forums.ni.com/t5/LabVIEW/bd-p/170

Cheers!

NickC9
Member
Member
on

Hi,

How to save html report as a PDF using report generation tool kit and ActiveX.

- Nick

GarryG
Member
Member
on

Hello, and thanks for the post on this!  Has anyone encountered an issue when using this to convert TestStand generated HTML reports to PDF (using the MSWord case)?  This code converts the html to PDF perfectly, except I cannot seem to get it to render the graphs correctly.  When I open the HTML in internet explorer, I see the graph after allowing the ActiveX control to run that creates the graph (it's installed with TestStand).

If anyone has a workaround for this, I would really appreciate it.  Can this be done using MSWord like this?

CLA, CTA
Not my tempo... AGAIN!
Daniel_H1
Member
Member
on

I would suggest you post this question on the discussion forums (ni.com/forums). You'll get a much better response there. Cheers!

FrankPF
Member
Member
on

Hi,

I use this VI and it runs very good.

My problem is that I have a Excel sheet with 6 spreadsheet and on this spreadsheet I use a printarea.

[PrintArea]

1="$A$1:$H$63"

2="$D$1:$K$54"

3="$A$1:$H$54"

4="$A$1:$H$63"

5="$A$1:$H$54"

6="$A$1:$H$54"

I will save this excelfile in a PDF (using the printarea) ! If anyone has a workaround !

2016-08-29. In the German Excel (Active X) is a BUG that the VI did not runs right. In the english version of Excel will be ok.

Strzechu
Member
Member
on

Hi, do you know the way to convert many the same(duplicated) .xls file to one pdf. (every .xls respond one .pdf ) ?

Thanks for help!

FrankPF
Member
Member
on

Hi,

Readout the folder where the excelfiles are be, open all files and copy all spreadsheeds in ONE excelfile. Than use the this vi for changing this excelfile in PDF.

SwapsG
Member
Member
on

This VI is working in one PC, but when I try to run it on other PC(LabVIEW 2012, MS Office 2007, WIN7 Pro), it is showing error  -2147024809, The parameter is incorrect,(one or more arguments are invalid), I reinstalled RGT toolkit but same error is coming.

piZviZ
Member
Member
on
Hi, Using this VI, I am able to generate pdf but it don't shows on front of my application. It stays minimized. Waiting for reply
anujsaini
Member
Member
on

hi this solution is working fine on the system where i have generated the code, but when i have created installer and inatalled the same on oter PC there is was not working can you please help me to resolve this problem.

SwapsG
Member
Member
on

This VI is working in one PC, but when I try to run it on other PC(LabVIEW 2012, MS Office 2007, WIN7 Pro), it is showing error  -2147024809, The parameter is incorrect,(one or more arguments are invalid), I reinstalled RGT toolkit but same error is coming.

Solution- You need to install add-on:- Microsoft Office Add-in: Microsoft Save as PDF or XPS