473,406 Members | 2,208 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,406 software developers and data experts.

Excel vs. Office Web Components

Allison (or others), thank you for the advice...a few more questions:

- I have tested on my workstation on Excel XP and my application references
the Excel 10.0 Object Library. I was told the server has the "Office 2003"
components which I'm assuming is OWC11. How do my imports, declarations or
other code change to account for the components versus having Excel
installed?
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Runtime.InteropServices.Marshal
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

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")

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

'impersonationContext.Undo()

End Sub

Nov 21 '05 #1
3 2126
The code you supplied below should work with both Office XP and Office 2003.
I should know since I wrote it and I've tested it with both versions of
Office.
;-)

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:O5*************@TK2MSFTNGP12.phx.gbl...
Allison (or others), thank you for the advice...a few more questions:

- I have tested on my workstation on Excel XP and my application
references
the Excel 10.0 Object Library. I was told the server has the "Office
2003"
components which I'm assuming is OWC11. How do my imports, declarations
or
other code change to account for the components versus having Excel
installed?
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Runtime.InteropServices.Marshal
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

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")

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

'impersonationContext.Undo()

End Sub

Nov 21 '05 #2
Steve,

Yes, it works perfectly with Office XP. But I need it to work with Office
Web Components that are installed on the server. What do I need to do to
this to make it work?

_____
DC G
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:eq*************@TK2MSFTNGP12.phx.gbl...
The code you supplied below should work with both Office XP and Office 2003. I should know since I wrote it and I've tested it with both versions of
Office.
;-)

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:O5*************@TK2MSFTNGP12.phx.gbl...
Allison (or others), thank you for the advice...a few more questions:

- I have tested on my workstation on Excel XP and my application
references
the Excel 10.0 Object Library. I was told the server has the "Office
2003"
components which I'm assuming is OWC11. How do my imports, declarations
or
other code change to account for the components versus having Excel
installed?
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Runtime.InteropServices.Marshal
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

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")

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

'impersonationContext.Undo()

End Sub


Nov 21 '05 #3
You mean without Excel being installed on the server?
I'd be surprised if the code would work at all.
There are many ways you can export to Excel without Excel having to be
installed on the server, but I don't think this is one of them.
For some other ideas look here:
http://SteveOrr.net/Articles/ExcelExport.aspx
http://SteveOrr.net/Articles/ExportPanel.aspx
http://SteveOrr.net/export.aspx

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

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

Yes, it works perfectly with Office XP. But I need it to work with Office
Web Components that are installed on the server. What do I need to do to
this to make it work?

_____
DC G
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:eq*************@TK2MSFTNGP12.phx.gbl...
The code you supplied below should work with both Office XP and Office

2003.
I should know since I wrote it and I've tested it with both versions of
Office.
;-)

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:O5*************@TK2MSFTNGP12.phx.gbl...
> Allison (or others), thank you for the advice...a few more questions:
>
> - I have tested on my workstation on Excel XP and my application
> references
> the Excel 10.0 Object Library. I was told the server has the "Office
> 2003"
> components which I'm assuming is OWC11. How do my imports,
> declarations
> or
> other code change to account for the components versus having Excel
> installed?
>
>
> Imports Microsoft.VisualBasic
> Imports System.Data
> Imports System.Runtime.InteropServices.Marshal
>
>
> 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
>
> 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")
>
> 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
>
> 'impersonationContext.Undo()
>
> End Sub
>
>
>



Nov 21 '05 #4

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

Similar topics

1
by: cybertof | last post by:
Hello, Is there a way to connect (through automation) a c# application to a running Excel 2003 instance on a specific workbook ? In the past, i used to use GetObject(...) function in VB6. ...
4
by: Denis Brkljacic | last post by:
Hello, Please, if enaybody could help a little bit... Namely, I need to build C# ASP.NET Web that opens some Template.xls, write something to it and then closes it (and releases the objects)....
9
by: [Yosi] | last post by:
Can I make an Excel file without having Excel in my PC ? I want to create Excel files from my C# application , then open those files later in another PC who have Excel installed . As we can open...
3
by: Rana | last post by:
I developed a reporting website using ASP.NET and Microsoft Office XP. The reports are generated using Microsoft Excel. It works perfectly as designed in the development environment. I deployed it...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
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...
3
by: DC Gringo | last post by:
Allison (or others), thank you for the advice...a few more questions: - I have tested on my workstation on Excel XP and my application references the Excel 10.0 Object Library. I was told the...
22
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
2
by: Nicholas Dreyer | last post by:
The following error Run-time exception thrown : System.Runtime.InteropServices.COMException - Error loading type library/DLL. happens while running the code listed at the bottom of this...
15
by: =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?= | last post by:
Hi All, We are in the process of Upgrade Excel 2003 (Office 2003) to Excel 2007 (Office 2007) for one of web application. This web application is using Excel (Pivot Table) reports. With Excel...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.