c# - 如何在不打开另一个工作簿/excel 应用程序的情况下将外部数据(.csv 文件)导入为新工作表

发布于 2024-09-28 18:56:34 字数 499 浏览 0 评论 0原文

我的目标是打开许多 .csv 文件,每个文件都位于同一 Excel 工作簿的新工作表中,而不需要为每个文件打开一个工作簿。

我注意到 Open() 或 OpenText() 方法属于 workBook 类,使用它们意味着打开一个新的工作簿。

更清楚地说,普通用户只需在 Excel 2003 中选择以下选项即可执行此操作: 数据>导入外部数据>导入数据...>> (然后选择 .csv 文件并按照向导操作)。 此方案将授予用户在新工作表中打开 .csv 文件的能力。 此外,还可以选择分隔符、文本限定符和数据格式,其方式与使用 workBook.OpenText() 方法类似。

我设法通过在单独的工作簿中打开每个 .csv 文件,然后将其复制到目标 Excel 工作簿中的新工作表来完成此操作。这似乎是一种笨拙的方法,我认为它需要更多时间(我在这里处理许多 .csv 文件)。

我试着到处寻找。难道这件事不能通过“Microsoft Excel 11.0 对象库”实现吗?

谢谢

My target is to open many .csv files, each of them in a new workSheet in the same excel workBook, without opening a workBook for each.

I noticed that the Open() or OpenText() methods belong to the workBook class and using them means opening a new workBook.

To be more clear, a regular user would simply do this in Excel 2003 by selecting:
Data > Import External Data > Import Data... > (then selecting a .csv file and go along with the wizard).
This scenario will grant the user an ability to open the .csv file to a new workSheet.
Also, it is possible to choose the Delimiters, Text Qualifier and Data Format, in a similar manner as using the workBook.OpenText() method.

I managed to do it by opening each .csv file in a seperate workBook and then copying it to a new workSheet in the target excel workBook. It seems kind of a clumsy way to do and i think it requires more time (im dealing with many .csv files here).

I tried searching everywhere. could it be that this thing is not possible via "Microsoft Excel 11.0 Object Library" ??

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴我心暖 2024-10-05 18:56:34

你必须使用工作簿来一一打开它们,但你可以改进它:

我设法通过打开每个
.csv 文件位于单独的工作簿中,并且
然后将其复制到新的工作表中
目标 Excel 工作簿。

只需使用一个工作簿对象打开每个 CSV 文件,并将打开的工作表复制到另一个工作簿对象(作为您的基簿),以将它们存储在单独的工作表中。

You have to use workbook to open them one by one, but you can improve it:

I managed to do it by opening each
.csv file in a seperate workBook and
then copying it to a new workSheet in
the target excel workBook.

Just use one workbook object to open each CSV file and copy the opened worksheet over to another workbook object (as your basebook) to store them in separate workssheets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文