将Excel列导出到多个文本文件 [英] export excel columns into multiple text files
本文介绍了将Excel列导出到多个文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将[A ... N]列中收集的数据[1 ... M]拆分为单独的文本文件,命名为每列的第一个单元格.
I need to split data [1...M] gathered in columns [A...N] into separate text files named as first cell of each column.
以excel排列的数据:
Data arranged in excel:
FileName_A |FileName_B |FileName_C |… |FileName_N
Data_A1 |Data_B1 |Data_C1 |… |Data_N1
Data_A2 |Data_B2 |Data_C2 |… |Data_N2
Data_A3 |Data_B3 |Data_C3 |… |Data_N3
… … … … …
DataA_AM DataA_BM DataA_CM DataA_AM DataA_NM
____________________________________________________________________________
应写入文件名
FileName_A.tex应该看起来像:
FileName_A.tex should look like:
_____________
Data_A1
Data_A2
Data_A3
…
DataA_AM
____________
我尝试过,但是...
I´ve tried, but...
尽管对于专家而言,这似乎是一件容易的事,但对我来说却是一个巨大的障碍,因为我对编码不熟悉.
Altough it seems an easy task for an expert, it is quite a huge obsticle for me becouse I am not familiar with coding.
非常感谢您的提前支持.
Thank You very much for support in advance.
推荐答案
在下面尝试代码.
Sub export_data()
Dim row, column, i, j As Integer
Dim fullPath, myFile As String
fullPath = "C:\Workspace"
row = 21
column = 5
For i = 1 To column
myFile = Cells(1, i).Value + ".txt"
myFile = fullPath + "/" + myFile
Open myFile For Output As #1
For j = 2 To row
Print #1, Cells(j, i).Value
Next j
Close #1
Next i
End Sub
您可以更改行号和列号.您的第一行始终是标题.请参见下面的Excel图片
You can change Row number and Column number. Your First row is always Header. See Image below for Excel
这篇关于将Excel列导出到多个文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文