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

3
  • See tex.stackexchange.com/a/207313/161015 Sep 25, 2021 at 15:32
  • I get the idea from there but I don't know how to put more columns than this three. I want to add two more columns. But It don't work for this code
    – IH Pro
    Sep 25, 2021 at 16:30
  • OK, I will add an answer. Sep 25, 2021 at 17:21

1 Answer 1

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
1
  • Thank you very much that was very helpful
    – IH Pro
    Sep 25, 2021 at 21:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .