[Tex/LaTex] Link LaTeX Documentation to Excel Data

databaseexcel

I am writing documentation for a build log that needs to have part numbers inserted. Rather than have someone go through and update part numbers in a document to reflect revisions and updates, I wanted to have parts simply listed in an excel spreadsheet (possibly across sheets to organize them) with static line numbers (so I can reference that in LaTeX somehow). Then, revisions could be made to the spreadsheet and the document recompiled.

What I would like is a command like this:

\insertdata{filename.xlsx}{sheetname}{linenumber}{pn} which would produce a part number. The last two arguments are basically a row/column selector ("pn" representing "partnumber" but could also be "name" or "description", etc. for various data stored in that row).

I have seen that the exceltex package could be re-wrapped to do this, but I am working on Windows, and I can't guarantee that others using this will have Cygwin installed, so it needs to be fully reliant on a rather stock Windows environment.

I would also prefer not to export the spreadsheet as a CSV, unless that can be integrated in the builder somehow.

If it's relevant, I am using MikTeX 2.9 and Sublime Text 3 with LaTeXTools on Windows 8.1.

Thanks!

Best Answer

The datatool package has a Java helper application datatooltk that has a batch mode and a GUI mode. The batch mode is the default and allows it to be integrated into the document build process. Using this sample XLS file as an example, I can fetch the data from the first sheet (labelled products) using datatooltk and store it in datatool's internal database structure:

% arara: datatooltk: {
% arara: --> output: products.dbtex,
% arara: --> xls: shop.xls,
% arara: --> sheet: products }
% arara: pdflatex
\documentclass{article}

\usepackage{datatool}

\DTLloaddbtex{\products}{products.dbtex}

\begin{document}

Fetch values from row 3:
\DTLassign{\products}{3}{\Product=Product,\Price=Price (inc VAT)}
Product: \Product. Price: \Price.

\end{document}

I've included arara directives, but if you're not using arara the build process is (assuming the file is called test.tex):

datatooltk --output products.dbtex --xls shop.xls --sheet products
pdflatex test

Fetch values from row 3: Product: USB stick. Price: 18.0.

Related Question