?
Solved

datagrid excel

Posted on 2004-09-21
5
Medium Priority
?
229 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 1000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month7 days, 22 hours left to enroll

765 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