我有一个大约100 cols的Excel工作表。有谁知道将每列的内容写入csv或txt文件的简单方法吗?将每个Excel列导出到单个文本或csv文件?
0
A
回答
0
我没有在我面前的Excel,但我认为这个代码大概是你所需要的,给出或采取一些语法错误。它应该将每列写入一个单独的文件,每个单元格放在不同的行上。它将适用于任意列高度,尽管列数在变量中(现在)。
dim fso as FileSystemObject
dim ts as TextStream
dim i as Integer
dim myCell as Range
set fso = FileSystemObject
for i = 0 to TotalColumnNumber
' last argument, True, says to create the text file if it doesnt exist, which is
' good for us in this case
Set ts = fso.OpenTextFile("column_" & i, ForWriting, True)
' set mycell to the first cell in the ith column
set myCell = SheetName.cells(1,i)
' continue looping down the column until you reach a blank cell
' writing each cell value as you go
do until mycell.value = ""
ts.writeline mycell.value
set myCell = myCell.offset(1,0)
loop
ts.close
next
set ts = nothing
set fso = nothing
让我知道这是否有助于或没有,我可以在以后再看看,如果你想
0
也许
Dim cn As Object
Dim rs As Object
Dim strFile As String
Dim strCon As String
Dim strSQL As String
Dim i As Integer
''This is not the best way to refer to the workbook
''you want, but it is very conveient for notes
''It is probably best to use the name of the workbook.
strFile = ActiveWorkbook.FullName
''Note that if HDR=No, F1,F2 etc are used for column names,
''if HDR=Yes, the names in the first row of the range
''can be used.
''This is the Jet 4 connection string, you can get more
''here : http://www.connectionstrings.com/excel
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
& ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"
''Late binding, so no reference is needed
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open strCon
''WHERE 1=1 = headers only, note hdr=yes above
strSQL = "SELECT * " _
& "FROM [Sheet1$] " _
& "WHERE 1=1"
''Open the recordset for more processing
''Cursor Type: 3, adOpenStatic
''Lock Type: 3, adLockOptimistic
''Not everything can be done with every cirsor type and
''lock type. See http://www.w3schools.com/ado/met_rs_open.asp
rs.Open strSQL, cn, 3, 3
''Output including nulls. Note that this will fail if the file
''exists.
For i = 0 To rs.Fields.Count - 1
strSQL = "SELECT [" & rs.Fields(i).Name & "] " _
& "INTO [Text;HDR=YES;FMT=Delimited;IMEX=2;DATABASE=C:\Docs\]." _
& rs.Fields(i).Name & ".CSV " _
& "FROM [Sheet1$] "
''To skip nulls and empty cells, add a WHERE statement
''& "WHERE Trim([" & rs.Fields(i).Name & "] & '')<>'' "
cn.Execute strSQL
Next
''Tidy up
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
0
非常快线,让你开始...
for i = 1 to 100
open "file" & i & ".txt" as #1
for each c in columns(i).cells
print #1, c.value
next c
close #1
next i
相关问题
- 1. PowerShell:将每行CSV导出到单个文件
- 2. 将多个文本/ csv文件导入到单个Excel工作表中
- 3. 将CSV文件导出到Excel 2007
- 4. 使用BAT脚本将CSV文件中的每个人导出到XAML文件
- 5. 将单列csv文件合并到单个csv文件中
- 6. 将Excel导出到文本文件
- 7. 如何将多个.xls(Excel)文件导出到一个.csv文件中?
- 8. 到多个文本文件的VBA Excel-导出特定列
- 9. 将多个查询结果导出到单个Excel文件
- 10. 将C#列表导出到Csv文件
- 11. jQuery DataTables:将单个列导出到Excel
- 12. 将TFS 2010历史记录导出到Excel或文本文件
- 13. 将多个文本文件导入Excel
- 14. 如何将单个列表导出为csv文件?
- 15. 将Python输出导出为CSV或文本文件(初学者)
- 16. 将数据导出到单个CSV文件
- 17. 将Lotus Notes文档导出到CSV和Excel文件
- 18. 将Iibre office数据库表导出到文本文件或csv文件
- 19. 我可以将多个文本文件导入到一个Excel表单中吗?
- 20. 将HTML表格导出为文本或CSV文件
- 21. 将文本文件的标题和内容导出到单独的Excel列中?
- 22. 将多个.csv文件导入到R
- 23. 的Python:导出文本列表到一个文本文件
- 24. 将PowerShell脚本导出为单个CSV
- 25. 将单元格数组导出到多列csv文件
- 26. 将文本文件导入到excel中 - 每遇到一个单词时都会启动一个新行
- 27. 将一个大的.csv文件导入到Excel中,
- 28. 如何将每个excel行导出为单独的单词文件?
- 29. 使用python从csv解析出单个文本文本到文本文件
- 30. 将单个CSV文件导入到MySQL中的多个表中