About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Latest news 2024-10-15: New blog post: Tales for Our Times Book Launch.

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 products
Alternatively 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.

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs