我创建了一个 excel 文件,其中包含姓名、职称、职位、部门、教职员工、学院、电话号码、电子邮件 ID 列
我想要按部分划分的电话簿,例如,我们有 16 个院系。因此,我想创建一个章节/节标题,例如“xyz 院系”,在其下创建节或子节,例如“abc 系”,在其下创建教职员工的姓名及其电话号码。
是否可以创建这样的目录?
答案1
该csvsimple
包适合您。给定一个 .csv 格式的档案,您可以获得一个仅包含所需数据的表(tabular
或)。在下面的示例中,我使用键仅打印与“部门”列(即第四列,因此)中的某个值匹配的行。我更喜欢使用环境,因为我预计某些表会跨越两页(或更多)。longtable
filter equal
\csvcoliv
longtable
\documentclass{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{csvsimple}
\usepackage{longtable}
\begin{filecontents*}[overwrite]{test.csv}
Name,Title,Designation,Department,Faculty,Institute,TelNo,EmailID
Isaak Bacharach,Doctor,Foo,Mathematics,Science,Foo,234234123,[email protected]
Reinhold Baer,Professor,Foo,Chemics,Science,Foo,234234123,[email protected]
Christian Bär,Doctor,Loo,Physics,Science,Loo,234234123,foogmail.com
Wolf Barth,Professor,Foo,Physics,Science,Foo,234234123,[email protected]
Friedrich L. Bauer,Professor,Loo,Chemics,Science,Loo,234234123,foogmail.com
August Beer,Doctor,Foo,Sociology,Literature,Foo,234234123,[email protected]
Walter Benz,Professor,Loo,Physics,Science,Loo,234234123,foogmail.com
Rudolf Berghammer,Professor,Foo,Sociology,Literature,Foo,234234123,[email protected]
Felix Bernstein,Professor,Loo,Physics,Science,Loo,234234123,foogmail.com
Ludwig Berwald,Doctor,Foo,Philosophy,Literature,Foo,234234123,[email protected]
Karl Bobek,Professor,Loo,Sociology,Literature,Loo,234234123,foogmail.com
Friedrich Böhm,Doctor,Foo,Philosophy,Literature,Foo,234234123,[email protected]
Oskar Bolza,Professor,Loo,Chemics,Science,Loo,234234123,foogmail.com
Karl-Heinz Boseck,Professor,Foo,Chemics,Science,Foo,234234123,[email protected]
Hermann Bottenbruch,Doctor,Loo,Philosophy,Literature,Loo,234234123,foogmail.com
\end{filecontents*}
\newcommand{\getphonelist}[1]{%
\begin{longtable}[l]{lll}
\bfseries Person & \bfseries Tel.~No. & \textbf{Email ID}
\csvreader[head to column names,filter equal={\csvcoliv}{#1}]{test.csv}{}%
{\\ \Name & \TelNo & \texttt{\EmailID}}
\end{longtable}}
\begin{document}
\csvautolongtable{test.csv}
\section*{Faculty of Science}
\subsection*{Department of Mathematics}
\getphonelist{Mathematics}
\subsection*{Department of Physics}
\getphonelist{Physics}
\section*{Faculty of Literature}
\subsection*{Department of Philosophy}
\getphonelist{Philosophy}
\subsection*{Department of Sociology}
\getphonelist{Sociology}
\end{document}