`
zendj
  • 浏览: 116307 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

vbs使用Excel.Application组件读写excel文件

阅读更多

vb创建xls表,并写入内容

Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象
Set ExcelBook = ExcelApp.Workbooks.Add
Set ExcelSheet = ExcelBook.Worksheets(1) '添加工作页
ExcelSheet.Activate
ExcelApp.DisplayAlerts = False
ExcelSheet.Name="sheet1"
ExcelSheet.Range("A1").Value = 100 '设置A1的值为100
ExcelBook.SaveAs "d:\test.xls" '保存工作表
msgbox "d:\test.xls创建成功!"
ExcelBook.close
set excelApp=nothing
set ExcelBook=nothing
set ExcelSheet=nothing

将以上代码copy到记事本存为"writexls.vbs"文件,可运行测试

读execel文件

Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象
Set ExcelBook = ExcelApp.Workbooks.open("d:\test.xls")
Set ExcelSheet = ExcelBook.Worksheets(1)
msgbox ExcelSheet.Range("A1").Value

将以上代码copy到记事本存为"readxls.vbs"文件,可运行测试


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics