批处理文件,用于在一个Excel工作表中合并大型CSV

时间:2013-11-30 18:19:15

标签: file batch-file

我有一个大的CSV多文件说20-30mb,它有相同的标题但是这些文件的行数不同。我需要一个批处理文件,它将所有CSV文件的内容复制到一个Excel工作表中。

希望你们帮我创建一个批处理文件。我试过创建宏但最后输入错误或不正确的数据。请帮助我

3 个答案:

答案 0 :(得分:1)

for %%a in (*.txt) do @type %%a|find /v "Header line" >newfile.csv
rem open in excel:
newfile.csv

答案 1 :(得分:0)

@echo off
for %%a in (*.csv) do set /P "header=" < "%%a" & goto continue
:continue
(
echo %header%
for %%a in (*.csv) do findstr /V /C:"%header%" < "%%a"
) > large.txt
ren large.txt large.csv

编辑:下面是该程序的一个示例:

C:\Users\Antonio\Documents
>type file1.csv
Common header for all files
File One line one
File One line two
File One line three

C:\Users\Antonio\Documents
>type file2.csv
Common header for all files
File Two line one
File Two line two
File Two line three

C:\Users\Antonio\Documents
>type file3.csv
Common header for all files
File Three line one
File Three line two
File Three line three

C:\Users\Antonio\Documents
>test

C:\Users\Antonio\Documents
>type large.csv
Common header for all files
File One line one
File One line two
File One line three
File Two line one
File Two line two
File Two line three
File Three line one
File Three line two
File Three line three

答案 2 :(得分:0)

如果CSV文件中的行数少于65K,那么这将起作用:

最终的CSV文件可以有超过65K行。

@echo off
set "flag="
for %%a in (*.csv) do (
   if not defined flag (
      copy "%%a" temp.tmp & set flag=1
    ) else (
      more +2 "%%a" >>temp.tmp
    )
)
ren temp.tmp "newfile.csv"