如何阅读WSH的电子表格?

我需要在WSH下使用JScript从.xls文件中读取一些单元格值。 是否有任何COM对象或任何我可以用来做的事情?     
已邀请:
实际上有一个COM组件。它的progId是“Excel.Application”,你可以像这样使用它:
var XLS = WScript.CreateObject("Excel.Application") ;
XLS.Workbooks.open(xlsFile) ;
var cellValue = XLS.Cells(row,col).Value ;
而已。就如此容易。变量
cellValue
现在保持单元格中的值(
row
col
)。 如果这还不够好,
xlsFile
可能是文件或URL的路径(是的,一个URL!,不是很好)。     
您可以使用ADO读取值... http://technet.microsoft.com/en-us/library/ee692882.aspx     
%windir% SysWOW64 cscript.exe ExcelSheetName.vbs ExcelSheetName.vbs:
Const ArrSize = 100

Dim ArrSheetName()

ReDim ArrSheetName(ArrSize)

IndexArr = 0



Dim ExcelFileName

ExcelFileName = "D:1ExcelSrc.xls"


Dim ADOCatalog, ADOTable, ADODBConnection

Set ADOCatalog      = Createobject("ADOX.Catalog")

Set ADOTable        = Createobject("ADOX.Table")

Set ADODBConnection = CreateObject("ADODB.Connection")


Dim strConnString, strSheetName

strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ExcelFileName & ";Extended Properties=Excel 8.0;"


ADODBConnection.Open strConnString

Set ADOCatalog.ActiveConnection = ADODBConnection


For Each ADOTable In ADOCatalog.Tables

    strSheetName = ADOTable.Name

    strSheetName = Replace(strSheetName, "'", "")

    strSheetName = Left(strSheetName, InStr(1, strSheetName, "$", 1) - 1)

    'Wscript.Echo strSheetName

    ArrSheetName(IndexArr)=strSheetName

    IndexArr=IndexArr+1

Next

ReDim Preserve ArrSheetName(IndexArr-1)

ADODBConnection.Close

Set ADOCatalog      = Nothing

Set ADOTable        = Nothing

Set ADODBConnection = Nothing


For Each ArrValue in ArrSheetName

    Wscript.Echo ArrValue

Next
    

要回复问题请先登录注册