如何从VBScript读取Excel文件?

问题描述 投票:0回答:3

我试图在VBScript中读取一个Excel文件,但在file.Readline我得到了奇怪的字符。你知道如何正确获得细胞的价值吗?没有Excel库。

Dim fso,file
Set fso  = Server.CreateObject("Scripting.FileSystemObject")
Set dict = CreateObject("Scripting.Dictionary")        
Set file = fso.OpenTextFile ("C:\myFile.xlsx",1)
row = 0
Do Until file.AtEndOfStream
    line = file.Readline
    dict.Add row, line
    row = row + 1
Loop
file.Close
vbscript asp-classic xlsx filesystemobject
3个回答
0
投票

如果你在excel中编写宏(也是可视化基本脚本),获取单元格值的方法不止一种。有范围功能(例如来自web :)工作表(“Sheet1”)。范围(“A5”)。值有单元格功能(来自web的示例)单元格(1,1)。

excel文件(xslx)实际上应该是zip文件,其中数据是xml。我想这就是为什么如果你使用VB编译器就无法阅读它。


0
投票

您很可能需要将页面的编码设置为UTF-8。请参阅前面的链接以获得简单描述:

Classic ASP text substitution and UTF-8 encoding https://www.w3schools.com/asp/prop_charset.asp

所以它看起来像下面的,位于页面顶部附近:

Response.Charset = "UTF-8"

0
投票

我已经使用扩展名.CSV解决了我的问题,因为这允许我以.txt的形式读取信息,其中默认情况下每个列都用逗号分隔,因此我的代码正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.