TransWikia.com

Using csvreader in a sentence

TeX - LaTeX Asked on April 17, 2021

I am using csvreader for dynamic reporting.

I would like to call values from specific cells using the csvreader function for example:

Thank you csvreader[head to column names, filter={thecsvinputline=2}]{sample.csv}{}{csvcolii} csvreader[head to column names, filter={thecsvinputline=2}]{sample.csv}{}{csvcoliii.}

To write “Thank you Mark Smith”

Where sample.csv containts for example:

Name,LastName
Mark,Smith
x,y
a,b

If I do this I actually get:
“Thank you Name,LastName Smith”

The information will not necessarily be in the same line of the csv file…

Any ideas of how to fix this or do it differently?

Thank you! 🙂

3 Answers

You can look example on the csvsimple package https://www.ctan.org/pkg/csvsimple

csvnames{my names}{Name=surname,LastName=givenname}

csvreader[my names, late after line=, late after last line=]%
  {example.csv}{}{%
    Thank you givenname surname %was born in birthyear and lives in address.
}

So you need to use directly the header string and put into variable after that you can use it easily.

Answered by user3284261 on April 17, 2021

Here is a way with readarray:

documentclass{article}
usepackage{readarray}
begin{filecontents*}{sample.csv}
Name,LastName
Mark,Smith
x,y
a,b
end{filecontents*}
newcommandfullname[1]{edeftmp{thenumexpr#1+1relax}%
  sample[tmp,1] sample[tmp,2]}
begin{document}
readarraysepchar{,}
readdef{sample.csv}sampledata
readarraysampledatasample[,2]

Thank you, fullname{1}.

Third name is fullname{3}.
end{document}

enter image description here

Answered by Steven B. Segletes on April 17, 2021

Another solution using datatool.

documentclass{article}
usepackage{datatool}
begin{filecontents*}{sample.csv}
    Name,LastName
    Mark,Smith
    x,y
    a,b
end{filecontents*}
DTLloaddb{data}{sample.csv}

newcommandfullname[1]{%
    DTLassign{data}{#1}{dbName=Name,dbLastName=LastName}%
    dbName~{scshapedbLastName}%
}

begin{document}
    Thank you, fullname{1}.
    
    Third name is fullname{3}.
end{document}

Answered by NBur on April 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP