Mit savebox und newcommand:
`PS: Falls es jmd. einfacher lösen kann, gerne.`
[![alt text][1]][1]
\documentclass[]{article}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\pgfplotstableset{string type, col sep=comma, header=false}
\pgfplotstableread[]{
a, b, c
d, e, f
g, x, i
j, k, l
}\mytable
\colorlet{CellColor}{red}
\colorlet{RowColor}{orange}
\colorlet{ColColor}{pink}
\def\literalx{x}
%\def\remembercol{-1}
%\def\rememberrow{-1}
\begin{document}
\pgfplotstableset{ myhighlights/.style={} }
\newcommand\MyTable{%
\pgfplotstabletypeset[myhighlights,
postproc cell content/.code={%
\def\temp{##1}% <--- ! '##', not '#'
\ifx\temp\literalx
\xdef\remembercol{\pgfplotstablecol}%
\xdef\rememberrow{\pgfplotstablerow}%
% Highlight Cell:
\pgfkeysalso{ @cell content/.add={\cellcolor{CellColor}}{} }%
\fi
},
]{\mytable}%
}
\newsavebox{\Mybox}
\savebox{\Mybox}{\MyTable}
\section{Raw Table}
\usebox{\Mybox}
\section{Read out row and column -- works}
x is in row no.~\rememberrow\ and column no.~\remembercol.
\def\y{0}
\section{Typeset highlighted Table -- works as well}
\pgfplotstableset{myhighlights/.style={%% =======
% Highlight Row:
every row no \rememberrow/.style={before row={\rowcolor{RowColor}}},
% Highlight Column:
columns/\remembercol/.style={
column type/.add={>{\columncolor{ColColor}}}{} },
}%% =======
}
\MyTable
\end{document}
[1]: https://texwelt.de/upfiles/5555555_4.png