【问题标题】:Saving each excel column data to separate textfiles将每个 excel 列数据保存到单独的文本文件中
【发布时间】:2018-12-08 14:14:04
【问题描述】:

有没有一种简单的方法可以将填充在 N 列中的 Excel 数据保存到 N 个相应的文本文件中?

如果N=3,则数据保存为columnA.txt、columnB.txt、columnC.txt,分别对应excel列A、B、C中的数据。

【问题讨论】:

  • 为什么我的研究工作会有所欠缺?这个问题很老套,但很清楚。

标签: excel file text save


【解决方案1】:

尝试使用下面的代码。我假设列数= 3;您可以通过修改“For lngColumn = 1 To 3”行来更改它。所有 3 个 txt 文件都被保存到您的 C: 驱动器(也可以在“strFile”行中更改)。

Sub SaveText()
    Dim lngColumn           As Long
    Dim lngRow              As Long
    Dim strFile             As String

    With Sheet1
        For lngColumn = 1 To 3
            strFile = "F:\Column" & lngColumn & ".txt"
            For lngRow = 1 To .Cells(1, lngColumn).End(xlDown).Row
                Open strFile For Append As #1
                Write #1, .Cells(lngRow, lngColumn).Value
                Close #1
            Next lngRow
        Next lngColumn
    End With
End Sub

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    相关资源
    最近更新 更多