472,331 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

Problem exporting datagrid with numeric values to Excel

I am using the following code to write data from a datagrid to an Excel file:
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
dg.RenderControl(hw)
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Response.AppendHeader("content-disposition",
"attachment;filename=test.xls")
Response.Write(txtWriter.ToString)
Response.End()
So far, so good. Creates an Excel spreadsheet very nicely. The problem
occurs when a column contains what appears to be numeric data. Leading
zeroes are being dropped. If the number is too large, the value is being
stored in scientific notation format. Is there any way to get my values to
download to Excel as text? These fields are coming from a SQL database where
they are stored as varchar. Thanks for any help.
Nov 19 '05 #1
1 2209
Hi Nancy,

I think it's an Excel bug. Because all are digits
(including leading 0), it automatically recognizes it as
number. In Excel automation, we can set text format for
specific column first then fill this kind of data. That
works perfectly. But for the datagrid exporting I can't
think any solution.

HTH

Elton Wang
el********@hotmail.com
-----Original Message-----
I am using the following code to write data from a datagrid to an Excel file: Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
dg.RenderControl(hw)
Response.ContentType = "application/vnd.ms- excel" Response.Charset = ""
Response.AppendHeader("content-disposition",
"attachment;filename=test.xls")
Response.Write(txtWriter.ToString)
Response.End()
So far, so good. Creates an Excel spreadsheet very nicely. The problemoccurs when a column contains what appears to be numeric data. Leadingzeroes are being dropped. If the number is too large, the value is beingstored in scientific notation format. Is there any way to get my values todownload to Excel as text? These fields are coming from a SQL database wherethey are stored as varchar. Thanks for any help.
.

Nov 19 '05 #2

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

Similar topics

0
by: Hideyuki | last post by:
Hi, I am using asp.net, and I am having a problem exporting datagrid to excel. One column contains numbers such as 123456875468. When this goes...
0
by: Deepa | last post by:
The application am doing writes a dataset to a csv file format. Everything works fine except for one issue. The dataset has a column "xyz" whose...
4
by: D | last post by:
I've created a report with many subreports of aggregate data. I want my client to be able to export this data to Excel to make her charts, etc. Only...
1
by: ad | last post by:
I use the code below to export the content of a data set to Excel, the code come form http://www.dotnetjohn.com/articles.aspx?articleid=36 But...
3
by: Bidarkota | last post by:
When i export DataGrid to Excel all the HTML contents are also exporting to excel. i am using stylesheets in the ASPX Page and i am getting an alert...
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". ...
0
by: Sridhar | last post by:
Hi, I am having trouble renaming the excel sheet while exporting to excel. we have a datagrid that contains some analytical data. I have the name...
0
by: kanepart2 | last post by:
Hi , I have the following code to export a datagrid to excel Public Sub ExportToExcel(ByVal dt As DataTable) Try Dim oApp As New...
3
by: nandithadevaraj | last post by:
When exporting a report to excel, is it possible to keep the properties around numeric values? More specifically - when exporting a report into...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

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.