473,654 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems displaying Excel on aspx page

Hi There

I have been having a play around with the following code to display a
datagrid in Excel (all from Steve Orr's site):

Private Sub btnTechServAccr ed_Click(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles btnTechServAccr ed.Click

Dim AcredDT As DataTable = UserSession.Cur rent.AcredTable
Dim aExcel As New Microsoft.Offic e.Interop.Excel .Application
Dim aBooks As Microsoft.Offic e.Interop.Excel .Workbooks
Dim aBook As Microsoft.Offic e.Interop.Excel .Workbook
Dim aSheets As Microsoft.Offic e.Interop.Excel .Sheets
Dim aSheet3 As Microsoft.Offic e.Interop.Excel .Worksheet
Dim aSheet1 As Microsoft.Offic e.Interop.Excel .Worksheet
Dim aCells As Microsoft.Offic e.Interop.Excel .Range
Dim tFile As String, tTemplate As String

tFile = "C:\Accreditati ons\Excel.xls"
tTemplate = "C:\Accreditati ons\Template.xl s"

aExcel.Visible = False : aExcel.DisplayA lerts = False

aBooks = aExcel.Workbook s
aBooks.Open("C: \Accreditations \Template.xls")

aBook = aBooks.Item(1)
aSheets = aBook.Worksheet s
aSheet3 = CType(aSheets.I tem(3),
Microsoft.Offic e.Interop.Excel .Worksheet)
aSheet1 = CType(aSheets.I tem(1),
Microsoft.Offic e.Interop.Excel .Worksheet)
aSheet3.Name = "Raw Data"
aCells = aSheet3.Cells
DumpData(AcredD T, aCells)
aSheet1.SaveAs( tFile)
aBook.Close()

aExcel.Quit()
ReleaseComObjec t(aCells) : ReleaseComObjec t(aSheet3)
ReleaseComObjec t(aSheets) : ReleaseComObjec t(aBook)
ReleaseComObjec t(aBooks) : ReleaseComObjec t(aExcel)
aExcel = Nothing : aBooks = Nothing : aBook = Nothing
aSheets = Nothing : aSheet3 = Nothing : aCells = Nothing
System.GC.Colle ct()
Response.Redire ct(tFile)
End Sub

Private Function DumpData(ByVal _
dt As DataTable, ByVal oCells As Microsoft.Offic e.Interop.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
This all works beautifully if I run the page from within Visual Studio 2003
- but as soon as I browse to the page using http://localhost/blah-de-blah it
fails at the point you would expect to see the message from the browser
asking if you want to open or save the file. Browser simply comes back with:

"The Page Cannot Be Displayed"

I get the impression that it is failing when it tries to overwrite the
"MyExcel" temporary document - and I have no doubt I am doing something daft
or have forgotten something obvious... any help would be appreciated.

I have set impersonation "Yes" and the IUSR account has permission to write
to the relevant excel files on the C: drive

Thanks

Jan 2 '07 #1
5 2267
"Stuart" <St****@discuss ions.microsoft. comwrote in message
news:4F******** *************** ***********@mic rosoft.com...
Dim aExcel As New Microsoft.Offic e.Interop.Excel .Application
Server-side automation of Office products is not recommended, to the extent
that Microsoft won't actually support any solution which uses it...
http://support.microsoft.com/default...US;q257757#kb2
This all works beautifully if I run the page from within Visual Studio
2003
That's right - because Visual Studio is running on your local machine - i.e.
it's not server-side automation...
I get the impression that it is failing when it tries to overwrite the
"MyExcel" temporary document - and I have no doubt I am doing something
daft
or have forgotten something obvious... any help would be appreciated.
See above...
Jan 2 '07 #2
Thanks Mark

I'm more interested in why the solution I have proposed is not working... I
appreciate and accept the constraints imposed on this - but it should still
work should it not...?

This is to support a report that may be run very occasionally on an Intranet
site and only 2 windows accounts have access to it in the first place

If anyone can tell me what I have missed in the code, rather than the
planning and concept, I would appreciate it still

Thanks again

"Mark Rae" wrote:
"Stuart" <St****@discuss ions.microsoft. comwrote in message
news:4F******** *************** ***********@mic rosoft.com...
Dim aExcel As New Microsoft.Offic e.Interop.Excel .Application

Server-side automation of Office products is not recommended, to the extent
that Microsoft won't actually support any solution which uses it...
http://support.microsoft.com/default...US;q257757#kb2
This all works beautifully if I run the page from within Visual Studio
2003

That's right - because Visual Studio is running on your local machine - i.e.
it's not server-side automation...
I get the impression that it is failing when it tries to overwrite the
"MyExcel" temporary document - and I have no doubt I am doing something
daft
or have forgotten something obvious... any help would be appreciated.

See above...
Jan 2 '07 #3
"Stuart" <St****@discuss ions.microsoft. comwrote in message
news:B6******** *************** ***********@mic rosoft.com...
I'm more interested in why the solution I have proposed is not working...
I
appreciate and accept the constraints imposed on this - but it should
still
work should it not...?
??? Did you actually read the MSDN article ???
Jan 2 '07 #4
Hi There
>
I have been having a play around with the following code to display a
datagrid in Excel (all from Steve Orr's site):
[snip]
This all works beautifully if I run the page from within Visual Studio 2003
- but as soon as I browse to the page using http://localhost/blah-de-blah it
fails at the point you would expect to see the message from the browser
asking if you want to open or save the file. Browser simply comes back with:

"The Page Cannot Be Displayed"

I get the impression that it is failing when it tries to overwrite the
"MyExcel" temporary document - and I have no doubt I am doing something daft
or have forgotten something obvious... any help would be appreciated.

I have set impersonation "Yes" and the IUSR account has permission to write
to the relevant excel files on the C: drive

Thanks
When you run from within VS2003, the site probably uses *your* account,
which probably has admin rights locally.
When you install it on the server, it probably runs as "NETWORK
SERVICES" (for Win2003) or "ASPNET" (for WinXP), not the "IUSR.."
account.
(And note the remarks from Mark Rae)

Hans Kesting
Jan 2 '07 #5
Few remarks that may help you:
- On a Windows 2003 server, you may create a second application pool
and set its identity to "Local System" instead of "Network services".
Assign that pool to the asp site that you want to write local files.
Note that for security you should not have asp scripts use this pool
unless they absolutely need to. One other right that "network user" is
missing is the ability to spawn executable processes, that may
interfere with starting the Excel engine.
- If it is possible that the target file exists, you need not only
DisplayAlerts = False but also AlertBeforeOver writing = False, else the
process will stop at the moment that SaveAs is called and the target
exists. In Excel 2003, DisplayAlerts=f alse does not suppress the
overwrite message box.
- If Excel still can't be run from ASP, you could make an external
application that creates the excel object. Running an external
application will work if you set the application pool to "Local
system".

Best regards,

Berend
Stuart schreef:
Thanks

This turns out to be something daft as predicted... if you put the saveas
file path to the wwwroot/Project Folder of course all processes and relevant
users are able to manipulate the files in this location... this is not the
case in my test directory of C:\ (for obvious reasons)

I feel thoroughly and duly warned... - but as I was implying - Microsoft do
not recommend this for certain reasons... none of which are "It doesn't work
at all" - I probably will not use this process - but needed to know why it
did not work !

Thanks again

"Hans Kesting" wrote:
Hi There
>
I have been having a play around with the following code to display a
datagrid in Excel (all from Steve Orr's site):
>
[snip]
This all works beautifully if I run the page from within Visual Studio 2003
- but as soon as I browse to the page using http://localhost/blah-de-blah it
fails at the point you would expect to see the message from the browser
asking if you want to open or save the file. Browser simply comes back with:
>
"The Page Cannot Be Displayed"
>
I get the impression that it is failing when it tries to overwrite the
"MyExcel" temporary document - and I have no doubt I am doing something daft
or have forgotten something obvious... any help would be appreciated.
>
I have set impersonation "Yes" and the IUSR account has permission to write
to the relevant excel files on the C: drive
>
Thanks
When you run from within VS2003, the site probably uses *your* account,
which probably has admin rights locally.
When you install it on the server, it probably runs as "NETWORK
SERVICES" (for Win2003) or "ASPNET" (for WinXP), not the "IUSR.."
account.
(And note the remarks from Mark Rae)

Hans Kesting

Jan 5 '07 #6

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

Similar topics

0
1571
by: Wynter | last post by:
RE: from Displaying a Document using the ASPNET user account to the Client Browser discussion (3/2/2004 Buddy Thanks for helping me on getting the document to display. But now I am left with a second issue. While I was displaying the document as an attachment I end up with an extra window open or if I remove the Target='_blank' then my main window goes blank What I am doing is using the base code from...
2
3439
by: Carole MacDonald | last post by:
There have been lots of posts on this topic, but I haven't been able to apply any of the suggestions to my situation. I have an .aspx page with a form on it that has several submit buttons on it. Clicking a button will cause a web service action that returns XML. I would like to display this XML response on the page with the form. I know I can display XML in an IFRAME by pointing its source to an XML file. But I'm streaming the XML...
3
3530
by: Scott | last post by:
Hello, we are having problems displaying non-aspx files (images, style sheets) since we have upgraded to the 1.1 framework when using a cookieless session (sessionID in the url). Check out our file system set up below. Now, in an aspx page, we set as the "src" of our images something like "../images/animage.jpg". If the current actual url in the browser is something like http://server/webapp/(someSessionID)/forms/form1.aspx
2
3276
by: Guillermo Rosich Capablanca | last post by:
I have a problem with utf-8 enconding and I don't know what to do in order to make it work. I want to open a new window with excel data so the user can choose to save it local. Everything works fine, the new window, the excel data appears, but, extended characters are wrong. I call the window from an aspx page using this:
2
5430
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been recommended by many for web applications. I create the instances of Excel, Workbook and the worksheet. And later on Release the references by “System.Runtime.InteropServices.Marshal.ReleaseComObject(Object)” and making the object as null finally....
2
1331
by: Joo Park | last post by:
Hello, i have an aspx page that displays data in tabular format. I'd like to change this page so that it outputs that same data into excel format. what needs to change in an aspx page to do that? thx in advance!
0
1692
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a single worksheet into a dataset. I successfully built a dynamic datagrid. And I did successfully bind it to the dataset. Then I added the datagrid control to a PlaceHolder. The first worksheet displays beautifully. The next step is to allow...
1
6119
by: Anonieko | last post by:
Here are some of the approaches. 1. Transform DataGrid http://www.dotnetjohn.com/articles.aspx?articleid=36 3. Use the Export approach http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp
0
1011
by: robin9876 | last post by:
In an .aspx (VB) page that displays that data in Excel which shows the data in excel within the browser. The following code is in the page to identify the file information. Response.AppendHeader("Content-Disposition", "inline; filename=Download.xls") Response.ContentType = "application/vnd.ms-excel" Is it possible to display the data within Excel without being in the
0
8814
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
8706
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...
1
8475
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6160
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
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
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
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
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
1592
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.