Solved

datagrid excel

Posted on 2004-09-21
5
220 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Comparing String Arrays. 5 39
Hey Audio! 3 27
Problem!!! 8 33
C# Gridview 1 27
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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

815 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

11 Experts available now in Live!

Get 1:1 Help Now