TransWikia.com

Write CSV in document with dynamic filename

TeX - LaTeX Asked by Ana Cláudia Faria on February 25, 2021

I’m super new to Latex and I’m trying to do automatic documents that present information regarding each project. Every folder and project has a different name/code and I’d like the document to add a table from a csv file that has the same code and is present in the same folder.

The code for the csv file would be something like XX.000000000.XX.V00.csv, and I need the 0’s to be different for each project (I’m trying to take them from the name of project with several concatenations).
I can’t get the csv reader to use the variable as a filename. How can I solve this?
Below is my code.

makeatletter
defcsvfilename{LM.}
g@addto@macrocsvfilename{substring{currfilename}{4}{12}}
g@addto@macrocsvfilename{.PS.}
g@addto@macrocsvfilename{substring{currfilename}{14}{16}}
g@addto@macrocsvfilename{.csv}
makeatother

csvautotabular[separator=semicolon, respect all]{csvfilename}

Thanks in advance for your help!

One Answer

Your g@addto@macrocsvfilename{substring{currfilename}{4}{12}} doesn't work. Instead of adding the required substring, it literally adds the text substring{followed by the original filename, followed by the literal text {4}{12}, etc.

The reason is that substring is not expandable. Instead it writes its result in a macro thestring. Therefore the solution for creating the filename is instead of all the g@addto@macros:

substring{currfilename}{4}{12}
edefcsvfilename{LM.thestring.PS.}
substring{currfilename}{14}{16}
edefcsvfilename{csvfilenamethestring.csv}

To find out what the filename has become, use

This is the filename: texttt{meaningcsvfilename}

Answered by Pieter van Oostrum on February 25, 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