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

Datagrid to Excel problem (ASP dot net)

I use the following code:

Private Sub RbtnExport_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RbtnExport.SelectedIndexChanged
Dim sFile As String = Session("User") & "-Customer List-" & Today()
sFile = sFile.Replace("/", "")
RbtnExport.Visible = False
Select Case RbtnExport.SelectedItem.Value
Case "Excel"
Response.ContentType = "application/x-msexcel"
Case "Word"
Response.ContentType = "application/msword"
End Select
Response.AddHeader("Content-Disposition", "Attachment; filename=" & sFile)
End Sub

To allow a user to save a web page with a datagrid on it into an Excel
sheet.

They'll run a page using a Web check box, which renders it to an ASPX page,
and then when they have the final product on the screen, they click the
radio button for Excel, and it prompts them to Open or to Save the file.

The problem occurs when you save or open the file.

The datagrid has 9 columns in it, a product code, description, unit of
measure, price, product hierarchy number, weight and UPC code, etc.

The data grid has a header & a footer on it, and each column in the datagrid
is sortable.

If I have a short list, one of maybe less than 20 records, I can click the
Excel button, it prompts me to save it, and it'll save as a document with a
..xls extension. You can then open it up without incident.

If the list is longer - say maybe over 40-50 rows in length (up to the
longest list, with up to 500 or more items in it), it will save it with a
..xls extension, but you cannot open it.

Excel attempts to open it, but it immediately gives you an OK box that says
"Unable to read file". It works fine if the number of rows is small (under
25 or so), but not if it's much more than that. Thus far, I have not seen a
pattern in it. The file that will open is 20K in size, the one that will
not is 400K in size. I have figured that the difference is between 30 and 50
records before it gives me this problem. I've noticed that each line
appears to add about 1K in file size to it the excel file.

It doesn't appear to be a memory issue, as excel works fine any other time,
and will open spreadsheets much larger than this. I've confirmed that it's
not version specific in Excel, as it barfs on every version of excel it
tries to open it in.

Any idea as to what is going on here on this problem? Is there any way I
can step thru the open of the file in Excel, to see the specific problem
Excel has with opening the file?

Any help/advice appreciated.

Thanks,

SC
Nov 18 '05 #1
2 2462
Steve,
If there are no formulas to be involved, you might want to look at using the
RenderControl method of the DataGrid (and most other ASP.NET controls)
This will spit out the HTML representation of the DataGrid.

You can find plenty of examples of doing this on the .NET.
--Peter

"Steve Chatham" <me@privacy.net> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl...
I use the following code:

Private Sub RbtnExport_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RbtnExport.SelectedIndexChanged
Dim sFile As String = Session("User") & "-Customer List-" & Today()
sFile = sFile.Replace("/", "")
RbtnExport.Visible = False
Select Case RbtnExport.SelectedItem.Value
Case "Excel"
Response.ContentType = "application/x-msexcel"
Case "Word"
Response.ContentType = "application/msword"
End Select
Response.AddHeader("Content-Disposition", "Attachment; filename=" & sFile)
End Sub

To allow a user to save a web page with a datagrid on it into an Excel
sheet.

They'll run a page using a Web check box, which renders it to an ASPX
page,
and then when they have the final product on the screen, they click the
radio button for Excel, and it prompts them to Open or to Save the file.

The problem occurs when you save or open the file.

The datagrid has 9 columns in it, a product code, description, unit of
measure, price, product hierarchy number, weight and UPC code, etc.

The data grid has a header & a footer on it, and each column in the
datagrid
is sortable.

If I have a short list, one of maybe less than 20 records, I can click the
Excel button, it prompts me to save it, and it'll save as a document with
a
.xls extension. You can then open it up without incident.

If the list is longer - say maybe over 40-50 rows in length (up to the
longest list, with up to 500 or more items in it), it will save it with a
.xls extension, but you cannot open it.

Excel attempts to open it, but it immediately gives you an OK box that
says
"Unable to read file". It works fine if the number of rows is small
(under
25 or so), but not if it's much more than that. Thus far, I have not seen
a
pattern in it. The file that will open is 20K in size, the one that will
not is 400K in size. I have figured that the difference is between 30 and
50
records before it gives me this problem. I've noticed that each line
appears to add about 1K in file size to it the excel file.

It doesn't appear to be a memory issue, as excel works fine any other
time,
and will open spreadsheets much larger than this. I've confirmed that
it's
not version specific in Excel, as it barfs on every version of excel it
tries to open it in.

Any idea as to what is going on here on this problem? Is there any way I
can step thru the open of the file in Excel, to see the specific problem
Excel has with opening the file?

Any help/advice appreciated.

Thanks,

SC

Nov 18 '05 #2
Peter:

Before I get too far into looking into this option (RenderControl) - a quick
question:

On our web pages, the datagrids may have a number of columns - like for
complete shipments, you'd have $$ ordered & shipped, and for incomplete
ones, you'd have those 2 colums + an open $$ and qty - meaning, that we'd
have 6 columns in some datagrids, and 10 in others. Too, the columns would
be named differently in each of the datagrids, as they're built from a SQL
command.

Does the Rendercontrol command force you to write routines to render the
datagrid based on the number of columns you have?

To answer your question, there are formulas involved, but they're in sql -
i.e. ordered-shipped = open etc.

SC


"Peter Bromberg [C# MVP]" <pb*******@yahoo.com> wrote in message
news:eA****************@tk2msftngp13.phx.gbl...
Steve,
If there are no formulas to be involved, you might want to look at using the RenderControl method of the DataGrid (and most other ASP.NET controls)
This will spit out the HTML representation of the DataGrid.

You can find plenty of examples of doing this on the .NET.
--Peter

"Steve Chatham" <me@privacy.net> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl...
I use the following code:

Private Sub RbtnExport_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbtnExport.SelectedIndexChanged
Dim sFile As String = Session("User") & "-Customer List-" & Today()
sFile = sFile.Replace("/", "")
RbtnExport.Visible = False
Select Case RbtnExport.SelectedItem.Value
Case "Excel"
Response.ContentType = "application/x-msexcel"
Case "Word"
Response.ContentType = "application/msword"
End Select
Response.AddHeader("Content-Disposition", "Attachment; filename=" & sFile) End Sub

To allow a user to save a web page with a datagrid on it into an Excel
sheet.

They'll run a page using a Web check box, which renders it to an ASPX
page,
and then when they have the final product on the screen, they click the
radio button for Excel, and it prompts them to Open or to Save the file.

The problem occurs when you save or open the file.

The datagrid has 9 columns in it, a product code, description, unit of
measure, price, product hierarchy number, weight and UPC code, etc.

The data grid has a header & a footer on it, and each column in the
datagrid
is sortable.

If I have a short list, one of maybe less than 20 records, I can click the Excel button, it prompts me to save it, and it'll save as a document with a
.xls extension. You can then open it up without incident.

If the list is longer - say maybe over 40-50 rows in length (up to the
longest list, with up to 500 or more items in it), it will save it with a .xls extension, but you cannot open it.

Excel attempts to open it, but it immediately gives you an OK box that
says
"Unable to read file". It works fine if the number of rows is small
(under
25 or so), but not if it's much more than that. Thus far, I have not seen a
pattern in it. The file that will open is 20K in size, the one that will not is 400K in size. I have figured that the difference is between 30 and 50
records before it gives me this problem. I've noticed that each line
appears to add about 1K in file size to it the excel file.

It doesn't appear to be a memory issue, as excel works fine any other
time,
and will open spreadsheets much larger than this. I've confirmed that
it's
not version specific in Excel, as it barfs on every version of excel it
tries to open it in.

Any idea as to what is going on here on this problem? Is there any way I can step thru the open of the file in Excel, to see the specific problem
Excel has with opening the file?

Any help/advice appreciated.

Thanks,

SC


Nov 18 '05 #3

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

Similar topics

1
by: Ugo | last post by:
Hi, I am having a problem exporting a Datagrid to excel in asp.net. For some reason I am getting a blank excel page. I set up in IIS the Mime for ..xls. My code is below any help would be...
1
by: Luis Esteban Valencia | last post by:
Here is my aspx code: ============= <%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="PDM.excel.WebForm3" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0...
3
by: nkunkov | last post by:
Hi, I have read a lot of articles in this newsgroup about how to solve this problem but found no solution. I'm trying to export a C# datagrid to Excel file. Here is my code that I have also...
1
by: Ed Chiu | last post by:
Hi, I copied the following codes from Internet to export datagrid to Excel, it works with datagrid not supporting sorting or paging. Response.ContentType = "application/vnd.ms-excel"...
4
by: Frank | last post by:
Hello All, I ham using VS.NET 2003. Have followed instructions from http://gridviewguy.com/ArticleDetails.aspx?articleID=26 along with several other articles to no avail. I am pulling my hair...
3
by: Mike | last post by:
Hello, I am attempting to export the contents of a datagrid on my webform (using Excel automation) through ASP.NET. I have added the Excel object library to my VS ASP.NET project but I am...
0
by: letsgetsilly | last post by:
I am populating a datagrid and outputting it to excel. Everything worked well last night, but today excel only displays the content in font color white, which is impossible to see. The data is all...
4
by: dinoo | last post by:
I would appreciate if some one could help me out with this problem. I am trying to export the datagrid to an excel file in ASP.NET. The functionality works fine. But I would like to setup the...
6
by: slinky | last post by:
I found the following code to transfer datagrid data to an Excel file. Is this written in C#?... I'm a vb.netter. I'm just not sure where to place the code to experiment on it. Should I place it in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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
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
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
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.