vba 将多个csv合并为一个工作簿

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26964912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:15:51  来源:igfitidea点击:

Combine multiple csv into one workbook

excelvba

提问by KALAI SELVAN

I have 4 files named inp1.csv, inp2.csv, inp3.csv, inp4.csv in the same folder.

我在同一个文件夹中有 4 个名为 inp1.csv、inp2.csv、inp3.csv、inp4.csv 的文件。

I need combine these files into a single workbook where each file should be in a separate sheet.

我需要将这些文件合并到一个工作簿中,其中每个文件都应该在一个单独的工作表中。

回答by Fred

You can look at a similar question here: Merging a large number of csv datasets

您可以在此处查看类似的问题:Merging a large number of csv datasets

If I understand you correctly, you wish to take multiple csv (i.e. text) files and join them into one. You will then open the resulting csv files in Excel. Is that correct? I should point out the Excel csv's have one tab (worksheet). To get each csv into a separate tab you would need to work with xlsx files.

如果我理解正确,您希望将多个 csv(即文本)文件合并为一个。然后,您将在 Excel 中打开生成的 csv 文件。那是对的吗?我应该指出 Excel csv 有一个选项卡(工作表)。要将每个 csv 放入单独的选项卡中,您需要使用 xlsx 文件。

For the solution referred to above, if you are working in Windows you need to install gawk. It works beautifully in the Windows command line or the PowerShell environment.

对于上面提到的解决方案,如果您在 Windows 中工作,则需要安装 gawk。它可以在 Windows 命令行或 PowerShell 环境中完美运行。