# Write "conditionnally" rows of a tabular with spreadtab

I'm writing a tabular using the spreadtab package for some calculus. I want to write it's rows only under a certain condition, i.e. to test in each of its rows if the condition is true, and then write this row, and not write the row it if the condition is false. All is ok when I do this in a tabular environment, like in this example, where the line of 3 is not written, because '1=2' is false:

Tabular\\
\begin{tabular}{|c|c|}
\hline
1&1         \\  \hline
\ifnum 1=1 2&2 \fi \\ \hline
\ifnum 1=2 3&3 \\ \hline\fi
\ifnum 1=1 4&4 \fi \\ \hline
\end{tabular}
\\
End of Tabular


which compiles well like this: Now if I insert the same tabular in a spreadtab environment, like in this macro:

\begin{spreadtab}{{tabular}{|c|c|}}
\hline
1&1\\
\ifnum 1=1 2&2 \fi \\ \hline
\ifnum 1=2 3&3 \\ \hline\fi
\ifnum 1=1 4&4 \fi \\ \hline


The program doesn't compile and I have this message of error:

! Undefined control sequence.
<argument> 2 \fi \@@nil
&


what is the problem in my program and how can I repair it ? Thank you

• The problem with tabular is that it uses its own parser. If it is simple enough, you can replace tabular with lots of \makebox'es. Dec 26, 2015 at 4:40
• The problem is that it's not simple but I have simplified it. I use this test in statistical calculus Dec 26, 2015 at 5:48

If you want to put only text in a cell with spreadtab you simply place somewhere in the cell the character @, this answer show how you can skip & inside the conditional.

The command \condRow with three arguments test if the first argument is equal to 1, the first and second cells of tabular will be the second and third argument of the command.

\documentclass{article}

\begin{document}

\newcommand{\condRow}[3]{\ifnum \numexpr#1\relax=1  #2\uppercase{&}#3\\\fi
\ifnum \numexpr#1\relax=1 \hline\fi}

\hline
1&1\\ \hline
@\condRow{1}{34}{202}
3&3\\ \hline
4&4\\ \hline