No expansion, no global assignments, no extra packages, no extra column, no ampersand shortcut, just two \foreach loops.
However, the |…| syntax of the matrix library can't be included anymore.
But when you generate the cells you can just use \node[…]{…}; directly (or use the various row …/column …/row … column … styles to change the style of rows, columns or cells.
In your case, just use create matrix={1}{1, ..., 5} and set matrix macro=#2. Which will create 1 row with five columns 1, 2, …, 5 but just putting the column numbers in the nodes.
Code
\documentclass[tikz]{standalone}
\tikzset{
% \protected because \pgfmatrixnextcell and \pgfmatrixendrow expand
% → can't use |…| shortcut, though
matrix node/.style 2 args={
name=\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn,
alias={\tikzmatrixname'-#1-#2}},
set matrix macro/.code=
\protected\def\tikzmatrixcell##1##2{\node[matrix node={##1}{##2}]{#1};},
set matrix macro'/.code=\protected\def\tikzmatrixcell##1##2{#1},
set matrix macro=r#1\,c#2,
create matrix/.style 2 args={
/tikz/matrix/content/.initial=,
/tikz/matrix/create rows/.style={
/tikz/matrix/reset create cell,
/tikz/matrix/create columns/.style={
/tikz/matrix/create cell={##1}{####1}},
/tikz/matrix/create columns/.list={#2},
/tikz/matrix/content/.append=\pgfmatrixendrow},
/tikz/matrix/create rows/.list={#1},
/tikz/node contents=\pgfkeysvalueof{/tikz/matrix/content}},
matrix/reset create cell/.style={
/tikz/matrix/create cell/.style 2 args={
/tikz/matrix/content/.append=\tikzmatrixcell{##1}{##2},
/tikz/matrix/create cell/.style 2 args={
/tikz/matrix/content/.append=
\pgfmatrixnextcell\tikzmatrixcell{####1}{####2}}}}}
\begin{document}
\tikz
\matrix[
draw, column sep=2ex,
set matrix macro=#2, create matrix={1}{1, ..., 5}];
\tikz
\matrix (m) [
draw, column sep=2ex, row sep=1em,
row 1 column 1/.style={set matrix macro=},
column 1/.append style={set matrix macro=row ##1},
row 1/.append style={set matrix macro=column ##2},
set matrix macro=#2#1, % like a spreadsheet
create matrix={0, ..., 8}{0, A, B, ..., E}]
(m'-1-A) edge[out=0, in=180] (m'-4-B);
\end{document}
Output


Too many }'s. – haggai_e Mar 12 '12 at 06:42\nodeinside the\edef, I'll need to put\noexpandthere as well. – haggai_e Mar 12 '12 at 08:13\iinitially, but it did have a\nodein each column. (I updated it now to include\ias well). – haggai_e Mar 12 '12 at 11:38\rowinside thetikzpicture, then\mymatrixcontentwould be local to it. – egreg Feb 12 '21 at 09:26expl3version; the\foreachbased versions need global assignments. – egreg Feb 12 '21 at 10:26column septo the right and/or a node whennodes in empty cellsis true). – Qrrbrbirlbel Aug 02 '23 at 20:57