473,394 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

button to export to excel

I have a simple button that should open another window and export a datagrid
to an Excel file. I'm getting: "Name 'window' is not declared."

What do I need to declare or import?
<INPUT ID="Button5" ONCLICK="Button5_Click" NAME="Button5" TYPE="button"
VALUE="Export to Excel">

Sub Button5_Click()
Dim sHTML
sHTML = window.Form1.children("dgCommunities").outerhtml()
Dim oXL, oBook
oXL = CreateObject("Excel.Application")
oBook = oXL.Workbooks.Add
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
oBook.HTMLProject.RefreshDocument()
oXL.Visible = True
oXL.UserControl = True
End Sub
--
_____
DC G
Nov 21 '05 #1
5 2372
The error message appears to be accurate.
I don't see any code where you actually create a new window.

Here's some examples for you:
http://SteveOrr.net/Articles/ClientSideSuite.aspx
http://SteveOrr.net/articles/ExcelExport.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
I have a simple button that should open another window and export a
datagrid
to an Excel file. I'm getting: "Name 'window' is not declared."

What do I need to declare or import?
<INPUT ID="Button5" ONCLICK="Button5_Click" NAME="Button5" TYPE="button"
VALUE="Export to Excel">

Sub Button5_Click()
Dim sHTML
sHTML = window.Form1.children("dgCommunities").outerhtml()
Dim oXL, oBook
oXL = CreateObject("Excel.Application")
oBook = oXL.Workbooks.Add
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
oBook.HTMLProject.RefreshDocument()
oXL.Visible = True
oXL.UserControl = True
End Sub
--
_____
DC G

Nov 21 '05 #2
I think you're taking the wrong approach if you're using ASP.NET with Excel.

You might want to look at one of these articles:

http://www.dotnetjohn.com/articles/articleid78.aspx

http://www.c-sharpcorner.com/Code/20...ridToExcel.asp

http://support.microsoft.com/default...b;en-us;317719

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
I have a simple button that should open another window and export a
datagrid
to an Excel file. I'm getting: "Name 'window' is not declared."

What do I need to declare or import?
<INPUT ID="Button5" ONCLICK="Button5_Click" NAME="Button5" TYPE="button"
VALUE="Export to Excel">

Sub Button5_Click()
Dim sHTML
sHTML = window.Form1.children("dgCommunities").outerhtml()
Dim oXL, oBook
oXL = CreateObject("Excel.Application")
oBook = oXL.Workbooks.Add
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
oBook.HTMLProject.RefreshDocument()
oXL.Visible = True
oXL.UserControl = True
End Sub
--
_____
DC G


Nov 21 '05 #3
Steve,

This worked great with Excel installed. May I ask what needs to change when
using Microsoft Office Web Components?

_____
DC G

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:e4**************@TK2MSFTNGP11.phx.gbl...
I think you're taking the wrong approach if you're using ASP.NET with Excel.
You might want to look at one of these articles:

http://www.dotnetjohn.com/articles/articleid78.aspx

http://www.c-sharpcorner.com/Code/20...ridToExcel.asp
http://support.microsoft.com/default...b;en-us;317719

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
I have a simple button that should open another window and export a
datagrid
to an Excel file. I'm getting: "Name 'window' is not declared."

What do I need to declare or import?
<INPUT ID="Button5" ONCLICK="Button5_Click" NAME="Button5" TYPE="button"
VALUE="Export to Excel">

Sub Button5_Click()
Dim sHTML
sHTML = window.Form1.children("dgCommunities").outerhtml()
Dim oXL, oBook
oXL = CreateObject("Excel.Application")
oBook = oXL.Workbooks.Add
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
oBook.HTMLProject.RefreshDocument()
oXL.Visible = True
oXL.UserControl = True
End Sub
--
_____
DC G

Nov 21 '05 #4
Here are some examples using Office Web Components for Office 2003:

-http://msdn.microsoft.com/office/understanding/owc/default.aspx

And here are some examples using Office Web Components for earlier versions:

-http://msdn.microsoft.com/office/previous/components/default.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:eT**************@TK2MSFTNGP15.phx.gbl...
Steve,

This worked great with Excel installed. May I ask what needs to change
when
using Microsoft Office Web Components?

_____
DC G

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:e4**************@TK2MSFTNGP11.phx.gbl...
I think you're taking the wrong approach if you're using ASP.NET with

Excel.

You might want to look at one of these articles:

http://www.dotnetjohn.com/articles/articleid78.aspx

http://www.c-sharpcorner.com/Code/20...ridToExcel.asp

http://support.microsoft.com/default...b;en-us;317719

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
>I have a simple button that should open another window and export a
>datagrid
> to an Excel file. I'm getting: "Name 'window' is not declared."
>
> What do I need to declare or import?
>
>
> <INPUT ID="Button5" ONCLICK="Button5_Click" NAME="Button5"
> TYPE="button"
> VALUE="Export to Excel">
>
> Sub Button5_Click()
> Dim sHTML
> sHTML = window.Form1.children("dgCommunities").outerhtml()
> Dim oXL, oBook
> oXL = CreateObject("Excel.Application")
> oBook = oXL.Workbooks.Add
> oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
> oBook.HTMLProject.RefreshDocument()
> oXL.Visible = True
> oXL.UserControl = True
> End Sub
>
>
> --
> _____
> DC G
>
>


Nov 21 '05 #5
Steve,

Yes, I've seen that, but I'm looking for a bit more guidance than such a
huge reference.

Plain and simple, I've got Excel installed on my workstation and my app
works just fine. I upload it to our hosting provider and it doesn't.
They've installed OWC latest edition, but to no avail. Here's my code:

Public Sub btnCommunitiesExcel_OnClick(ByVal sender As System.Object, ByVal
e As System.EventArgs)

Dim oExcel As New Excel.Application
Dim oBooks As Excel.Workbooks, oBook As Excel.Workbook
Dim oSheets As Excel.Sheets, oSheet As Excel.Worksheet
Dim oCells As Excel.Range
Dim sFile As String, sTemplate As String
Dim ds As New DataSet
Dim da As New SqlDataAdapter(Session("savedCommunitiesSql"),
connection1.conString)
da.Fill(ds, "CommunitiesExcel")
Dim dt As DataTable = ds.Tables("CommunitiesExcel")

'Insert your code that runs under the security context of the authenticating
user here.
sFile = Server.MapPath(Request.ApplicationPath) & _
"\advanced\ExcelExports\Communities.xls"
sTemplate = Server.MapPath(Request.ApplicationPath) & _
"\advanced\ExcelExports\CommunitiesTemplate.xl s"
oExcel.Visible = False : oExcel.DisplayAlerts = False

'Start a new workbook
oBooks = oExcel.Workbooks
oBooks.Open(Server.MapPath(Request.ApplicationPath ) & _
"\advanced\ExcelExports\CommunitiesTemplate.xl s")

'Load colorful template with chart
oBook = oBooks.Item(1)
oSheets = oBook.Worksheets
oSheet = CType(oSheets.Item(1), Excel.Worksheet)
oSheet.Name = "First Sheet"
oCells = oSheet.Cells
DumpData(dt, oCells) 'Fill in the data
oSheet.SaveAs(sFile) 'Save in a temporary file
oBook.Close()

'Quit Excel and thoroughly deallocate everything
oExcel.Quit()
ReleaseComObject(oCells) : ReleaseComObject(oSheet)
ReleaseComObject(oSheets) : ReleaseComObject(oBook)
ReleaseComObject(oBooks) : ReleaseComObject(oExcel)
oExcel = Nothing : oBooks = Nothing : oBook = Nothing
oSheets = Nothing : oSheet = Nothing : oCells = Nothing
System.GC.Collect()
Response.Redirect(sFile) 'Send the user to the file

End Sub

Private Function DumpData(ByVal _
dt As DataTable, ByVal oCells As Excel.Range) As String
Dim dr As DataRow, ary() As Object
Dim iRow As Integer, iCol As Integer

'Output Column Headers
For iCol = 0 To dt.Columns.Count - 1
oCells(2, iCol + 1) = dt.Columns(iCol).ToString
Next

'Output Data
For iRow = 0 To dt.Rows.Count - 1
dr = dt.Rows.Item(iRow)
ary = dr.ItemArray
For iCol = 0 To UBound(ary)
oCells(iRow + 3, iCol + 1) = ary(iCol).ToString
Response.Write(ary(iCol).ToString & vbTab)
Next
Next
End Function
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Here are some examples using Office Web Components for Office 2003:

-http://msdn.microsoft.com/office/understanding/owc/default.aspx

And here are some examples using Office Web Components for earlier versions:
-http://msdn.microsoft.com/office/previous/components/default.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:eT**************@TK2MSFTNGP15.phx.gbl...
Steve,

This worked great with Excel installed. May I ask what needs to change
when
using Microsoft Office Web Components?

_____
DC G

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:e4**************@TK2MSFTNGP11.phx.gbl...
I think you're taking the wrong approach if you're using ASP.NET with

Excel.

You might want to look at one of these articles:

http://www.dotnetjohn.com/articles/articleid78.aspx

http://www.c-sharpcorner.com/Code/20...ridToExcel.asp

http://support.microsoft.com/default...b;en-us;317719

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
>I have a simple button that should open another window and export a
>datagrid
> to an Excel file. I'm getting: "Name 'window' is not declared."
>
> What do I need to declare or import?
>
>
> <INPUT ID="Button5" ONCLICK="Button5_Click" NAME="Button5"
> TYPE="button"
> VALUE="Export to Excel">
>
> Sub Button5_Click()
> Dim sHTML
> sHTML = window.Form1.children("dgCommunities").outerhtml()
> Dim oXL, oBook
> oXL = CreateObject("Excel.Application")
> oBook = oXL.Workbooks.Add
> oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
> oBook.HTMLProject.RefreshDocument()
> oXL.Visible = True
> oXL.UserControl = True
> End Sub
>
>
> --
> _____
> DC G
>
>



Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jim Quast | last post by:
I have an ASP page and a CREGReports002.vbs file coded to export data to excel. I do this by building variables in a stored procedure. The ASP page has text boxes, list boxes, and radio buttons. ...
0
by: | last post by:
I have this an application that uses a CrystalReportViewer (WindowsFormViewer) control. My problem is that when I try to export the report to Excel using the integrated export button, the...
1
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table....
8
by: DC Gringo | last post by:
I have a simple button that should open another window and export a datagrid to an Excel file. I'm getting: "Name 'window' is not declared." What do I need to declare or import? <INPUT...
0
by: Sridhar | last post by:
Hi, I have a export to excel function where it exports the data of a datagrid into the excel sheet. For this, I am using the button and the text on that button reads "Export to Excel". Instead...
13
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"...
1
by: adityakowtha | last post by:
Hi, I am developing an application that sometimes has data being displayed in tabular form. Whenever I want to export the data to an excel spreadsheet, I rightclick on the table and select the...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
2
by: =?Utf-8?B?SkRSYXZlbg==?= | last post by:
I have searched all over and can not seem to find an effective way to simply copy the contents of a ASP:gridview column to the clipboard based on a button or similar HTML or ASP.NET control. ASP...
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.