作者hallfive (sigh)
看板Visual_Basic
标题Re: [VB6 ] 请问用FileSystemObject来处理Excel档案
时间Sat May 9 19:14:44 2009
不好意思 因为看到有前辈推文说
不可以用 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)
1F:推 rushcat:那不就是Excel的元件 跟FSO有关系吗@"@ 05/09 20:34
2F:→ rushcat:另外只要给Excel.Application正确路径档名 不会有问题的 05/09 20:35
3F:→ hallfive:抱歉 是我搞错了....恩 感谢指正 05/09 20:43
※ 编辑: hallfive 来自: 123.195.202.61 (05/09 20:44)
4F:推 rushcat:的确不能用FSO读xls档案 但本来就有excel元件可以用阿XD 05/09 20:47