Not the same syntax, but I believe it's sufficient nonetheless.
\documentclass{ctexbook}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage{CJKnumb}
\newcounter{ncolumns}
\setcounter{ncolumns}{5}
\ExplSyntaxOn
% we need LaTeX counters and not expl3 ones because of tabularx two-step process
\newcounter{repeatstart}
\newcounter{repeatcurrent}
\newcounter{repeatlast}
\NewDocumentCommand{\repeatcell}{mm}
{% #1 = number of repeats
% #2 = key-value pairs
\oaheix_repeatcell:nn { #1 } { #2 }
}
\tl_new:N \l__oaheix_repeatcells_body_tl
\keys_define:nn { oaheix/repeatcells }
{
text .code:n = \cs_gset_protected:Nn \__oaheix_repeatcell_text:n { #1 },
start .code:n = \setcounter{repeatstart}{#1},
}
\cs_new_protected:Nn \oaheix_repeatcell:nn
{
\keys_set:nn { oaheix/repeatcells } { #2 }
\tl_clear:N \l__oaheix_repeatcells_body_tl
\int_step_inline:nnn
{ \value{repeatstart} + 1 }
{ \value{repeatstart} + #1 }
{
\tl_put_right:Nx \l__oaheix_repeatcells_body_tl
{
\int_compare:nF { ##1 = \value{repeatstart} + 1 } { & }
\__oaheix_repeatcell_text:n { ##1 }
}
}
\tl_use:N \l__oaheix_repeatcells_body_tl
\setcounter{repeatlast} { \int_eval:n { \value{repeatstart} + #1 } }
}
\NewExpandableDocumentCommand{\lastvalue}{}{\int_eval:n { \value{repeatlast} } }
\AtBeginEnvironment{tabularx}{\setcounter{repeatstart}{0}}
\ExplSyntaxOff
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{*{\value{ncolumns}}{|X<{\centering}}|}
\hline
\repeatcell{\value{ncolumns}}{text = \CJKnumber{#1}} \\
\hline
\eline{\value{ncolumns}} \\
\hline
\repeatcell{\value{ncolumns}}{start=\lastvalue, text = \CJKnumber{#1}} \\
\hline
\eline{\value{ncolumns}} \\
\hline
\end{tabularx}
\bigskip
% repeat to show the numbers are correct
\noindent
\begin{tabularx}{\textwidth}{*{\value{ncolumns}}{|X<{\centering}}|}
\hline
\repeatcell{\value{ncolumns}}{text = #1} \\
\hline
\eline{\value{ncolumns}} \\
\hline
\repeatcell{\value{ncolumns}}{start=\lastvalue, text = #1} \\
\hline
\eline{\value{ncolumns}} \\
\hline
\end{tabularx}
\end{document}
Note you don't use \c
for the current column index, but rather #1
. The last value used is stored as \lastvalue
.