473,480 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ASP.NET + Excel Download

We create an excel object with Excel/Office Interop Assembly and we want to
offer this excel object as download without creating physically the file.

The download window appears with "Save As.", "Open", etc

Problem:

The file we get as download is not the excel object we created. Instead of
the correct values/data we just get the namespace from the excel object in
the downloaded file.

Source code:

Private Sub SetExcel()

Dim ea As New Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet

wb = ea.Workbooks.Add(1)

ws = wb.ActiveSheet

ws.Name = "Details"

ws.Cells(1, 1) = "test"
ws.Cells(4, 4) = "hallo"
ws.Cells(5, 6) = 4324
ws.Cells(3, 5) = "tja"

Call DownloadFromText(wb)

ea.Quit()

End Sub

Public Sub DownloadFromText( _
ByVal obj As Object)

Dim strHdr As String = ""

strHdr = "attachment;filename=ExcelFile.xls"

With HttpContext.Current.Response

.Clear()
.ContentType = "application/vnd.ms-excel"
.ContentEncoding = System.Text.Encoding.Default
.AppendHeader("Content-Disposition", strHdr)
.Write(obj)
.Flush()
.Clear()
.Close()

End With

End Sub

Output:

An excel file with one single line containing the text:

Microsoft.Office.Interop.Excel.WorkbookClass

We assume:

ContentType or ContentEncoding of HttpContext.Current.Response are not set
correctly

-OR-

The Write(obj) method is not the correct one to use in this case.

Everything works fine when writing first the excel object into a physical
file and offer the download with Response.TransmitFile. But creating the
file is not what we want.

Any suggestions could help us a lot.

Thanks.
Nov 19 '05 #1
1 1816
have tried response.writefile() ?
"George Homorozeanu" <ge****************@hotmail.com> wrote in message
news:ue**************@TK2MSFTNGP14.phx.gbl...
We create an excel object with Excel/Office Interop Assembly and we want to offer this excel object as download without creating physically the file.

The download window appears with "Save As.", "Open", etc

Problem:

The file we get as download is not the excel object we created. Instead of
the correct values/data we just get the namespace from the excel object in
the downloaded file.

Source code:

Private Sub SetExcel()

Dim ea As New Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet

wb = ea.Workbooks.Add(1)

ws = wb.ActiveSheet

ws.Name = "Details"

ws.Cells(1, 1) = "test"
ws.Cells(4, 4) = "hallo"
ws.Cells(5, 6) = 4324
ws.Cells(3, 5) = "tja"

Call DownloadFromText(wb)

ea.Quit()

End Sub

Public Sub DownloadFromText( _
ByVal obj As Object)

Dim strHdr As String = ""

strHdr = "attachment;filename=ExcelFile.xls"

With HttpContext.Current.Response

.Clear()
.ContentType = "application/vnd.ms-excel"
.ContentEncoding = System.Text.Encoding.Default
.AppendHeader("Content-Disposition", strHdr)
.Write(obj)
.Flush()
.Clear()
.Close()

End With

End Sub

Output:

An excel file with one single line containing the text:

Microsoft.Office.Interop.Excel.WorkbookClass

We assume:

ContentType or ContentEncoding of HttpContext.Current.Response are not set
correctly

-OR-

The Write(obj) method is not the correct one to use in this case.

Everything works fine when writing first the excel object into a physical
file and offer the download with Response.TransmitFile. But creating the
file is not what we want.

Any suggestions could help us a lot.

Thanks.

Nov 19 '05 #2

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

Similar topics

9
3885
by: jillandgordon | last post by:
I am trying to import an excel file into Access 97. It looks perfectly all right but, every time I try to import it, I get to the lst step and am told that it was not imported due to an error. ...
4
21794
by: Ali | last post by:
I need a functionality where my clients download Excel files and after they do, I do some processing. Downloading is easily achieved using a anchor or hyperlink tag, but that does not give me the...
4
2480
by: Lewis Edward Moten III | last post by:
I have a file that users can download through a web page protected by forms authentication: Download.aspx?ID=45 and within that file ... FileInfo fileToDownload = new FileInfo(fileName);
4
2208
by: Vishal | last post by:
Hello, I have a dataset with some content. I can convert this dataset in a csv format which is then stored in a stringwriter. Now I want this be open via excel, so I set the contenttype...
3
18776
by: David Reynolds | last post by:
Does anyone know how I could stream Excel to the browser for download without saving the file somewhere first. I wasn't sure how I would go about it.
3
4108
by: Rik Moed | last post by:
Hi, I am having a problem with Excel 2003 worksheets when I upload them using the HtmlIputFile. After the upload, I start to download the worksheet and it appears to be currupt. I recieve the...
6
8044
by: Eddie | last post by:
Hi all, I am displaying a number of reports, and giving the users an option to display them on the web or download them to Excel. If they want the Excel file, I just use the PHP header command...
0
3276
by: =?Utf-8?B?ZGlzcGxheW5hbWU=?= | last post by:
The following code used to outputs to Excel 2003 fine. Do I need to change it to output to Excel 2007? <% Response.ContentType = "application/vnd.ms-excel" Response.AddHeader...
13
2965
by: Peter | last post by:
VS2008 ans ASP.NET 3.5, Office 2003 What is the best way to run Excel Template from ASP.NET web page were the Excel is only installed on the client without any ActiveX? If so can someone point...
0
7041
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
7043
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,...
1
6737
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
6921
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...
1
4776
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...
0
4481
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...
0
2995
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...
0
1300
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 ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.