我需要帮助将同一行插入 excel 文件并将其保存到不同的目录。文件名和 D 列值每次都会不同,但其余的行 1 到 6 的值相同。在第 7 行,D 列取 D 列、第 2 到第 6 行的平均值。是否有批处理脚本可以插入第 7 行和公式并将其保存到另一个目录?
分析数据 | 元素名称 | 象征 | 实际的 | 名义 | 偏差 | U-Tol。 | L-Tol。 | 奥托尔 | 合格/不合格 |
---|---|---|---|---|---|---|---|---|---|
1.粗糙度[喷砂位置1] | 镭 | 3.5142 | 50 | 2.1 | 好的 | ||||
2.粗糙度[喷砂位置2] | 镭 | 3.3612 | 50 | 2.1 | 好的 | ||||
3.粗糙度[喷砂位置3] | 镭 | 3.5808 | 50 | 2.1 | 好的 | ||||
4.粗糙度[喷砂位置4] | 镭 | 3.4778 | 50 | 2.1 | 好的 | ||||
5.粗糙度[喷砂位置5] | 镭 | 3.3631 | 50 | 2.1 | 好的 | ||||
6.粗糙度[喷砂位置平均值] | 镭 | 3.45942 | 50 | 2.1 | 好的 |
下面是我尝试过的,它插入了信息但删除了其他所有内容。
@Echo off & Setlocal EnableExtensions EnableDelayedExpansion
Set Row=0
( for /f "tokens=1-9 delims=," %%A in ("C:\temp\Surfcom*.csv") do (
Set /A Row+=7
If !Row! lss 6 (
Rem new header
echo "Analysis data","Element Name","Symbol","Actual","Nominal","Deviation","U-Tol.","O-Tol","OK/NG"
) Else
(Rem insert new empty rows
echo "6.Roughness [Blast Position Average]","","Ra","=Sum(D2:D6)/5","","","50","2.1","OK"
)
)
) > "myfile.tmp"
move /y "myfile.tmp" "myfile.csv"
答案1
它插入了信息,但删除了其他所有内容
这就是你告诉它要做的事情:
If !Row! lss 6 (
Rem new header
echo "Analysis data","Element Name","Symbol","Actual","Nominal","Deviation","U-Tol.","O-Tol","OK/NG"
) Else
(Rem insert new empty rows
echo "6.Roughness [Blast Position Average]","","Ra","=Sum(D2:D6)/5","","","50","2.1","OK"
)
您没有复制现有的行。请尝试以下操作:
If !Row! lss 6 (
echo %%A
) Else
(Rem insert new row
echo "6.Roughness [Blast Position Average]","","Ra","=Sum(D2:D6)/5","","","50","2.1","OK"
)