General ⇒ csvtools | Print Text based on Condition
csvtools | Print Text based on Condition
I am generating letter using csvtools package. I have a CSV file which has three fields: Name, address, grade.
I wrote the code, but I want to print a part of text based on condition (data from the CSV file). For example if grade is "A" then print "distincation" for that student, if grade is "B" then print "firstclass" for that student.
Please let me know how can I do this .
Regards
Shagi
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
csvtools | Print Text based on Condition
Code: Select all
\documentclass{letter}
\usepackage{etoolbox}
\usepackage{datatool}
\begin{filecontents*}{test.csv}
Name,Address,Grade
A.N. Other,1 The Street,A
Some One,2 The Road,B
\end{filecontents*}
\DTLloaddb{mydata}{test.csv}
\newcommand{\Agrade}{distinction}
\newcommand{\Bgrade}{first class}
\newcommand{\gradelabel}[1]{%
\ifcsdef{#1grade}{\csuse{#1grade}}{unknown classification}%
}
\begin{document}
\DTLforeach*{mydata}{\Name=Name,\Address=Address,\Grade=Grade}{%
\begin{letter}{\Name\\\Address}
\opening{Dear \Name}
You grade is \Grade\ (\gradelabel{\Grade}).
\end{letter}
}
\end{document}
Nicola Talbot
Creating a Minimal Example: http://www.dickimaw-books.com/latex/minexample/