Solved

datagrid excel

Posted on 2004-09-21
5
219 Views
Last Modified: 2010-04-15
Hi everyone,

When exporting to excel, I find that my 0's are being truncated. i.e. 0.00  will show on excel as -> 0

How can I correct this behavior?

Thank you.
0
Comment
Question by:testn1
  • 3
5 Comments
 

Author Comment

by:testn1
ID: 12116693
 
Response.Clear();
Response.Buffer= true;

Response.ContentType = "application/vnd.ms-excel";


    response.ContentType = "application/vnd.ms-excel"

    Dim stringWrite As New System.IO.StringWriter
 
    Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
   
    Dim dg As New DataGrid

    dg.DataSource = ds.Tables(0)

    dg.DataBind()

    dg.RenderControl(htmlWrite)

    response.Write(stringWrite.ToString)
    response.End()
0
 
LVL 9

Expert Comment

by:s_sansanwal
ID: 12116770
By Default Column format in Excel is "General"

Right click on the column and select "Format Cells"
Now, on number Tab, select "Number" and press OK

Now, excel would display 0.00 properly


Cheers
S Sansanwal
0
 

Author Comment

by:testn1
ID: 12116846
that's exactly what I need but, automatically from the c# code.. before the excel file is created...
0
 
LVL 1

Accepted Solution

by:
micaiah earned 250 total points
ID: 12118009
You can force excel to display the number as text (i.e., exactly as entered) by prepending a single quote (apostrophe) to the number ( so 0.00 --> '0.00 ). Of course, your source column will have to be text / varchar (or converted to it) first.
0
 

Author Comment

by:testn1
ID: 12128284
ok,i prepended a ' and the outpput in excel is:   '0.00
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now