16

I am wondering if there is a way to read the data from an excel file and then somehow using a forloop outside a tabular, get a special exam sheet for each student.

Until now, we have been using a code similar to this one:

Fill the blanks below and answer the question.

\begin{tabular}{|l|l|}
\hline
Name:    & E-mail:         \\ \hline
Surname: & Student Number: \\ \hline
\end{tabular}

Question: 2+2=?

and we print the above paper 100 times for a class of 100 student. Now I want to do something like this:

\readfile{students.xls}

\forloop{from i=1 to i=100}{

Answer the question below.

\begin{tabular}{|l|l|}
\hline
Name: \cell{A_i}    & E-mail: \cell{B_i}         \\ \hline
Surname: \cell{C_i} & Student Number: \cell{D_i} \\ \hline
\end{tabular}

Question: 2+2=?

\newpage
}

to get a 100-page .pdf file in which every student has a special page.

Thanks in advance.

  • I have never used it but I think this should be possible with the datatool package and a csv file (you can export your excel file into a csv format) – clemens Jan 26 '16 at 8:01
  • I normally do that the other way around, by using a python script that generates a LaTeX source. If you are interested, rlog.rgtti.com/software/python/python-and-openoffice – Rmano Jan 26 '16 at 9:59
  • Would love to see this expanded - Often teachers have to produce 3 versions of the same test - easy/medium/hard - using different question pools and some students only having 3 choices instead of 4. Scripting the test in python or LuaTex seems like a good option if there was a nice template to start from. – בנימן הגלילי Jan 26 '16 at 10:30
14

You can use the odsfile package, which supports manipulations with OpenDocument Spreadsheet files. You need to convert your excel file to ODS using LibreOffice (Excel can do this as well, but LibreOffice produces cleaner files).

Odsfile provides \includespread command with keyval interface:

\documentclass{article}
\usepackage{fontspec}
\usepackage{odsfile}
\usepackage{url}
\begin{document}
\includespread[%
  file=students.ods,
  range=a1:d,
  rowtemplate={%
    \begin{tabular}{|l|l|}%
    \hline%
    Name: -{1} & E-mail: -{2}\\ \hline% 
    Surname: -{3} & Student Number: -{4}\\ \hline%
    \end{tabular}%
  \endgraf%
    Question: $2 + 2  = $ ?
    \newpage},
  ]

\end{document}

file property specifies spreadsheet file, range specifies range to be processed (columns are a, b, c, etc., rows are numbered, default value for second part of the range is row count, when the number is left).

rowtemplate enables to specify code which will be executed for each row, columns are accessed using -{column number}. Note that we must use \endgraf instead of paragraphs.

The file must be compiled using lualatex.

Sample:

enter image description here

8

Short answer: You are looking for Auto Multiple Choice (AMC).

Long answer: You are looking for Auto Multiple Choice (AMC) that is a LaTeX package and a free GUI program for Linux. If you are a Window user that make regularly exams, it worth to install Linux only to have this program. AMC can make one exam to each student with randomly questions, so each student have completely different questions, or alternatively the same questions, but randomly mixed, with answers in different order too. The scanned images of the written exams may be marked automatically, and their results exported to a LibreOffice spreadsheet linked to the student names using some identification code.

  • 1
    Off topic: Linux users, be careful when trying to install it from terminal, because it will ask to install texlive from repository and a lot of other TeX stuffs. – Sigur Jan 26 '16 at 19:34
  • I think the OP is asking for the same question on all 100 tests, with header information student specific. Nevertheless this answer may help others who find their way here. – Ethan Bolker Jan 26 '16 at 19:57
  • 1
    @Siguir This will happen installing any program with dependencies with texlive (Gummi, Latexila, etc.). See Integrating vanilla TeX Live with Debian to a solution to this. – Fran Jan 26 '16 at 19:57
  • @EthanBolker ACM is designed to scan a ID code and /or the signature to respectively assign automatically and/or manually the sheet evaluation to the student name. Moreover the exam copies are numbered, making nominative sheets needless. But AMC can also will print the students names from a CSV file so you do not need a student ID. See here. – Fran Jan 27 '16 at 6:26
  • off-topic, but I do not recommend nominative sheets in general, at least without additional signature, because then is impossible verify the real identity of the student a posteriori (The exam with name A was really made by the the student A ... or may be someone else?) Even not malicious exchange of exams is possible when the students are not forced to write thir own name in their own handwriting! – Fran Jan 27 '16 at 7:09
2

you can use csvsimple package (http://ctan.math.washington.edu/tex-archive/macros/latex/contrib/csvsimple/csvsimple.pdf)

Here are some possibilities of this package that I find very useful. Documentation is very detailed

with the given data file

================ StudentFile.txt============

name, email, surname, studentnumber
robert, robert@yahoo.fr, roro, 123466
julie, juju@gmail.com, juju, 987456
laure,lolo@test.fr,lolo, 147852
aline,lili@us.com,lili,963258
martine,mart@hotmail.com, titine,258741

===========================================

and latex source

\documentclass{article}
\usepackage{csvsimple}
\begin{document}
\csvreader%
{StudentFile.txt}{1=\name,2=\email,3=\surname,4=\studentnumber}%
{
\begin{tabular}{|l|l|}
\hline
Name: \name   & E-mail: \email       \\ \hline
Surname: \surname & Student Number: \studentnumber \\ \hline
\end{tabular}
\vfill
Questions:

$2+\studentnumber=????$
\vfill
\clearpage
}%

\end{document}
  • What about the page numbers? it is giving running page numbers. But each question paper should have its own page numbers know? – David Jan 27 '16 at 5:06
  • use \pagestyle{empty} – rpapa Jan 27 '16 at 9:38
  • no actually, suppose the questionaire is having 5 pages and I want the page numbers for the 5 pages not for the whole pdf files..@rpapa – David Jan 28 '16 at 12:54
1

A poor man low weight no package approach, limited to four records (could go to nine records if space removal was handled more seriously). To be adapted to one's needs.

\documentclass{article}
% only for self-contained example here
\usepackage{filecontents}
\begin{filecontents*}{StudentFile.txt}
robert, robert@yahoo.fr, roro, 123466
julie, juju@gmail.com, juju, 987456
laure,lolo@test.fr,lolo, 147852
aline,lili@us.com,lili,963258
martine,mart@hotmail.com, titine,258741
\end{filecontents*}

% input stream
\newread\MyFile

\makeatletter
\newcommand*\ParseCSVFile [1]{%
    \openin\MyFile #1\relax
    {\endlinechar-1\ParseCSVFile@}%
    \closein\MyFile
}%
\def\ParseCSVFile@ {%
    \ifeof \MyFile
    \else
        \read \MyFile to \ParseCSVFile@oneline
%debugging
%\typeout{ICI: \ParseCSVFile@oneline}%
        \ifx\ParseCSVFile@oneline\par
        \else
        \ifx\ParseCSVFile@oneline\empty
        \else
           \expandafter
               \ParseCSVFile@DoOneLine\ParseCSVFile@oneline$$$$%
        \fi\fi
        \expandafter\ParseCSVFile@
    \fi
}%

% to be customized as need. 
\def\ParseCSVFile@DoOneLine #1#2,#3#4,#5#6,#7#8$$$${%
    \begin{tabular}{|l|l|}%
    \hline
    Name: #1#2& E-mail: #3#4\\ 
    \hline
    Surname: #5#6& Student Number: #7#8\\ 
    \hline
    \end{tabular}%
  \par
    Question: $2 + 2  = $ ?
\clearpage
}

\makeatother

\begin{document}

\ParseCSVFile {StudentFile.txt}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.