3

I want to generate invoices based on a CSV table. My approach looks like this:

\documentclass{letter}
\usepackage{invoice}
\usepackage{datatool}
\address{ABC AG \\
    Nonamestreet 4 \\
    1100 Vienna \\
    [email protected]}
\date{16. September 2013}
\begin{document}    
\DTLloaddb{bills}{billdata.csv}
\DTLforeach{bills}
{\firstname=firstname}
{\lastname=lastname}
{\caddress=customeraddress}
{\tariffname=tariffname}
{\service=service}
{\rateperunit=rateperunit}
{\unitcount=unitcount}
{
\begin{letter}{\firstname~ \lastname \\ \caddress}
\opening{Invoice}     Dear customer \lastname! This is your current bill.
\begin{invoice}{Euro}{20}
\ProjectTitle{\tariffname}
\Fee{Regular charge} {\rateperunit} {\unitcount}
\end{invoice}
\closing{Best regards, ABC AG}
\end{letter}
\clearpage
}
\end{document}

The CSV file has the following structure:

firstname   lastname    customeraddress tariffname  service rateperunit unitcount
John    Doe Musterstraße 4  Tariff1 Call    0.04    4
...

I then compile the .tex file with PDFLaTeX.

But I'm always getting this error:

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...                                              

l.36 \NeedsTeXFormat{LaTeX2e}[
                           1995/12/01]
? 

and

! Emergency stop.
...                                              

l.36 \NeedsTeXFormat{LaTeX2e}[
                              1995/12/01]
You're in trouble here.  Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

I am using the texlive package of Ubuntu 13.04, and I also tried that with csvsimple, ending up with the exact same error.

4
  • Please help! This is the last part of my thesis which is due in less than a week! Thank you in advance. Sep 16, 2013 at 9:28
  • 2
    invoice loads fp with \input instead of \RequirePackage and this disturbs datatool as it doesn't realize that fp has already been loaded. Try if it works if you load datatool before invoice. Or correct invoice.sty. Sep 16, 2013 at 9:56
  • @UlrikeFischer you're right, using \RequirePackage works (with the other modifications I post in my answer)
    – Red
    Sep 16, 2013 at 9:59
  • I want to thank you all for the fast answers! You really saved my thesis. Sep 16, 2013 at 11:00

1 Answer 1

6

A part for the error that contains the date that is fixed following the comment of @Ulrike Fischer (by substituting \input{fp} with \RequirePackage{fp} into the invoice.sty file), the main error is in the \DTLforeach command. You don't have to add an argument for each field in your .csv file but group them all in the same argument of \DTLforeach.

Also in your .csv file you need to separate your fields with a , and not with spacing.

\documentclass{letter}
\usepackage{invoice}
\usepackage{datatool}
\address{ABC AG \\
    Nonamestreet 4 \\
    1100 Vienna \\
    [email protected]}
\date{16. September 2013}
\begin{document}    
\DTLloaddb{bills}{billdata.csv}
\DTLforeach{bills}
{\firstname=firstname,
\lastname=lastname,
\caddress=customeraddress,
\tariffname=tariffname,
\service=service,
\rateperunit=rateperunit,
\unitcount=unitcount}
{
\begin{letter}{\firstname~ \lastname \\ \caddress}
\opening{Invoice}     Dear customer \lastname! This is your current bill.
\begin{invoice}{Euro}{20}
\ProjectTitle{\tariffname}
\Fee{Regular charge} {\rateperunit} {\unitcount}
\end{invoice}
\closing{Best regards, ABC AG}
\end{letter}
\clearpage
}
\end{document}

enter image description here

1
  • Marked it. What makes the author of invoice.sty using input{} instead of RequirePackage{}? Shall I report a bug? Sep 16, 2013 at 11:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .