我有一个包含三列的示例 csv 表 - 宠物、名称和编号。这是猫和狗的列表,它们各自的名称以及每个名称的出现次数。即
csv 文件中猫或狗的顺序完全是随机的,所以我使用乳胶将一只宠物的所有部分有效地分组到输出文档中它自己的表中。
我的文档创建了两个表格,没有任何问题。我想在最后一列添加一个复选框和文本字段,但到目前为止,尝试这样做时总是出现以下错误。
! \@sDTLforeach 的使用与其定义不匹配。\@ifnextchar ... \reserved@d =#1\def \reserved@a { #2}\def \reserved@b {#3}\f... l.70 ...andafter\docsvlist\expandafter{\uniquepet} ?
下面是文档代码,供参考。
感谢任何帮助。
\documentclass{article}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[parfill]{parskip} % Do not indent paragraphs
\usepackage{longtable, tabu}
\usepackage{datatool}
\usepackage{cellspace}
\usepackage{makecell}
\usepackage{booktabs}
\usepackage{hyperref}
\usepackage[a4paper,top=18mm,bottom=12mm,right=8mm,left=8mm,landscape]{geometry}
\tabulinesep=0.8mm
\setcellgapes{2pt}
\begin{filecontents*}{Pet.csv}
Pet,Name,Number
Dog,Buddy,6305
Dog,Max,5719
Dog,Molly,5402
Cat,Sadie,3389
Cat,Jake,3159
Cat,Lucy,3039
Cat,Bear,2916
Dog,Jack,2703
Dog,Shadow,2537
Dog,Abby,2467
Cat,Rocky,2455
Cat,Toby,2313
Cat,Chloe,2290
\end{filecontents*}
\begin{document}
\begin{Form}
\DTLloadrawdb{Pets}{Pet.csv}%Load vocab file
\newcommand*{\uniquepet}{}
\newcommand*{\csvlistsep}{\renewcommand{\csvlistsep}{ ,}}
\DTLforeach*{Pets}{\Pet=Pet}{%
\expandafter\DTLifinlist\expandafter{\Pet}{\uniquepet}%
{}% do nothing, already in list
{% add to list
\ifdefempty{\uniquepet}%
{\let\uniquepet\Pet}% first element of list
{% append to list
\eappto\uniquepet{,\Pet}%
}%
}%
}
\newcommand{\nextrow}{}
\renewcommand{\nextrow}{}
\newcolumntype{Z}{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}X}
\renewcommand{\do}[1]{%
\bgroup
\def\arraystretch{1}
\makegapedcells
\begin{tabular}{c}
{\huge\bf Popular #1 Names}\\
\end{tabular}
\egroup
\CheckBox[width=1em]{Tick Box}
\TextField{Alternative}
\bgroup
\small
\begin{longtabu} to \textwidth { @{} p{19mm} | p{24mm} | Z }
{\bf Name} & {\bf Occurance} & {\bf Correct?} \par Tick box or enter alternative \\
\toprule \endhead
\DTLforeach*{Pets}{\Pet=Pet, \Name=Name, \Number=Number}
{\ifnum\pdfstrcmp{#1}{\Pet}=0
\eappto\nextrow{\Name & \Number & \noexpand\CheckBox[width=1em]{\Name} \par Free Text Box \noexpand\\} % Collect rows
\fi}%
\nextrow % Print table row
\bottomrule
\end{longtabu}
\egroup
\clearpage
}
\expandafter\docsvlist\expandafter{\uniquepet}
\end{Form}
\end{document}