简体   繁体   English

将Excel工作表导出到文本文件

[英]Export excel worksheet to a text file

I would like to know the simplest way to create a text file and then write ALL the data from a worksheet into that file (tab-delimited). 我想知道最简单的方法来创建文本文件,然后将工作表中的所有数据写入该文件(制表符分隔)。 I don't only want to write particular cells into the sheet (I want everything on the worksheet) but also don't want to have to have to write every cell. 我不仅要在工作表中写入特定的单元格(我希望工作表中的所有内容),而且也不必必须写每个单元格。 I know the command for writing cells is like this: 我知道编写单元格的命令是这样的:

open "c:|OUTPUT.txt" for output as #1 print #1, cells(1,2) & cells(2,2) & cells(3,2) ... close 打开“ c:| OUTPUT.txt”以输出为#1打印#1,cells(1,2)和cells(2,2)&cells(3,2)...关闭

but is there a way to just write all the data from the sheet into a txt file? 但是有没有办法将工作表中的所有数据都写入txt文件? I want to run this on a loop for many worksheets. 我想在许多工作表的循环上运行它。

Use the VBA SaveAs method to save it as a .txt by passing xlTextWindows as the FileFormat. 通过将xlTextWindows作为FileFormat传递,使用VBA SaveAs方法将其SaveAs为.txt。

See this page for details on the SaveAs method. 有关SaveAs方法的详细信息,请参SaveAs 页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM