打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
VBScript读取 Excel 与 写入 Excel
Function  GetCellValue(excelSheet, row, column, path)
        
 on   error   resume   next 
        
 Set  Wshshell  =   CreateObject ( " Wscript.shell " )
        
 Set  ExcelApp  =   CreateObject ( " excel.Application " )
        ExcelApp.Visible 
 =   True 
        
 Set  newBook  =  ExcelApp.Workbooks.Open(path)
        
 If   Err  =   0   Then 
                
 Set  excelSheet  =  ExcelApp.ActiveSheet
                GetCellValue 
 =  excelSheet.Cells(row, column)
                ExcelApp.Quit
                Wshshell.Popup GetCellValue,
 2 , " 获取的Excel单元格的值为: " , 0 + 64 
         
 Else 
                Wshshell.Popup 
 " 请确认文件是否已经创建 " , 3 , " 文件不存在 " , 0 + 64 
                ExcelApp.Quit
         
 End   If 
 
End Function 
 
Call  GetCellValue( " excel " , 9 , 9 , " E:/excel.xls " )

写入:
 Function  WExcel(row,col,value,path)
        
 Set  Wshshell  =   Createobject ( " Wscript.shell " )
        Err 
 =   0 
        
 on   error   resume   next 
    
 Dim  fso,f
    
 Set  fso  =   CreateObject ( " Scripting.FileSystemObject " )
    
 Set  f  =  fso.GetFile(path)
           
 Set  ExcelApp  =   CreateObject ( " Excel.Application " )
        ExcelApp.Visible 
 =   true 
        
 If   Err  =   0   Then 
                
 Set  newBook  =  ExcelApp.Workbooks.Open(path)
                newBook.Worksheets(
 1 ).Activate
                newBook.Worksheets(
 1 ).Cells(row,col).value = value
                newBook.Worksheets(
 1 ).Name = " excel " 
                newBook.Save
                ExcelApp.Application.quit
                
 set  newBook  =   nothing 
                
 Set  ExcelApp  =   nothing 
         
 Elseif  Err  =   53   Then 
                
 Set  newBook  =  ExcelApp.Workbooks.Add
                newBook.Worksheets(
 1 ).Activate
                newBook.Worksheets(
 1 ).Cells(row,col).value = value                 
                newBook.Worksheets(
 1 ).Name = " excel " 
                newBook.SaveAs path
                ExcelApp.Application.quit
                
 set  newBook  =   nothing 
                
 Set  ExcelApp  =   nothing 
         
 Else 
                Wshshell.Popup 
 " 发生未知错误 "  5  " 无法继续 " , 0 + 32         
         
 End   If 
 
End Function 
 
Call  WExcel( 9 , 9 , " liuyi " , " E:/excel.xls " )
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
asp中把数据库内容导出到excel
QTP 常用函数库
VB创建一个EXCEL文件
!!嵌入excel 动态创建activex
VB6.0 导出excel 方法源代码
qtp之excel操作函数
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服