Assuming you can use .csv instead of .xls(x), there are several tools for manipulating CSV files, for example csvsimple.
Though if you want to reinvent some wheels: you can use \ReadCSV to read in the .csv file to a key-value structure, then \getValue to fetch those values when needed. The syntax of \ReadCSV is:
\ReadCSV [*] {<label>} [<name>,<value>] {<file>}
\ReadCSV will read the CSV <file>, and take columns <name> and <value> (<name> and <value> are the number of the columns; defaults are <name>=1 and <value>=2) and save them under the <label> for later. If the optional * is used, the file is read as a string.
Once the file is read, you can fetch the saved values using \getValue:
\getValue <macro> {<name>} {<label>}
\getValue will fetch the <value> column for the respective <name> in the CSV file read under <label>, and save that in the <macro>.
In your example (removing header row and column), you'd have:
\ReadCSV{mydata}{test.csv}
\getValue\rdPar{Third Parameter}{mydata}
\rdPar % prints 7
Here's the expl3 implementation (it is minimalistic: there's no error checking for wrong input, missing data, etc.):
\begin{filecontents*}{test.csv}
Third Parameter , 7
First Parameter , 5
Second Parameter , 3
\end{filecontents*}
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
% Step 1: reading the file
\ior_new:N \l__diaa_csv_ior
\bool_new:N \l__diaa_csv_str_bool
\NewDocumentCommand \ReadCSV { s m >{ \SplitArgument {1} {,} }O{ 1,2 } m }
{
\IfBooleanTF {#1}
{ \bool_set_true:N \l__diaa_csv_str_bool }
{ \bool_set_false:N \l__diaa_csv_str_bool }
\diaa_csv_read:nnnn {#2} #3 {#4}
}
\cs_new_protected:Npn \diaa_csv_read:nnnn #1 #2 #3 #4
{
\prop_new:c { g__diaa_csv_#1_prop }
\ior_open:NnTF \l__diaa_csv_ior {#4}
{ __diaa_csv_read:cnn { g__diaa_csv_#1_prop } {#2} {#3} }
{ \msg_error:nnn { diaa } { file-not-found } {#4} }
}
\msg_new:nnn { diaa } { file-not-found }
{ File~`#1'~not~found. }
\cs_new_protected:Npn __diaa_csv_read:Nnn #1 #2 #3
{
\bool_if:NTF \l__diaa_csv_str_bool
{ \ior_str_map_inline:Nn }
{ \ior_map_inline:Nn }
\l__diaa_csv_ior
{
\prop_put:Nxx #1
{ \clist_item:nn {##1} {#2} }
{ \clist_item:nn {##1} {#3} }
}
}
\cs_generate_variant:Nn __diaa_csv_read:Nnn { c }
%
% Step 2: getting the values
\NewDocumentCommand \getValue { m m m }
{ \tl_set:Nx #1 { \diaa_csv_item:nn {#2} {#3} } }
\NewExpandableDocumentCommand \CSVItem { m m }
{ \diaa_csv_item:nn {#1} {#2} }
\cs_new:Npn \diaa_csv_item:nn #1 #2
{ \prop_item:cn { g__diaa_csv_#2_prop } {#1} }
\ExplSyntaxOff
\begin{document}
\ReadCSV{mydata}{test.csv}
\getValue\rdPar{Third Parameter}{mydata}
\rdPar
\edef\rdPar{\CSVItem{First Parameter}{mydata}}%
\rdPar
\end{document}
.xls(x)is binary), so doing what you want would require 1) to get a full spec of the.xlsxfile format (the easy part) and 2) implement that in LaTeX (the hard, if not impossible part, due to how TeX reads files). That said, if you can export your.xlsxfile to a plain text (usually.csv) format, the solution would be rather easy. – Phelype Oleinik Sep 15 '20 at 01:21\getValue. Also, your tagging implies that you're trying to do this in perl, not tex. Your question is relatively easy to solve if you change your file to a csv. Is that feasible? Or must it be xlsx? – Teepeemm Sep 15 '20 at 01:21