0

I want to import a products.tex in a spreadtab. The content of the products.tex is

@ Plant & 1 &  60 &  2 & 77 \\
@ Book  & 2 &  90 &  4 & 64 \\
@ Other & 3 & 100 & 10 &  6 \\

and I want to import it in the following table

\begin{document}
    \begin{spreadtab}{{tabular}{lcc}}
        \toprule
        @ Product name & @ Number & @ Price & @ Count & Count2 \\
        \midrule
        \input{products}
        \midrule
        @ Total & &:={sumprod(b2:[0,-1];c2:[1,-1])} & sum(c2:[0,-1])& sum(d2:[0,-1])\\
        \bottomrule
    \end{spreadtab}
\end{document}

I have no Idea how to implement it. I would be very thankful for your help

Simon Dispa
  • 39,141
IH Pro
  • 141

1 Answers1

1

a

Try this code. Based on use-input-inside-a-spreadtab-environment

\documentclass{article}

\usepackage{spreadtab,booktabs,xpatch}

% From https://tex.stackexchange.com/a/207313/161015 ************************** \makeatletter \def\spreadtab@ii{\IfSubStr\ST@tab{\noexpand\input}{\expandafter\spreadtab@iii\ST@tab@nil}\relax} \def\spreadtab@iii#1\input#2#3@nil{% \long\def\spreadtab@iv##1\spreadtab@iv{\endgroup\def\ST@tab{#1##1#3}\spreadtab@ii}% \begingroup \everyeof{\spreadtab@iv\noexpand}% \expandafter\spreadtab@iv@@input#2 } \xpretocmd\spreadtab@i\spreadtab@ii{}{} \makeatother
%**************************************************

\begin{document} \begin{spreadtab}{{tabular}{lcccc}} \toprule %% col a & col b & col c & col d & col e <<<<<<<<<<<<<<<< @ Product name & @ Number & @ Price & @ Count & @ Count2 \ \midrule \input{products} \midrule @ Total & &:={sumprod(b2:b4;c2:c4)} & sum(d2:d4)& sum(e2:e4)\ \bottomrule \end{spreadtab} \end{document}

The file products.tex

%% File products.tex

@ Plant & 1 & 60 & 2 & 77 \ % row 2 @ Book & 2 & 90 & 4 & 64 \ % row 3 @ Other & 3 & 100 & 10 & 6 \ % row 4

Simon Dispa
  • 39,141