2011-04-05 170 views

回答

5

其實,有此COM組件。它的程序是「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 !,很不是它)。

0

%WINDIR%\ Syswow64資料\ Cscript.exe將ExcelSheetName.vbs

ExcelSheetName.vbs:

Const ArrSize = 100 

Dim ArrSheetName() 

ReDim ArrSheetName(ArrSize) 

IndexArr = 0 



Dim ExcelFileName 

ExcelFileName = "D:\1\ExcelSrc.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