![使用以下结构在电子表格中导入 tex 数据](https://linux22.com/image/439920/%E4%BD%BF%E7%94%A8%E4%BB%A5%E4%B8%8B%E7%BB%93%E6%9E%84%E5%9C%A8%E7%94%B5%E5%AD%90%E8%A1%A8%E6%A0%BC%E4%B8%AD%E5%AF%BC%E5%85%A5%20tex%20%E6%95%B0%E6%8D%AE.png)
我想在电子表格中导入 products.tex。products.tex 的内容是
@ Plant & 1 & 60 & 2 & 77 \\
@ Book & 2 & 90 & 4 & 64 \\
@ Other & 3 & 100 & 10 & 6 \\
我想将其导入下表
\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}
我不知道如何实现它。非常感谢你的帮助
答案1
尝试此代码。基于在 Spreadtab 环境中使用输入
\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}
文件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