本文介绍了VBScript-使用Active X导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为一个9岁的应用程序研究了数周的解决方案.我需要将DataGrid导出到Excel. Response方法将不会导出大型数据集,因此我想使用ActiveX.

我目前有一个按钮ibtnExcel_Click,并且要导出"grdResult"内容-这是DataGrid.我也想删除一个Checkbox控件.

下面显示的是我的VBScript代码.我需要修改它的帮助.

子ibtnExcel_Click()

恢复错误,继续下一个
DIM sHTML,oExcel,fso,filePath

sHTML = document.all(grdResult).outerHTML

SET fso = CreateObject(" Scripting.FileSystemObject")
filePath = fso.GetSpecialFolder(2)& "\ MyExportedExcel.xls"
fso.CreateTextFile(filePath).Write(sHTML)

昏暗的我
SET i = 0

当错误编号> 0
err.Clear()
filePath = fso.GetSpecialFolder(2)& " \ MyExportedExcel" &我和".xls"

i = i + 1
循环

SET oExcel = CreateObject("Excel.Application")
如果err.number> 0或oExcel = NULL THEN
msgbox(您需要在系统上安装Excel并启用Active-X组件.")
退出功能
END IF

oExcel.Workbooks.open(filePath)
oExcel.Workbooks(1).WorkSheets(1).Name =我的Excel数据"
oExcel.Visible = true
设置fso = Nothing

I have been working on a solution for weeks for a 9 year old applicaiton. I need to export a DataGrid to Excel. The Response method will not export large datasets so I want to use ActiveX.

I currently have a button ibtnExcel_Click and want to export "grdResult" content - this is the DataGrid. I also want to remove a Checkbox control.

Shown below is my VBScript code. I need help to modify it.

Sub ibtnExcel_Click()

ON ERROR RESUME NEXT
DIM sHTML, oExcel, fso, filePath

sHTML = document.all(grdResult).outerHTML

SET fso = CreateObject("Scripting.FileSystemObject")
filePath = fso.GetSpecialFolder(2) & "\MyExportedExcel.xls"
fso.CreateTextFile(filePath).Write(sHTML)

DIM i
SET i = 0

DO WHILE err.number > 0
err.Clear()
filePath = fso.GetSpecialFolder(2) & "\MyExportedExcel" & i & ".xls"

i = i + 1
LOOP

SET oExcel = CreateObject("Excel.Application")
IF err.number>0 OR oExcel =NULL THEN
msgbox("You need to have Excel Installed and Active-X Components Enabled on your System.")
EXIT FUNCTION
END IF

oExcel.Workbooks.open(filePath)
oExcel.Workbooks(1).WorkSheets(1).Name = "My Excel Data"
oExcel.Visible = true
Set fso = Nothing

推荐答案



这篇关于VBScript-使用Active X导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 23:11