Saturday, June 2, 2018

How to Generate the PDF Report through LabVIEW

There has been a previous sister article (reply the key word "WORD" to get this sister article - editor's note: This article is reproduced from the WeChat public number "LabVIEW-Jobs", so you need to reply to the public number.) It's about how to read the contents of MS WORD documents through LabVIEW. At the end of the article, there is a primer that LabVIEW can also complete the production of MS WORD documents and PDF format documents. PDF is a very complex format, so here are some tools to achieve our goals. It's also from the story of a sister article, a PDF format report generated by a customer's production test software, which solved the read problem and thought how it was generated. After looking at every corner of the software, the key word "itextsharp©" seems to be related, finding the source through a search - itextsharp© is indeed an open source library that specializes in dealing with PDF. Those who are interested can learn more about this library.


Itextsharp© free open source library, the main tool of this article. It has served tens of thousands of people, and it is necessary to briefly introduce the source. At present, the open source library has been published on two major hosting platforms: and, which are interested in going in and worshipping the big gods--the great people. The details are not introduced. Let me explain the copyright license of this tool. Itextsharp© is completely free, before the fourth edition is the open source MPL and LGPL protocol, the popular free freedom of open source, whether your own project is open source or closed source. After the 4.2 version, itextsharp© is still open source, but you must also open your own project, that is, the AGPL protocol. And commercial projects unwilling to open source must purchase copyrights, and names become iText© (Fifth Edition), no longer itextsharp. As you can see from the screenshot below, we use the version, which should be without copyright.


Even if you get this open source library, further integration into LabVIEW® is very tedious, since there are a lot of parameters to be configured. So here we want to introduce another LabVIEW-based toolkit which called Exaprom PDF. This toolkit developed based on our previous itextsharp© by a Canadian company. Since itextsharp© is open source, Exaprom PDF is also open source, BSD protocol.


First download the toolkit, the download and installation instructions are at: The author (Jean-Marc Simard, who is also a great god) posted on the NI forum and can see that he has been maintaining and is still answering some questions from the user. The following is basically a porter. The author produced two versions:

2013 version download address:; 2009 version Download address: After downloading the archive, unzip it to get a folder and a file, as shown in the following figure: One is the .VI code package, and the other .mnu file is the menu file.



Next, place them in the specified directory: C:\Program Files\National Instruments\LabVIEW Version\vi.lib\ (Maybe it is a little different upon your Windows® OS version) Place the code folder here, refer to the below screenshot.


Then place the menu file, as shown in the following screenshot: C:\Program Files\National Instruments\LabVIEW Version\menus\Categories\Programming\, (maybe a little different upon your Windows OS version) as the name implies, it knows the specific location.


After you place all files into the specific locations and restart LabVIEW, you can see that the function panel has loaded all PDF-related functions. As shown the below:


Reading here, you should feel a lot of peace of mind. The author developed this toolkit entirely based on LabVIEW® and NI style and it very easy to use and start. In addition, you can also find that the author (Great God) has complete copyright notice information in each function's program panel and Help page - both itextsharp's copyright statement and the author's own BSD copyright notice.


Finally, is it feeling less or missing? Yes, it seems that there is no user instruction? In fact, the author has provided the very detailed help information for every function, as well as a very detailed user manual. The author is very clever to integrate the entire user manual into a VI. It is the function VI labeled in the next screenshot. After opening and running, it will generate a 43 page PDF document, which is a lot of pictures and text, and the User is full of the creation of the text and various instances of the PDF document. Just imagine: an example has generated an PDF document with 43 pages of illustrations. What else can't be done? If there is a higher requirement, or the discovery of bug, it can interact with the original author at the place where the article is published, and it can basically solve the general problem. Of course, with the progress of technology, PDF is also a further development, but it can be seen that copyright considerations, the author does not upgrade the itestsharp©, and can not be upgraded in the existing mode.



It is over here. It can be said that in addition to the author (myself) introduced this artifact(toolkit), and talked about copyright issues many times. It also promotes a kind of copyright awareness. Even if it is free and open source software, it is also required the agreement, such as signature, re-open source and so on. Therefore, if the software is developed through this article, not expect to label the copyright agreement everywhere, at least the copyright notice of itestsharp and Exaprom PDF is marked on the copyright page of the software. Again, the toolkit mentioned in this article can be used for closed-source commercial purposes without paying fees, and only the developer's copyright information needs to be retained. Well, the spread of this article also requested to retain the source and signature - WeChat® public number: LabVIEW-Jobs :-)



1. (Exaprom PDF release page)

2. Https:// (itestsharp official website)

3. Https:// (itestsharp source code shared release page)


Note: This article is translated and reprinted from WeChat public account--LabVIEW-Jobs, please follow this WeChat public number for the original source inquiry. And any question about this article, please also contact with author by email


Saturday, May 5, 2018



将NI LabVIEW软件中的数据移动到Microsoft Excel有许多不同的方法。 每种方法都有优缺点,因此我们将探讨一些可用的选项,以帮助您找到适合您应用的选项。



DIY ActiveX


































1 数据可以以编程方式发送到Excel,但保存文件需要手动操作
2需要用于Microsoft Excel的TDM Excel加载项 - 可以免费下载并与最新版LabVIEW一起安装
3需要安装用于Microsoft Office的NI LabVIEW报表生成工具包



导出数据到Excel方法支持任何图形、图表、表格、数组或数字数据控件。 图形和图表仅导出可见数据,这意味着您可以使用图形工具来放大感兴趣的区域,并仅导出需要的数据。 表格仅导出当前选中的数据,而数组则可导出数组中的所有数据。

您还可以使用调用节点,以编程方式调用导出数据到Excel导出绘图数据到Excel方法。 以下代码片段可生成正弦波,然后将绘图数据输出到Excel两次,以显示两种不同的方法。 两种方法之间的区别是导出绘图数据到Excel方法仅导出指定图的数据,而导出数据到Excel方法则导出所有图的数据。 这个简单的例子只有一个图,所以这两个方法产生的结果相同。

使用这种技术时,请注意,Excel必须安装在与LabVIEW相同的机器上,并且无法通过编程来保存Excel文件。 因此,这种方法最适合于需要交互式调查数据并快速将数据发送到Excel进行分析或发布的应用。

注意: "导出到Excel功"功能从LabVIEW 2010版开始提供,此前的版本均不具备该功能。


NI开发了技术数据管理流(TDMS)文件格式来快速、高效地保存文档化的测量数据。 虽然TDMS本身不支持Excel,但是您可以使用一个免费的Excel加载项将数据导入Excel。

创建TDMS文件最简单的方法是使用文件I/O选板中的 Write To Measurement File Express VI。

与所有Express VI一样,将VI放在程序框图上时,会看到一个配置对话框。这个特定的Express VI可以不仅仅只是保存为TDMS,所以一定要在文件格式部分中选择二进制(TDMS)。 保存文件的方式有多种,当选定文件已经存在时的做法也有多种选择。

[+] 放大图片



对于更习惯手动控制的用户,LabVIEW还提供了一个用于写入TDMS文件的API,而无需使用Express VI。

如果有数据存储到TDMS文件中,则需要确保您已安装用于Microsoft Excel的TDM Excel加载项。 安装LabVIEW时,您可能已经安装了该加载项,如果没有,您可以随时免费下载。 安装加载项后,您可以直接在TDMS文件上单击鼠标右键,然后选择 打开方式»Excel导入器,这时会打开Excel并显示相应的数据。


[+] 放大图片


[+] 放大图片

数据导入到Excel后,就不会依赖或链接回原始的TDMS文件(但原始文件可以使用LabVIEW或DIAdem中的ExcelTDM DataPlugin重新创建),因此您可以随意与任何Excel用户共享您的工作簿。


大多数情况都支持逗号分隔值(CSV)文件格式,因此您可以在Excel中打开文件,但也可以将其导入到其他电子表格、数据库或分析工具。 CSV文件是人类可读的文本文件,列与列之间通过逗号隔开,行与行之间则通过换行隔开。 这通常需要我们在LabVIEW中进行一些数据操作,以便将测量数据转换为适当的格式,因为我们无法使用复杂的数据类型(如波形),也不能将数值存储更高效的二进制格式,以便LabVIEW或TDMS文件内部使用。

您可以使用文件I/O选板中的Write To Spreadsheet File VI来创建要在Excel中打开的CSV文件。

简单的一维数组并不需要进行任何额外的处理。默认情况下,Write To Spreadsheet File VI使用制表符(/t)作为分隔符,因此您只需要指定逗号(,)作为分隔符即可。

一个更复杂的例子是将Express VI返回的数据(如DAQ助手模拟信号)写入CSV文件中,并标记时间,同时在下一列显示测量值。 下面的代码片段显示了如何将动态数据转换为波形数组; 然后将数组中每个波形的所有测量值转换为字符串; 接着再为每个样本制定一个时间字符串; 并最终为这些字符串创建二维数组,以便传递给Write To Spreadsheet File VI。

[+] 放大图片


[+] 放大图片

如果您使用上面的代码片段,Excel将会理解您的时间戳,但可能无法以有用的方式进行格式化 - Excel是为商业办公而开发的,通常无法在数秒甚至更短的时间内处理数据。 要解决这个问题,您必须使用自定义格式来格式化包含时间数据的单元格,如下所示。

[+] 放大图片

这种方法的一个缺点是此格式化信息无法保存在CSV文件中,因此每次将新文件导入Excel时都必须手动重复该过程。 虽然只能在Excel中打开一次,但您仍可以将数据保存为Excel文件来保留格式,以便后续使用。

Microsoft Office报表生成工具包

在将数据发送到Excel时,用于Microsoft Office的NI LabVIEW报表生成工具包提供了很大的灵活性。 最大的优点之一是您可以在Excel中创建一个模板工作簿,并将其保存为.xltx或.xlt文件,然后使用LabVIEW在VI运行时使用数据填充模板。 此代码段显示如何使用MS Office Report Express VI填充此类模板。

[+] 放大图片

创建模板时,您可以像任何其他Excel工作簿一样自定义格式。 然后将单元格命名为数据要放置的位置(对于表格或数组,您只需要命名左上方的单元格即可)。

[+] 放大图片

创建模板后,将Express VI指向模板,并告诉LabVIEW您希望数据如何显示在报表中(以表格或图表形式显示)以及是否要打开、保存或打印Excel文件。

运行上面的代码片段会产生如下所示的输出。 这个简单的例子介绍了这种方法的使用 - 顾名思义,报表生成工具包通常用于自动化生成完整的报表,而不是将简单的数据发送到Excel。

[+] 放大图片

除了Express VI之外,报表生成工具包还提供了一个可用于自动化Excel的完整API。 下面的示例代码产生的输出类似于上述示例,但不需要模板工作簿。 此外,该示例不是使用LabVIEW图形的图像,而是使用Excel图表工具绘制图形。

[+] 放大图片


[+] 放大图片

 DIY ActiveX/.NET

报表生成工具包基于Excel ActiveX接口。 您可以通过直接ActiveX调用或Microsoft.Office.Interop.Excel .NET程序集自动创建Excel文件来使用此API。 下面的代码片段生成与Report Generation Toolkit示例基本相同的结果,但是使用的是.NET互操作程序集来与Excel进行通信。 可以看到,代码最后更为复杂,但任何有ActiveX/.NET编程背景的人员都不会觉得陌生。

[+] 放大图片



[+] 放大图片


如果您有更高级的数据需求,比如较大型的数据集、大量的文件或特定的报告需求,还可考虑DIAdem。 DIAdem是一款用于快速定位、分析和报告测量数据的工具,通常更能够满足工程师对数据工具的许多需求。




  1. 本文转载至NI官方文章,如有侵权请联系admin删除,来源地址:
  2. 技术探讨可联系support