Iterating Through Data
This code requires the shop.xls spreadsheet. The file shop-products.dbtex is created using:
datatooltk --output shop-products.dbtex --xls shop.xls --sheet productsAlternatively you can use datatooltk-gui to import the data and save it to a file called shop-products.dbtex.
\documentclass[captions=tableheading]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{datatool}
\DTLloaddbtex{\products}{shop-products.dbtex}
\begin{document}
Data imported from \texttt{shop.xls} is shown in
Table~\ref{tab:products}.
\begin{table}
\caption{Formatted data imported from \texttt{shop.xls}}
\label{tab:products}
\centering
\begin{tabular}{lrr}
\multicolumn{1}{c}{\bfseries Product} &
\multicolumn{1}{c}{\bfseries Price (ex VAT)} &
\multicolumn{1}{c}{\bfseries Price (inc VAT)}%
\DTLforeach*{xlsproducts}%
{%
\Product=Product,%
\exPrice=Price (ex VAT),%
\incPrice=Price (inc VAT)%
}%
{%
\\\Product &
\dtlround{\exPrice}{\exPrice}{2}\pounds\exPrice &
\dtlround{\incPrice}{\incPrice}{2}\pounds\incPrice
}%
\end{tabular}
\end{table}
\end{document}
Download sample-iter-xls.tex or sample-iter-xls.pdf.
