VBScript-使用Active X导出到Excel [英] VBScript - Using Active X to export to Excel

查看:130
本文介绍了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

推荐答案

您是否考虑过获取数据网格的内容并将其导出为更通用的格式,例如.csv(逗号分隔值)?即:基本上是创建一个文本文件,该文件可以在Excel(或任何其他能够打开文本文件的程序)中打开.

这将解决很多问题.
Have you considered taking the contents of your datagrid and exporting it to a more generic format such as .csv (comma separated values)? ie: Basically creating a text file that can be opened in Excel (or any other program capable of opening text files).

This will get around a whole host of issues.


您是否有资源可以向我指出有关导出到csv的信息?
Do you have resources that could point me to regarding exporting to csv?


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆