473,804 Members | 3,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Visua lBasic
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.Coun t - 1
oCells(2, iCol + 1) = dt.Columns(iCol ).ToString
Next

'Output Data
For iRow = 0 To dt.Rows.Count - 1
dr = dt.Rows.Item(iR ow)
ary = dr.ItemArray
For iCol = 0 To UBound(ary)
oCells(iRow + 3, iCol + 1) = ary(iCol).ToStr ing
Response.Write( ary(iCol).ToStr ing & vbTab)
Next
Next
End Function

Public Sub btnCommunitiesE xcel_OnClick(By Val sender As System.Object,
ByVal e As System.EventArg s)
Dim oExcel As New Excel.Applicati on
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("savedC ommunitiesSql") ,
connection1.con String)
da.Fill(ds, "CommunitiesExc el")
Dim dt As DataTable = ds.Tables("Comm unitiesExcel")

sFile = Server.MapPath( Request.Applica tionPath) & _
"\advanced\Exce lExports\Commun ities.xls"

sTemplate = Server.MapPath( Request.Applica tionPath) & _
"\advanced\Exce lExports\Commun itiesTemplate.x ls"

oExcel.Visible = False : oExcel.DisplayA lerts = False

'Start a new workbook
oBooks = oExcel.Workbook s
oBooks.Open(Ser ver.MapPath(Req uest.Applicatio nPath) & _
"\advanced\Exce lExports\Commun itiesTemplate.x ls") 'Load colorful
template with chart
oBook = oBooks.Item(1)
oSheets = oBook.Worksheet s
oSheet = CType(oSheets.I tem(1), Excel.Worksheet )
oSheet.Name = "First Sheet"
oCells = oSheet.Cells

DumpData(dt, oCells) 'Fill in the data

oSheet.SaveAs(s File) 'Save in a temporary file
oBook.Close()

'Quit Excel and thoroughly deallocate everything
oExcel.Quit()
ReleaseComObjec t(oCells) : ReleaseComObjec t(oSheet)
ReleaseComObjec t(oSheets) : ReleaseComObjec t(oBook)
ReleaseComObjec t(oBooks) : ReleaseComObjec t(oExcel)
oExcel = Nothing : oBooks = Nothing : oBook = Nothing
oSheets = Nothing : oSheet = Nothing : oCells = Nothing
System.GC.Colle ct()
Response.Redire ct(sFile) 'Send the user to the file

'impersonationC ontext.Undo()

End Sub

Nov 21 '05 #1
3 2147
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******@visio ntechnology.net > wrote in message
news:O5******** *****@TK2MSFTNG P12.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.Visua lBasic
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.Coun t - 1
oCells(2, iCol + 1) = dt.Columns(iCol ).ToString
Next

'Output Data
For iRow = 0 To dt.Rows.Count - 1
dr = dt.Rows.Item(iR ow)
ary = dr.ItemArray
For iCol = 0 To UBound(ary)
oCells(iRow + 3, iCol + 1) = ary(iCol).ToStr ing
Response.Write( ary(iCol).ToStr ing & vbTab)
Next
Next
End Function

Public Sub btnCommunitiesE xcel_OnClick(By Val sender As System.Object,
ByVal e As System.EventArg s)
Dim oExcel As New Excel.Applicati on
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("savedC ommunitiesSql") ,
connection1.con String)
da.Fill(ds, "CommunitiesExc el")
Dim dt As DataTable = ds.Tables("Comm unitiesExcel")

sFile = Server.MapPath( Request.Applica tionPath) & _
"\advanced\Exce lExports\Commun ities.xls"

sTemplate = Server.MapPath( Request.Applica tionPath) & _
"\advanced\Exce lExports\Commun itiesTemplate.x ls"

oExcel.Visible = False : oExcel.DisplayA lerts = False

'Start a new workbook
oBooks = oExcel.Workbook s
oBooks.Open(Ser ver.MapPath(Req uest.Applicatio nPath) & _
"\advanced\Exce lExports\Commun itiesTemplate.x ls") 'Load colorful
template with chart
oBook = oBooks.Item(1)
oSheets = oBook.Worksheet s
oSheet = CType(oSheets.I tem(1), Excel.Worksheet )
oSheet.Name = "First Sheet"
oCells = oSheet.Cells

DumpData(dt, oCells) 'Fill in the data

oSheet.SaveAs(s File) 'Save in a temporary file
oBook.Close()

'Quit Excel and thoroughly deallocate everything
oExcel.Quit()
ReleaseComObjec t(oCells) : ReleaseComObjec t(oSheet)
ReleaseComObjec t(oSheets) : ReleaseComObjec t(oBook)
ReleaseComObjec t(oBooks) : ReleaseComObjec t(oExcel)
oExcel = Nothing : oBooks = Nothing : oBook = Nothing
oSheets = Nothing : oSheet = Nothing : oCells = Nothing
System.GC.Colle ct()
Response.Redire ct(sFile) 'Send the user to the file

'impersonationC ontext.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.ne t> wrote in message
news:eq******** *****@TK2MSFTNG P12.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******@visio ntechnology.net > wrote in message
news:O5******** *****@TK2MSFTNG P12.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.Visua lBasic
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.Coun t - 1
oCells(2, iCol + 1) = dt.Columns(iCol ).ToString
Next

'Output Data
For iRow = 0 To dt.Rows.Count - 1
dr = dt.Rows.Item(iR ow)
ary = dr.ItemArray
For iCol = 0 To UBound(ary)
oCells(iRow + 3, iCol + 1) = ary(iCol).ToStr ing
Response.Write( ary(iCol).ToStr ing & vbTab)
Next
Next
End Function

Public Sub btnCommunitiesE xcel_OnClick(By Val sender As System.Object,
ByVal e As System.EventArg s)
Dim oExcel As New Excel.Applicati on
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("savedC ommunitiesSql") ,
connection1.con String)
da.Fill(ds, "CommunitiesExc el")
Dim dt As DataTable = ds.Tables("Comm unitiesExcel")

sFile = Server.MapPath( Request.Applica tionPath) & _
"\advanced\Exce lExports\Commun ities.xls"

sTemplate = Server.MapPath( Request.Applica tionPath) & _
"\advanced\Exce lExports\Commun itiesTemplate.x ls"

oExcel.Visible = False : oExcel.DisplayA lerts = False

'Start a new workbook
oBooks = oExcel.Workbook s
oBooks.Open(Ser ver.MapPath(Req uest.Applicatio nPath) & _
"\advanced\Exce lExports\Commun itiesTemplate.x ls") 'Load colorful
template with chart
oBook = oBooks.Item(1)
oSheets = oBook.Worksheet s
oSheet = CType(oSheets.I tem(1), Excel.Worksheet )
oSheet.Name = "First Sheet"
oCells = oSheet.Cells

DumpData(dt, oCells) 'Fill in the data

oSheet.SaveAs(s File) 'Save in a temporary file
oBook.Close()

'Quit Excel and thoroughly deallocate everything
oExcel.Quit()
ReleaseComObjec t(oCells) : ReleaseComObjec t(oSheet)
ReleaseComObjec t(oSheets) : ReleaseComObjec t(oBook)
ReleaseComObjec t(oBooks) : ReleaseComObjec t(oExcel)
oExcel = Nothing : oBooks = Nothing : oBook = Nothing
oSheets = Nothing : oSheet = Nothing : oCells = Nothing
System.GC.Colle ct()
Response.Redire ct(sFile) 'Send the user to the file

'impersonationC ontext.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******@visio ntechnology.net > wrote in message
news:%2******** ********@tk2msf tngp13.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.ne t> wrote in message
news:eq******** *****@TK2MSFTNG P12.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******@visio ntechnology.net > wrote in message
news:O5******** *****@TK2MSFTNG P12.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.Visua lBasic
> 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.Coun t - 1
> oCells(2, iCol + 1) = dt.Columns(iCol ).ToString
> Next
>
> 'Output Data
> For iRow = 0 To dt.Rows.Count - 1
> dr = dt.Rows.Item(iR ow)
> ary = dr.ItemArray
> For iCol = 0 To UBound(ary)
> oCells(iRow + 3, iCol + 1) = ary(iCol).ToStr ing
> Response.Write( ary(iCol).ToStr ing & vbTab)
> Next
> Next
> End Function
>
> Public Sub btnCommunitiesE xcel_OnClick(By Val sender As
> System.Object,
> ByVal e As System.EventArg s)
> Dim oExcel As New Excel.Applicati on
> 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("savedC ommunitiesSql") ,
> connection1.con String)
> da.Fill(ds, "CommunitiesExc el")
> Dim dt As DataTable = ds.Tables("Comm unitiesExcel")
>
> sFile = Server.MapPath( Request.Applica tionPath) & _
> "\advanced\Exce lExports\Commun ities.xls"
>
> sTemplate = Server.MapPath( Request.Applica tionPath) & _
> "\advanced\Exce lExports\Commun itiesTemplate.x ls"
>
> oExcel.Visible = False : oExcel.DisplayA lerts = False
>
> 'Start a new workbook
> oBooks = oExcel.Workbook s
> oBooks.Open(Ser ver.MapPath(Req uest.Applicatio nPath) & _
> "\advanced\Exce lExports\Commun itiesTemplate.x ls") 'Load colorful
> template with chart
> oBook = oBooks.Item(1)
> oSheets = oBook.Worksheet s
> oSheet = CType(oSheets.I tem(1), Excel.Worksheet )
> oSheet.Name = "First Sheet"
> oCells = oSheet.Cells
>
> DumpData(dt, oCells) 'Fill in the data
>
> oSheet.SaveAs(s File) 'Save in a temporary file
> oBook.Close()
>
> 'Quit Excel and thoroughly deallocate everything
> oExcel.Quit()
> ReleaseComObjec t(oCells) : ReleaseComObjec t(oSheet)
> ReleaseComObjec t(oSheets) : ReleaseComObjec t(oBook)
> ReleaseComObjec t(oBooks) : ReleaseComObjec t(oExcel)
> oExcel = Nothing : oBooks = Nothing : oBook = Nothing
> oSheets = Nothing : oSheet = Nothing : oCells = Nothing
> System.GC.Colle ct()
> Response.Redire ct(sFile) 'Send the user to the file
>
> 'impersonationC ontext.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
5051
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. Regarding C#, I have heard about System.Runtime.InteropServices.marshal.GetActiveObject ("Excel.Application")
4
1850
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). Well, what actually happens is that I simply manage to open the Excel file (somewhere in the filesystem on the server), then I manage even to write something to it, but when I release all the object, there's always EXCEL.EXE in task manager on the...
9
6608
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 and read from Access files in C# application without having Access in this PC in this case we install MDAC , Is there any thing similar to MDAC for Excel ? if yes where can I download it ? what is the name of the file ?
3
286
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 on production server, which has Microsoft Office 2003 installed. The site works perfectly, except that the excel reports do not come up. No error message is displayed. Is it an issue with Microsoft frontpage extension or could it be a Microsoft...
14
5807
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 SQL DATABASE, probably by the click of a button. Is this possible? & what is the BEST APPROACH for doing this? & also if any links are there do tell those to me too coz I have no idea how to go about doing it.
8
2862
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 ID="Button5" ONCLICK="Button5_Click" NAME="Button5" TYPE="button" VALUE="Export to Excel"> Sub Button5_Click()
3
2558
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 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
22
15360
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 reproduce the behavior described below? For this example, I am using Excel 2002 and VS .NET 2002 and VB 6. MSFT KB article 304661 gives a trivial example of early and late binding to Excel from VB .NET. Note that there is a variable naming...
2
4929
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 message in the environment shown here: Operating System: Microsoft Windows Version 5.1 (Build
15
5362
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 2003 application (Reports) works ok. But when Office 2003 is upgraded to Office 2007 Excel reports stops working. It Log the error “Exception from HRESULT: 0x800A03EC.” In database.
0
10583
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10337
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10082
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7622
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.