![结合发票和数据工具来创建序列发票](https://linux22.com/image/275504/%E7%BB%93%E5%90%88%E5%8F%91%E7%A5%A8%E5%92%8C%E6%95%B0%E6%8D%AE%E5%B7%A5%E5%85%B7%E6%9D%A5%E5%88%9B%E5%BB%BA%E5%BA%8F%E5%88%97%E5%8F%91%E7%A5%A8.png)
我想根据 CSV 表生成发票。我的方法如下:
\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}
CSV 文件具有以下结构:
firstname lastname customeraddress tariffname service rateperunit unitcount
John Doe Musterstraße 4 Tariff1 Call 0.04 4
...
然后我.tex
使用 PDFLaTeX 编译该文件。
但我总是收到这个错误:
! 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]
?
和
! 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.
我正在使用texlive
Ubuntu 13.04 的软件包,并且我也尝试使用它csvsimple
,结果出现了完全相同的错误。
答案1
包含日期的错误的一部分已根据 @Ulrike Fischer 的评论进行了修复(通过在文件中替换\input{fp}
)\RequirePackage{fp}
,invoice.sty
主要错误在\DTLforeach
命令中。您不必为.csv
文件中的每个字段添加一个参数,而是将它们全部分组到同一个参数中\DTLforeach
。
另外,在您的.csv
文件中,您需要用 a 分隔字段,,
而不是用空格。
\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}