A simple csv file 610711.csv
:
ooo,aaa,bbb,ccc,ddd,eee,fff
ooa,0.32,0.22,0.99,0.35,1.22,0.19
oob,1.22,1.72,3.27,2.05,3.21,3.27
ooc,4.10,0.32,2.49,1.10,0.52,2.19
A solution with expl3
code:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{csvsimple}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{float}
\begin{document}
\ExplSyntaxOn
\NewDocumentCommand { \getmax } { }
{
\clist_gset:Nx \g_tmpa_clist {\aaa, \bbb, \ccc, \ddd, \eee, \fff}
\clist_sort:Nn \g_tmpa_clist
{
\fp_compare:nNnTF {##1} < {##2}
{ \sort_return_swapped: }
{ \sort_return_same: }
}
\tl_gset:Nx \g_tmpa_tl { \clist_item:Nn \g_tmpa_clist {1} }
}
\NewDocumentCommand { \mynum } { m }
{
\fp_compare:nNnTF { #1 } = { \g_tmpa_tl }
{ \cellcolor{blue!20} \num{#1} }
{ \num{#1} }
}
\ExplSyntaxOff
\def\myasdf{1.5cm}
\begin{table}[htbp]
\sisetup{round-mode=places, round-precision=4}
\centering
\csvreader[tabular=lp{\myasdf}p{\myasdf}p{\myasdf}p{\myasdf}p{\myasdf}p{\myasdf},
table head=\toprule Test Sequence & A & B & C & D & E & F\\ \midrule,
head to column names,
before line=\getmax,
late after last line=\\\bottomrule]
{610711.csv}%
{}%
{\csvcoli & \mynum{\aaa} & \mynum{\bbb} &%
\mynum{\ccc} & \mynum{\ddd} & \mynum{\eee} & \mynum{\fff}
}
\caption{Example Caption}
\label{tab:table1}
\end{table}
\end{document}
Use datatool
's \DTLfetch{<db name>}{<source col>}{<source val>}{<target col>}
to return the value associated with <target col>
where <source col>
is <source val>
in <db name>
(it acts like a lookup-up table).
\documentclass{article}
\begin{filecontents*}[overwrite]{tasks.csv}
task,obj,resources,wp
task1.1,1,2k,1
task2.1,2,3k,2
task3.1,3,4k,3
\end{filecontents*}
\usepackage{datatool}
\begin{document}
% Load the database; later referenced as tasks
\DTLloaddb
[keys={task,obj,resources,wp}]% <options>
{tasks}% <db name>
{tasks.csv}% <filename>
Resources for the first task from Work Package
\DTLfetch{tasks}{task}{task1.1}{wp} %\input{project.csv[task1.1, wp]}
are
\DTLfetch{tasks}{task}{task1.1}{resources} %\input{project.csv[task1.1, resources]}
USD.
\end{document}
Note that spaces in the CSV file are returned, so that'll depend on how you manage spaces within the output (from \DTLfetch
). I've removed them, since typical CSV exports will exclude them.
Best Answer
You can use
where
x
denotes the integer number of a particular row.