Re: [VB6 ] 請問用FileSystemObject來處理Excel檔案
不好意思 因為看到有前輩推文說
不可以用 CommonDialog + FileSystemObject來讀取.xls檔案格式
...我可能表達不夠清楚 我指的讀取是指開啟檔案 然後把資料讀進來
我自己是有看王國榮先生的vb書籍
裡面也是介紹以CommonDialog + FileSystemObject來讀取 存取.txt檔案
我自己有試寫了一下 從結果來看 似乎是只能用CommonDialog 但不能用 FileSystemObject
來開啟.xls檔案 程式碼如下
'以CommonDialog開啟檔案
With CommonDialog1
.CancelError = True
.DialogTitle = "開啟檔案"
.Filter = "Excel格式檔 (*.xls)|*.xls|文書檔 (*.doc;*.txt)|*.doc;*.txt"
.ShowOpen
'用FileSystemObject來開啟.xls檔
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open CommonDialog1.filename
xlApp.Sheets("sheet1").Select
============寫入讀取excel的資料==========
xlApp.Workbooks.Close
xlApp.Quit
Set xlApp = Nothing
End With
不知道有沒有什麼問題? 謝謝
※ 引述《hallfive (sigh)》之銘言:
: 我目前用CommonDialog + FileSystemObject可以成功的開啟並讀取.txt格式的檔案資料
: 語法如下
: '使用CommonDialog物件
: With CommonDialog1
: .CancelError = True
: .DialogTitle = "開啟檔案"
: .Filter = "Excel格式檔 (*.xls)|*.xls|文書檔 (*.doc;*.txt)|*.doc;*.txt"
: .ShowOpen
: '用FileSystemObject來讀取.txt檔
: Set fs = CreateObject("Scripting.FileSystemObject")
: Set txtf = fs.OpenTextFile(.filename, ForReading)
: Temp = txtf.ReadAll
: txtf.Close
: End With
: 那我想請問各位 是否可以用 CommonDialog + FileSystemObject來讀取.xls
: 等excel的格式呢?
: 我直接用這樣的方法開啟.xls檔案 結果程式只偵測出1個資料
: (但其實.txt檔裡有50個資料) 是檔案格式的問題嗎?
: 請問有沒有比較適合讀取excel檔案的方法 謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.195.202.61
※ 編輯: hallfive 來自: 123.195.202.61 (05/09 19:15)
推
05/09 20:34, , 1F
05/09 20:34, 1F
→
05/09 20:35, , 2F
05/09 20:35, 2F
→
05/09 20:43, , 3F
05/09 20:43, 3F
※ 編輯: hallfive 來自: 123.195.202.61 (05/09 20:44)
推
05/09 20:47, , 4F
05/09 20:47, 4F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):