婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 用vbs讀取Excel文件的函數代碼

用vbs讀取Excel文件的函數代碼

熱門標簽:辦理膠州400電話財稅 外呼營銷下單系統 加盟電銷機器人好的品牌 海外美發店地圖標注 百度地圖標注怎么卸載 打電話的外呼系統貴不貴 陜西高頻外呼回撥系統哪家好 前鋒辦理400電話申請 新密防封卡外呼系統違法嗎
核心代碼
復制代碼 代碼如下:

Function ReadExcel( myXlsFile, mySheet, my1stCell, myLastCell, blnHeader )
' Function : ReadExcel
' Version : 2.00
' This function reads data from an Excel sheet without using MS-Office
'
' Arguments:
' myXlsFile [string] The path and file name of the Excel file
' mySheet [string] The name of the worksheet used (e.g. "Sheet1")
' my1stCell [string] The index of the first cell to be read (e.g. "A1")
' myLastCell [string] The index of the last cell to be read (e.g. "D100")
' blnHeader [boolean] True if the first row in the sheet is a header
'
' Returns:
' The values read from the Excel sheet are returned in a two-dimensional
' array; the first dimension holds the columns, the second dimension holds
' the rows read from the Excel sheet.
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
Dim arrData( ), i, j
Dim objExcel, objRS
Dim strHeader, strRange

Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3

' Define header parameter string for Excel object
If blnHeader Then
strHeader = "HDR=YES;"
Else
strHeader = "HDR=NO;"
End If

' Open the object for the Excel file
Set objExcel = CreateObject( "ADODB.Connection" )
' IMEX=1 includes cell content of any format; tip by Thomas Willig
objExcel.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
myXlsFile ";Extended Properties=""Excel 8.0;IMEX=1;" _
strHeader """"

' Open a recordset object for the sheet and range
Set objRS = CreateObject( "ADODB.Recordset" )
strRange = mySheet "$" my1stCell ":" myLastCell
objRS.Open "Select * from [" strRange "]", objExcel, adOpenStatic

' Read the data from the Excel sheet
i = 0
Do Until objRS.EOF
' Stop reading when an empty row is encountered in the Excel sheet
If IsNull( objRS.Fields(0).Value ) Or Trim( objRS.Fields(0).Value ) = "" Then Exit Do
' Add a new row to the output array
ReDim Preserve arrData( objRS.Fields.Count - 1, i )
' Copy the Excel sheet's row values to the array "row"
' IsNull test credits: Adriaan Westra
For j = 0 To objRS.Fields.Count - 1
If IsNull( objRS.Fields(j).Value ) Then
arrData( j, i ) = ""
Else
arrData( j, i ) = Trim( objRS.Fields(j).Value )
End If
Next
' Move to the next row
objRS.MoveNext
' Increment the array "row" number
i = i + 1
Loop

' Close the file and release the objects
objRS.Close
objExcel.Close
Set objRS = Nothing
Set objExcel = Nothing

' Return the results
ReadExcel = arrData
End Function

使用方法:
復制代碼 代碼如下:

Option Explicit

Dim arrSheet, intCount

' Read and display columns A,B, rows 2..6 of "ReadExcelTest.xls"
arrSheet = ReadExcel( "ReadExcelTest.xls", "Sheet1", "A1", "B6", True )
For intCount = 0 To UBound( arrSheet, 2 )
WScript.Echo arrSheet( 0, intCount ) vbTab arrSheet( 1, intCount )
Next

WScript.Echo "==============="

' An alternative way to get the same results
arrSheet = ReadExcel( "ReadExcelTest.xls", "Sheet1", "A2", "B6", False )
For intCount = 0 To UBound( arrSheet, 2 )
WScript.Echo arrSheet( 0, intCount ) vbTab arrSheet( 1, intCount )
Next
您可能感興趣的文章:
  • C#數據導入/導出Excel文件及winForm導出Execl總結
  • php讀取EXCEL文件 php excelreader讀取excel文件
  • Asp.net生成Excel文件并下載(更新:解決使用迅雷下載頁面而不是文件的問題)
  • PHPExcel讀取Excel文件的實現代碼
  • 將datagrid控件內容輸出到excel文件
  • .NET中讀取Excel文件的數據及excelReader應用

標簽:伊春 梅州 阜陽 咸陽 河南 四平 牡丹江 武威

巨人網絡通訊聲明:本文標題《用vbs讀取Excel文件的函數代碼》,本文關鍵詞  用,vbs,讀取,Excel,文件,的,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《用vbs讀取Excel文件的函數代碼》相關的同類信息!
  • 本頁收集關于用vbs讀取Excel文件的函數代碼的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 文安县| 茂名市| 年辖:市辖区| 吴堡县| 松江区| 双流县| 织金县| 方正县| 江口县| 织金县| 长沙县| 庆元县| 扬中市| 资源县| 乐平市| 景洪市| 云梦县| 金门县| 蓬溪县| 凤凰县| 浦北县| 泗阳县| 西乌| 云南省| 旺苍县| 嘉义市| 民丰县| 南平市| 日土县| 乡宁县| 永城市| 白朗县| 陆良县| 桂东县| 桓台县| 来凤县| 图木舒克市| 东乡县| 肥东县| 桐梓县| 延寿县|