|
-
Feb 18th, 2004, 07:16 PM
#1
Thread Starter
New Member
how to: vb.net exporting datagrid to excel
Hi all
I am exporting the datagrid values to excel. that part is working fine. but when i export the data to excel i am loosing the leading zeros. does any one know how to do this?
Thanks
Last edited by toml; Feb 18th, 2004 at 08:03 PM.
-
Feb 19th, 2004, 11:26 AM
#2
Sounds like your data is being converted to a numeric data type somewhere along the way. If you can keep it as Text then you should keep the leading zeroes.
This world is not my home. I'm just passing through.
-
Feb 19th, 2004, 01:44 PM
#3
Thread Starter
New Member
can some one give me an example
-
Feb 19th, 2004, 10:28 PM
#4
Sleep mode
Something like this : When it's string type , it should pertain its zeros like trisuglow said .
VB Code:
Dim I As Integer
Dim Str As String = I.[B]ToString()[/B]
-
Aug 25th, 2004, 11:44 AM
#5
Lively Member
toml,
I am wanting to export some data out of my datagrid and into excel. Would you mind sharing this with me?
Thanks in advance!!
-
Aug 25th, 2004, 11:59 AM
#6
Hyperactive Member
how are you exporting the data?
Are you using the excel.application object to open a sheet and writing the data cell by cell, or are you opening a datatable using the oledb provider and connecting to your sheet file?
There are a few problems with either and it mostly pertains to how excel interprets the data you are sending to the sheet.
In general excel interprets all numeric data as Numerics, not string, so leading zeros will be truncated unless the column is formatted to display leading zeros.
It would be helpful to see the code you are using to export your data.
Whadayamean it doesn't work....
It works fine on my machine!

-
Aug 25th, 2004, 05:53 PM
#7
Addicted Member
If you are looking for a quick and dirty way to export to excel...
You can always export in HTML format... excel picks it up, including formatting, but be warned, the grid background dissapears like when u have a graph in excel (because excel is interpreting HTML).
Then again if you copy the data into a new excel document, the grids work fine.
In the example, dgrTemp is the datagrid to export
Code:
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
dgrTemp.RenderControl(hw)
dgrTemp.Dispose()
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = " "
Response.AddHeader("Content-Disposition", "inline;filename=Report.xls;")
Response.Write("<table border=0>")
Response.Write("<tr>")
Response.Write("<td style='font-family:Arial; font-size:12pt; font-weight: lighter'>")
Response.Write("<b>Report Name</b>")
Response.Write("<tr></tr>")
Response.Write("</td>")
Response.Write("</tr>")
Response.Write("<tr>")
Response.Write("<td>")
Response.Write("Date: " & Date.Now.ToShortDateString & " Time: " & Date.Now.ToShortTimeString)
Response.Write("</td>")
Response.Write("</tr>")
Response.Write("<td>")
Response.Write(tw.ToString)
Response.Write("</td>")
Response.Write("</tr>")
Response.Write("</table>")
Response.End()
If the facts don't fit the theory, change the facts. --Albert Einstein
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|