ntCol).value =arrValue(i-intFromRow)
Next
‘写入完成后,保存EXCEL
ExcelApp.DisplayAlerts=False
ExcelApp.Save
‘关闭Excel
closeExcelSheet ExcelBook,ExcelApp,ExcelSheet
End Sub
‘******************************************************
‘Function:读Excel中某一行的值
‘Input parameter:
‘strFilePath:保存Excel的文件路径
‘strExcelSheetName:要读取的Excel中Sheet的名称
‘intRow:读取哪一行的数据
‘For example:”E:\a.xls”,”Sheet1″,1
‘Return:取到的值
‘******************************************************
function getRowValues(strFilePath,strSheetName,intRow)
‘定义变量
Dim ExcelApp,ExcelBook,ExcelSheet,intColumnsCount,arrValues()
‘创建EXCEL程序,打开工作簿,设置当前活动sheet
Set ExcelApp = CreateObject(“Excel.Application”)
Set ExcelBook = ExcelApp.WorkBooks.Open(strFilePath)
Set ExcelSheet = ExcelBook.WorkSheets(strSheetName)
‘得到excel中共有几列
intColumnsCount =ExcelBook.ActiveSheet.UsedRange.Columns.count
‘获取excel中值
Redim Preserve arrValues(intColumnsCount -1)
For i=1 to intColumnsCount
arrValues(i-1) = ExcelSheet.Cells(intRow,i)
Next
‘返回值
getRowValues=arrValues
‘关闭Excel
closeExcelSheet ExcelBook,ExcelApp,ExcelSheet
end Function
‘******************************************************
‘Sub: 写入Excel中某一行的值
‘Input parameter:
‘strFilePath:保存Excel的文件路径
‘strExcelSheetName:要写入Sheet的名称
‘intRow:写入哪一个行的数据
‘intFromCol:从哪里列开始写
‘arrValue:写入值(数组)
‘For example:”E:\a.xls”,”Sheet1″,5,2
‘Return:
‘******************************************************
Sub setRowValues(strFilePath,strSheetName,intRow,intFromCol,arrValue)
‘定义变量
Dim ExcelApp,ExcelBook,ExcelSheet,intColcount
Dim intArrColumnsCount,intColumnsCount
‘创建EXCEL程序,打开工作簿,设置当前活动sheet
Set ExcelApp = CreateObject(“Excel.Application”)
Set ExcelBook = ExcelApp.WorkBooks.Open(strFilePath)
Set ExcelSheet = ExcelBook.WorkSheets(strSheetName)
‘得到数组的大小
intArrColumnsCount=UBound(arrValue)
‘最后写到哪一列
intColcount=intFromCol+intArrColumnsCount
‘设置值
For i=intFromCol To intColcount
ExcelSheet.cells(intRow,i).value =arrValue(i-intFromCol)
Next
‘写入完成后,保存EXCEL
ExcelApp.DisplayAlerts=False
ExcelApp.Save
‘关闭Excel
closeExcelSheet ExcelBook,ExcelApp,ExcelSheet
End Sub
‘******************************************************
‘Function:读Excel中所有的值
‘Input parameter:
‘strFilePath:保存Excel的文件路径
‘strExcelSheetName:要读取的Excel中Sheet的名称
‘For example:”E:\a.xls”,”Sheet1″
‘Return:取到的值
‘******************************************************
function getAllValues(strFilePath,strSheetName)
‘定义变量
Dim ExcelApp,ExcelBook,ExcelSheet,intRowscount,intColumnsCount,arrGetCellValue()
‘创建EXCEL程序,打开工作簿,设置当前活动sheet
Set ExcelApp = CreateObject(“Excel.Application”)
Set ExcelBook = ExcelApp.WorkBooks.Open(strFilePath)
Set ExcelSheet = ExcelBook.WorkSheets(strSheetName)
‘得到excel中共有几列
intRowscount =ExcelBook.ActiveSheet.UsedRange.Rows.Count
intColumnsCount =ExcelBook.ActiveSheet.UsedRange.Columns.count
‘获取excel中值
Redim Preserve arrGetCellValue (intRowscount-1,intColumnsCount-1)
For i=1 To intRowscount
For j=1 to intColumnsCount
arrGetCellValue(i-1,j-1) = ExcelSheet.Cells(i,j)
Next
Next
‘返回值
getAllValues=arrGetCellValue
‘关闭Excel
closeExcelSheet ExcelBook,ExcelApp,ExcelSheet
end Function
‘******************************************************
‘Function:读取某值第一次出现的行号
‘Input parameter:
‘strFilePath:Excel文件保存的路径
‘strSheetName:要读取的Excel中Sheet