| |
JimmyFo
Posts: 5
Score: 0
Joined: 9/20/2005
Status: offline
|
Hi folks, I have a grid view on a content page and on the content page are a number of things: an ASP.net gridview control, a button with the function name "Export()" in the "onclientclick" property, and this function which I'm trying to use to export to excel: <script type="text/vbscript"> Function Export() msgbox("In Func") On Error Resume Next Dim sHTML, oExcel, fso, filePath Dim oelem 'oelem = document.body.childNodes("grid") 'oelem = document.all("grid") oelem = document.getElementById("grid") If oelem Is Nothing Then 'you cannot find it msgbox("cannot find grid") Exit Function 'early exit, you can wrap the whole functional part in the else if part if you like End If Dim slen slen = oelem.length 'make sure it is not dispHTMLElementCollection If err.number = 0 Then msgbox("error number <> 0") Exit Function 'there are more than one element of "grid" return, you have to reconsider how to deal with it End If err.clear sHTML = document.all("grid").outerHTML msgbox(sHTML) fso = CreateObject("Scripting.FileSystemObject") filePath = fso.GetSpecialFolder(2) & "\MyExportedExcel.xls" 'fso.CreateTextFile(filePath).Write(sHTML) fso.CreateTextFile(filePath) wscript.sleep(1000) oExcel.Workbooks.open(filePath) Dim i 'SET i = 0 i = 0 Do While Not fso.fileexists(filePath) 'err.Clear() 'no need filePath = fso.GetSpecialFolder(2) & "\MyExportedExcel" & i & ".xls" 'why do you write something like this to an xls file??? disregarding exist or not??? 'fso.CreateTextFile(filePath).Write(sHTML) i = i + 1 Loop oExcel = CreateObject("Excel.Application") 'IF err.number>0 OR oExcel =NULL THEN If err.number <> 0 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.Workbooks(1).WorkSheets.cells(1, 1) = sHTML oExcel.Visible = True fso = Nothing End Function </script> The two message boxes that pop up on click are "in Func" and "cannot find grid" - meaning it can't find the gridview, I assume. No other errors appear. 1) This is a content page, but I don't see how that could affect it. 2) This has an ASP.Net AJAX script manager on it, but even on pages without it, I still can't get it to work. Any ideas? Thanks! James
|
|