473,503 Members | 3,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exporting in Excel using Response.ContentType = "application/ms-excel"

I am creating a TAB delimited file with .XLS extention using the Response.ContentType = "application/ms-excel" method. Normally I would place this on it's own form and delete all the HTML in the ASPX page - otherwise the aspx code gets appended to the end of the file out put to Excel. How do I produce the same output from a page where I cannot simply delete all the HTML code (must leave buttons and other objects intact)? In other words how can I keep the aspx code from being appended to the file that is sent to the client?

Here is the pertinent code (adapted from article by Steve C. Orr):

If custConnection.State = ConnectionState.Closed Then
custConnection.ConnectionString = "data source=OURSERVERINFOHERE;initial catalog=DB_NAME;integrated security=SSPI"
custConnection.Open()
End If
custAdapterCommand = New SqlClient.SqlDataAdapter("SELECT * FROM tMAIN WHERE DivisionDeptID = " & TextBox1.Text.ToString, custConnection)
custAdapterCommand.Fill(custDataSet, "tMain")
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition", "inline;filename=test.xls")
Response.Write(ConvertDtToTDF(custDataSet))

Private Function ConvertDtToTDF(ByVal dt As DataSet) As String
Dim dr As DataRow, ary() As Object, i As Integer
Dim iCol As Integer

'Output Column Headers
For iCol = 0 To dt.Tables(0).Columns.Count - 1
Response.Write(dt.Tables(0).Columns(iCol).ColumnNa me.ToString & vbTab)
Next
Response.Write(vbCrLf)

'Output Data
Dim aText As String = "" ' TESTING
For Each dr In dt.Tables(0).Rows
ary = dr.ItemArray
For i = 0 To UBound(ary)
'Response.Write(ary(i).ToString & vbTab)
aText += ary(i).ToString & vbTab
Next
'Response.Write(vbCrLf)
aText += vbCrLf
Next
Return aText
End Function
Nov 20 '05 #1
0 5652

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

Similar topics

4
16139
by: Microsoft | last post by:
I'm trying to display a word document inside a web page, but everytime I do I get this error: Error Type: Microsoft VBScript runtime (0x800A0046) Permission denied: 'CreateObject' Does...
2
10221
by: MaxiWheat | last post by:
Hi, I am using a software that uses MS Word to create PDF files. When I try to run the sample code (ASP 3.0), I get an error on this statement : Set oWord =...
4
2057
by: Julie | last post by:
I stumbled across Application from someone else's code, and I can't find out squat about by searching MS, Google, or Google Groups. For the most part, this is returning the fully-qualified name...
5
4943
by: TJS | last post by:
trying to display pdf file in browser fails on this line: Response.ContentType = "application/pdf" getting an error about no declaration found for "response" what declaration is needed ???
6
1752
by: farmer | last post by:
Compiler Error Message: CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement And: (int)Application++; Makes no sense.
0
1632
by: ASP Developer | last post by:
For some reason when I direct my users to a word document via Response.ContentType = "application/word" the spell check is turned off. Does anyone know which smart tag needs to be mofied to have it...
13
2279
by: Kobee | last post by:
Hi, I'm having a few issues adapting to new 2.0 "website" project vs. the old 1.1 "web application". One of the major issues I'm having is with the notion of namespaces. Using the old way, I...
3
8184
by: rdudejr | last post by:
Hi all, Ive got a database approx 350 GB in which Im getting very high Time waited for prefetch. This is directly out of the snapshot for the db (these are for the entire database I assume as I...
0
1981
by: CWogksch | last post by:
Hello, Everyone... My name is Chris Wogksch. I have a point of sale application developed in VB6 using MS Access 2003 as the database. I've been running versions of this app for over eight...
4
61753
by: Bjorn Sagbakken | last post by:
With ASP.NET 2.0 I'm trying to display the pdf file directly in the client browser, but I only get a download dialogue box. Downloading the file works fine, but I want to view the PDF directly. ...
0
7192
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
7064
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
7261
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
7315
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
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4665
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
3158
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
1492
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 ...
0
369
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...

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.