我是靠谱客的博主 欢喜电灯胆,最近开发中收集的这篇文章主要介绍EXCEL 读取txt文本数据,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

在一个txt文本文件中存有一下格式数据

Your Merchant Order ID: # xxxxxxx
Purchase Date: February 2, 2009 10:17:30 AM PST
Shipping Service: Standard
Buyer Name: John Doe
Buyer E-mail: none@none.com

Your Merchant Order ID: # xxxxxxx
Purchase Date: February 2, 2009 10:17:30 AM PST
Shipping Service: Standard
Buyer Name: John Doe
Buyer E-mail: none@none.com
希望转换数据到excel文件中,并在一行显示同一记录。

Order IDPurchaseDateShippingServiceBuyerNameBuyerE-mail
# xxxxxxxFebruary 2, 2009 10StandardJohn Doenone@none.com
# xxxxxxxFebruary 2, 2009 10StandardJohn Doenone@none.com

 

Sub  DataRead()
  
Set  fs  =   CreateObject ( " Scripting.FileSystemObject " )
  Open ActiveWorkbook.Path 
&   " "   &   " ok.txt "   For  Input  As  # 1
  i 
=   2
  
Do   While   Not  EOF( 1 )
        Line Input #
1 , txt
        
Dim  a
        a 
=   Split (txt,  " : " )
        
If   InStr (txt,  " Order ID " >   0   Then
                Cells(i, 
1 =   Trim (a( 1 ))
        
ElseIf   InStr (txt,  " Purchase Date " >   0   Then
                Cells(i, 
2 =   Trim (a( 1 ))
        
ElseIf   InStr (txt,  " Shipping Service " >   0   Then
                Cells(i, 
3 =   Trim (a( 1 ))
        
ElseIf   InStr (txt,  " Buyer Name " >   0   Then
                Cells(i, 
4 =   Trim (a( 1 ))
        
ElseIf   InStr (txt,  " Buyer E-mail " >   0   Then
                Cells(i, 
5 =   Trim (a( 1 ))
                i 
=  i  +   1
        
End   If
  
Loop
  Close #
1
  
End Sub

 

转载于:https://www.cnblogs.com/lwl0606/archive/2009/02/05/1384393.html

最后

以上就是欢喜电灯胆为你收集整理的EXCEL 读取txt文本数据的全部内容,希望文章能够帮你解决EXCEL 读取txt文本数据所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(81)

评论列表共有 0 条评论

立即
投稿
返回
顶部