Debian Codegraph @

texmf-dist/doc/latex/datatool/datatool-user-examples/datatool-user-example098.tex

raw
1 % This file is embedded in datatool-user.pdf version 3.4.3 2025-12-04
2 % Example 98 Editing a Row of Data
3 % Label: "ex:selectandeditrow"
4 % arara: pdflatex
5 % arara: pdfcrop
6 \documentclass[12pt]{article}
7 \pagestyle{empty}
8 \begin{filecontents}[noheader,overwrite]{customers.csv}
9 Id,Organisation,Surname,Forename,Email,Age
10 1,,Parrot,Polly,[email protected],42
11 2,University of Somewhere,Canary,Mabel,[email protected]
12 3,University of Somewhere,Zebra,Zoë,[email protected],21
13 4,Zinnia Florestry,Arara,José,[email protected],42
14 5,,Duck,Dickie,[email protected],
15 6,Newt Fellowship,Axolotl,Lizzie,[email protected]
16 7,Avian Emporium,Canary,Fred,[email protected],19
17 8,Newt Fellowship,,Molgina,[email protected]
18 9,,Mander,Sally
19 10,Élite Emporium,Fant,Eli,[email protected],101
20 \end{filecontents}
21
22 \usepackage{datatool}
23 \DTLsetup{default-name=customers}
24 \DTLread{customers.csv}
25 \begin{document}
26 % Edit ID 9
27 \DTLaction[key=Id,value=9]{select row}
28 \dtlreplaceentryincurrentrow
29 {Newt Fellowship}% new value
30 {\dtlcolumnindex{customers}{Organisation}}% column index
31 \dtlappendentrytocurrentrow
32 {Email}% column key
33 {[email protected]}% value
34 \dtlupdateentryincurrentrow
35 {Age}% column key
36 {23}% value
37 \dtlrecombine
38
39 % Remove ID 2
40 \dtlgetrowforvalue{customers} {\dtlcolumnindex{customers}{Id}}% column index
41 {2}% value
42 \dtlrecombineomitcurrent
43
44 \DTLaction{display}
45 \end{document}