1:ADODB方式
Function GetConfig(sConfigFile, sSheet,sCaseId) ' Call PrintLog(Now, LOG_STATUS_INFO, "GetConfig(" & sConfigFile & "," & sSheet & ")") Dim oDictionary, oConnection Set oDictionary = CreateObject("Scripting.Dictionary") Set oConnection = CreateObject("ADODB.Connection") oConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sConfigFile & ";Extended Properties=Excel 8.0;Persist Security Info=False;Jet OLEDB" Dim oRecordSet, sSQL Set oRecordSet = CreateObject("ADODB.RecordSet") sSQL = "Select * from [" & sSheet & "$] where id = '" & sCaseId & "'" oRecordSet.Open sSQL, oConnection, ADO_FWDONLY Do Until oRecordSet.EOF MsgBox oRecordSet("PARENT")) oRecordSet.MoveNext Loop Set GetConfig = oDictionary ' Returns Set oDictionary = Nothing oRecordSet.Close 'Closes database connections oConnection.Close Set oRecordSet = Nothing Set oConnection = Nothing End Function
2:Application方式
Function getUdfColumnNames(sXlsPath, sSheetName) Dim xlsApp, xlsWorkBook, xlsSheet Set xlsApp = CreateObject("Excel.Application") xlsApp.Visible = False Set xlsWorkBook = xlsApp.Workbooks.Open (sXlsPath) Set xlsSheet = xlsWorkBook.Sheets(sSheetName) MsgBox xlsSheet.cells(1,1) MsgBox xlsSheet.usedRange.Rows.Count xlsWorkBook.Close xlsApp.Quit Set xlsSheet = Nothing Set xlsWorkBook = Nothing '释放内存 Set xlsApp = Nothing '释放Excel对象 End Function
3,UPDATE
Function updateCellValue(sXlsPath, sSheetName, iRow, iColumn, strValue) Dim xlsApp, xlsWorkBook, xlsSheet Set xlsApp = CreateObject("Excel.Application") '创建Excel对象 xlsApp.Visible = False 'true 为显示excel对象,false为不显示 Set xlsWorkBook = xlsApp.Workbooks.Open (sXlsPath) '打开指定路径的Excel表格 Set xlsSheet = xlsWorkBook.Sheets(sSheetName) '选择指定Sheet xlsApp.Cells(iRow,iColumn).value = strValue xlsWorkBook.Save xlsWorkBook.Close xlsApp.Quit Set xlsSheet = Nothing Set xlsWorkBook = Nothing '释放内存 Set xlsApp = Nothing '释放Excel对象 End Function
参考文献: http://www.voiceguide.com/vghelp/source/html/modvbs.htm
相关推荐
从国外网站上找到的用vbs读取excel的脚本,比较强悍。 编辑代码,查找并在以下位置xls文件路径。 <pre> strExcelPath = "xls文件的路径" 当然,要想正确运行,你需得安装ms excel才行。
一起学习VBS脚本语言,主要是如何读取excel
在wincc中,用vbs做excel报表时,经常会遇到报表打开时数据存不上的问题,这时需要先将报表关闭,数据才能够保存到报表中。本文介绍了用VBS脚本自动将某个excel文件关闭的方法。
如何在WINCC中基于VBS实现对EXCEL文件中数据的读写?
VBS脚本读写EXCEL方法介绍
本文档是使用VBS脚本文件,操作wincc中的变量,然后将变量值读取,按照一小时一次的频率,写入EXCEL表格内,并生成相应名称的表格
本文主要介绍了在WinCC中如何使用VBS脚本访问变量归档数据,并且获得数据使用Excel模版保存新文件,其中包括两个代码文本文档
vbs读取excel内容的代码打包
wincc7.4 用VBS将变量写入EXCEL,并能读取记录文件
wincc中通过vbs写excel
vbs操作excel全集 vbs控制EXCEL
vbs跳过宏安全提示和级别设置直接打开EXCEL
在WinCC项目中如何使用VBS读取报警记录数据到EXCELzip,西门子之在WinCC项目中如何使用VBS读取报警记录数据到EXCEL
VBS脚本操作Excel常见方法汇总
在WinCC中如何使用VBS读取变量归档数据到EXCEL
A0579_ 在WinCC中如何使用VBS读取变量归档数据到EXCEL
VBS连接和操作EXCEL (一) 使用动态创建的方法 首先创建 Excel 对象,使用ComObj: oExcel = CreateObject( "Excel.Application" ) 1) 显示当前窗口: oExcel.Visible = True 2) 更改 Excel 标题栏: oExcel.Caption ...
自己写的vbs读取配置文件的代码 直接就能用 很好使哈
poi无法直接获取excel各sheet页打印页数,调用vbs脚本获取excel各sheet页打印预览总页数。
通过命令行测试 , 参数为excel路径和pdf目标路径。 可以通过java调用,实现自动转换。