Example Code

Cross platform wrapper library for generating OpenOffice & LibreOffice spreadsheet documents via LabVIEW python node.

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.

    Operating System

  • Linux
  • Windows

    Programming Language

  • Python

    Other

  • LibreOffice
  • Apache OpenOffice

Code and Documents

Attachment

Description

LvOO - Cross platform brige between Labview and PyOO (Python interface to OpenOffice & LibreOffice API)


LvOO - wrapper library for generating OpenOffice & LibreOffice spreadsheet documents via LabView python node.

The main goal of the library – support both Windows and Linux versions of LabView, using only internal python node only (no .NET, no ActiveX).

 It uses PyOO module created by Miloslav Pojman (miloslav.pojman@gmail.com) - https://github.com/mila/pyoo  
"PyOO wraps a robust OpenOffice(LibreOffice) Python-UNO bridge to simple and Pythonic interface"

Not all features, implemented in PyOO, are supported yet.


Available features:

  • Creating new default spreadsheet document
  • Opening existing document as template
  • Inserting data from LabView to spreadsheet cells
  • Creating new and renaming available sheets
  • Saving spreadsheets in various formats, including MS Office, PDF, etc…
  • Headless (conversion) mode – hide all Office UI

 

How to Use

Instructions:

  1. Unpack content of attached archive to the local drive
  2. Open LabVIEW project file. Project is saved in LabVIEW 2020 under Windows.
  3. Open test.vi Set required oo path to Office installation program directory. Set optional template file, save_file and save_format
  4. Run test.vi On Windows reboot the machine once and run test.vi again. One reboot is required for every change of oo path and calling lvoo create session.vi
  5. If you build an executable containig this library, you need to place lvoo.py and pyoo.py into the py subfolder, relative to executable path.

SubVIs description:

lvoo create session.vi – initialization routine. Input variables:

  • py_version  – version of used python interpreter. If empty, library tries to determine it automatically (on Windows only). On Linux you must provide it manually
  • oo_path      – path to Office program directory. On Windows “c:\Program Files (x86)\OpenOffice 4\program”. On Linux “/usr/bin”. This input is absolutely required
  • oo_startup  – string array of soffice executable startup arguments. These command line arguments determine behavior and appearance of the Office program. You may leave default. 

lvoo generate spreadsheet.vi – open or create spreadsheet, transfer cells data, save and close Calc document or leave it opened. Input variables:

  • sheets          – data to be transferred to spreadsheet cells (described later)
  • template      – full path to file, which will be opened as template. If path is empty – new default spreadsheet will be created
  • ASCII            – if False data will be transferred as UTF-8 characters (work on Linux only). If True, data will be converted to ASCII using system locale
  • save_path    – full path to the new file. If path is empty, Office Calc window will be opened allowing user to save file manually. If not empty, file will be saved in the pointed location and Office Calc UI will not appear – no user interaction required at all. This is true for LibreOffice. OpenOffice will show UI for a couple of seconds and then close it
  • save_format – string representing file format, if you want to convert output file to something other than default *.ods. Some format is predefined in PyOO library, but you can use other format described in UNO documentation 

lvoo destroy session.vi     – dummy close session vi, not really needed.


LabView type of "sheets” data input - collection of spreadsheet document sheets represented by array of clusters. Each cluster consists of array of cells and sheet name. 
If sheet name is not empty, current sheet will be renamed, otherwise leaved default. Array of cells consists of clusters representing single cell. 
This cluster contains row number, column number and data. Data is LabView Variant data type. You can connect numeric and string values. Other types not tested yet.


 

Additional Information

Installation on Windows:

Install preferred Office system. You can use OpenOffice or LibreOffice, but not the both simultanously. By default Office on Windows include its own python interpreter. Manuals recommend using interpreter included to Office pack, instead of python, installed on your system. All office stuff is in the "c:\Program Files (x86)\LibreOffice(or OpenOffice 4)\program" directory. This is main entrance point for the library, which contains soffice.exe itself, python interpreter and its modules.

Besides this, LabView python node needs to know the path to interpreter. You can add it manually to system PATH variable. A little script, included in this project, can do it for you automatically, but only in the user section of environmental variables. One reboot is required for normal python node working after changing oo_path variable and starting lvoo create session.vi! This script also automatically finds the installed python version.


Installation on Linux:

Tested on OpenSUSE Leap 15.1. LibreOffice and Python 3.6 preinstalled on this release. Library is working “out of the box”. No system environmental variables changes required.


Dependencies:

  • OpenG String Library
  • OpenG File Library
  • OpenG Variant Library
  • JSONtext Library

Tested on:

  • Win10 x64 + LabView 2020 x32 + OpenOffice 4.1.13 x32 + Python 2.7.18 x32 (supplied with OO)
  • Win10 x64 + Labview 2020 x32 + LibreOffice 7.3.7 x32 + Python 3.8.15 x32 (supplied with LO)
  • OpenSUSE Leap 15.1 x64 + Labview 2020 x64 + LibreOffice 6.4.5.2 x64 + Python 3.6.12 x64

version 0.0.4 17.01.2023
Copyright (c) 2023 Dmitry Lebedev dvl@engineer.com
 
This library is released under the MIT license. See the LICENSE file.


 

Related Links

PyOO module Miloslav Pojman (miloslav.pojman@gmail.com) - https://github.com/mila/pyoo

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

Contributors