How to insert data extracted from a csv file?

Added by Marcos Vinicius over 7 years ago

I would like to insert data extracted from an externally loaded table (csv, ods, xls, etc). For example, exam number 1 uses the first line of the file, exam 2 uses the second line, and so on. Is it possible to do this with automultiplechoice?


Replies (4)

RE: How to insert data extracted from a csv file? - Added by Marcos Vinicius over 7 years ago

Yes, I have already done that. My question is, for example:
I use a "student.csv" file like that:

name,forename,id
Boulix,Jojo,001
Golin,André,002
Moniuszko,Stanisław,003

and a separate data file (data.csv) like that:
var1,var2,var3,var4
1,2,3,4
5,6,7,8
9,10,11,12

I want associate the first line of the data file with the first student and so on without putting the data variables as columns of student.csv.

RE: How to insert data extracted from a csv file? - Added by Frédéric Bréal over 7 years ago

I tried with the datatool package.

\DTLgetvalue{\command}{database}{row number}{column number}
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{datatool,csvsimple} %

\usepackage[bloc,outsidebox]{automultiplechoice}

%pour obtenir le numéro du sujet
\makeatletter
\def\Nsujet{\the\AMCid@etud}
\makeatother
\renewcommand{\AMCsubjectPageTag}{\Nsujet}

%%%§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
\newcommand{\sujet}{
\onecopy{1}{ %
%%%%%%%%%%%%%%%%%En tête de la copie %%%%%%%%%%%%%%%%

\noindent{}\champnom{\fbox{    
        \begin{minipage}{0.97\linewidth}
           {\Large\bf\nom{}~\prenom{}}  \hfill\null      
          \vspace*{1mm}
        \end{minipage}
      }}\medskip%

%aller à la ligne n° i qui correspond au numéro du sujet
\begin{question}{A}
\DTLgetvalue{\Var1}{data}{\Nsujet}{1}
What is the next number following \Var1 ?
\AMCOpen{lines=1}{\mauvaise[0.25]{0,25}\bareme{0.25}\mauvaise[0.50]{0,5}\bareme{0.5}\mauvaise[0.75]{0,75}\bareme{0.75}\bonne[1]{1}\bareme{1}}
\end{question}

\DTLgetvalue{\Var1}{data}{\Nsujet}{1}
\begin{question}{\Var1}
What is the next number following \Var1 ?
\AMCOpen{lines=1}{\mauvaise[0.25]{0,25}\bareme{0.25}\mauvaise[0.50]{0,5}\bareme{0.5}\mauvaise[0.75]{0,75}\bareme{0.75}\bonne[1]{1}\bareme{1}}
\end{question}

\AMCassociation{\identifiant}
      }
}
%%%%§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§

\begin{document}
\DTLloaddb{data}{data.csv}

\csvreader[head to column names]{/home/moi/Projets-QCM/divers/listetest.csv}{}{\sujet}
\end{document}

RE: How to insert data extracted from a csv file? - Added by Marcos Vinicius over 7 years ago

This is exactly what I wanted, thank you!

(1-4/4)