Solved

datagrid excel

Posted on 2004-09-21
5
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

696 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