显示 csv 数据库内容

显示 csv 数据库内容

我是新手。我需要创建欧洲主要歌剧(古典声乐)课程的目录。每所学校都有自己的页面。每个页面都有关于学校的具体信息:学校名称、地址、学位名称(硕士、证书……)、学位网站(链接)、费用、申请截止日期、开始日期、持续时间、联系人……等等。

据我所知,一个好的做法是创建一个 csv 文件 (targets.csv),然后使用它datatool在表格中显示其内容。理论上是这样的;但实际上它不起作用(对我来说)。这是我的 target.csv 文件:

id,institute,address,degree,websitedegree,fee,applicationfee,applicationdl,startdate,duration,contactperson,cptitle,cpcontact,actionplanned,actiontaken,furtheraction,fadl,lastupdate
1,%id
The Juilliard School,%institute
60 Lincoln Center Plaza New York NY 10023,%address
Master of Science in Voice,%degree
\href{http://www.juilliard.edu/apply-audition/application-audition-requirements/master-music-and-graduate-diploma-table-contents}{website}(to be updated 2016),%websitedegree
62000 dollars per year (a.i.),%fee
120 dollars,%application feed
1.12.2015 (to be confirmed),%application deadline
smtg,%start date
2 years,%duration
na na na,%contact person
na na na,%cp title
mail,%cp contact
apply,%action planned
20.07.2015: scheduled recording session for audition,%action taken
record prescreening audition according to the repertoire,%further action
15.09.2015,%further action deadline
\today%last update

和我的 main.tex 文件:

\documentclass{article}
\usepackage[showframe,paperwidth=32cm]{geometry}
\usepackage{hyperref}
\usepackage{datatool}

\begin{document}
    \DTLloaddb{myDB}{targets.csv}
    \noindent\DTLdisplaydb{myDB}
\end{document}

我收到以下错误:

! File ended while scanning use of \@dtl@trim.
<inserted text>
\par
<*> main.tex
I suspect you have forgotten a `}', causing me
to read past where you wanted me to stop.
I'll try to recover; but if the error is serious,
you'd better type `E' or `X' now and fix your file.
! Emergency stop.
<*> main.tex
*** (job aborted, no legal \end found)

有人能帮帮我吗?谢谢 Laura

答案1

您的问题出在 csv 文件中:您用逗号分隔每个字段,然后插入换行符。换行符会干扰解析器宏,解析器宏仅搜索逗号作为字段分隔符。当找到换行符时,它会将其作为行分隔符读取并开始新行,而不会完成读取头部声明的所有字段。因此,解决方案是删除所有换行符并将所有字段放在一行上。

id,institute,address,degree,websitedegree,fee,applicationfee,applicationdl,startdate,duration,contactperson,cptitle,cpcontact,actionplanned,actiontaken,furtheraction,fadl,lastupdate
1,"The Juilliard School","60 Lincoln Center Plaza New York NY 10023","Master of Science in Voice", "\href{http://www.juilliard.edu/apply-audition/application-audition-requirements/master-music-and-graduate-diploma-table-contents}{website}(to be updated 2016)","62000 dollars per year (a.i.)","120 dollars","1.12.2015 (to be confirmed)",smtg,"2 years","na na na","na na na",mail,apply,"20.07.2015: scheduled recording session for audition","record prescreening audition according to the repertoire","15.09.2015","\noexpand\today"
1,"The Juilliard School","60 Lincoln Center Plaza New York NY 10023","Master of Science in Voice", "\href{http://www.juilliard.edu/apply-audition/application-audition-requirements/master-music-and-graduate-diploma-table-contents}{website}(to be updated 2016)","62000 dollars per year (a.i.)","120 dollars","1.12.2015 (to be confirmed)",smtg,"2 years","na na na","na na na",mail,apply,"20.07.2015: scheduled recording session for audition","record prescreening audition according to the repertoire","15.09.2015","\noexpand\today"

另外,当你添加一个包含空格的字段时,你需要用两个双引号将其括起来,因为空格可能会很麻烦。

这里我放了一个 WME,我使用环境DTLenvforeach而不是\DTLdisplaydatabase。此环境允许您逐行读取数据库并使用每列,将它们分配给宏。我\newpage在环境末尾放了一个,因此每行都显示在新页面中,正如您所问的那样。

\documentclass{article}
\usepackage[showframe,paperwidth=32cm]{geometry}
\usepackage{hyperref}
\usepackage{datatool}
    \DTLloaddb{myDB}{database.csv}
\begin{document}
\begin{DTLenvforeach}{myDB}{\id=id,\instit=institute,\addr=address,\degr=degree,\web=websitedegree,\fee=fee,\appl=applicationfee,\appldl=applicationdl,\sdate=startdate,\durat=duration,\person=contactperson,\cptitle=cptitle,\cpcontact=cpcontact,\actionp=actionplanned,\actiont=actiontaken,\faction=furtheraction,\fadl=fadl,\lupdate=lastupdate}
\centering
\null
\vspace{\fill}
\begin{tabular}{*{5}{c}}
\bfseries Id & \bfseries Institute & \bfseries Address & \bfseries Degree & \bfseries Web \\
\id & \instit & \addr & \degr & \web
\end{tabular}

\vspace{\fill}
\begin{tabular}{*{6}{c}}
\bfseries Fee & \bfseries Application fee & \bfseries Application dl & \bfseries Start date & \bfseries Duration & \bfseries Contact person\\
\fee & \appl & \appldl & \sdate & \durat & \person
\end{tabular}

\vspace{\fill}
\begin{tabular}{*{4}{c}}
\bfseries Cp title & \bfseries Cp contact & \bfseries Action planned & \bfseries Action taken \\
\cptitle & \cpcontact & \actionp & \actiont
\end{tabular}

\vspace{\fill}
\begin{tabular}{*{3}{c}}
\bfseries Futher action & \bfseries Fadl & \bfseries Last update\\
\faction & \fadl & \lupdate
\end{tabular}

\vspace{\fill}
\newpage
\end{DTLenvforeach}
\end{document}

相关内容