2011-04-05 119 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