Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

datagrid excel

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
testn1
Asked:
testn1
  • 3
1 Solution
 
testn1Author Commented:
 
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
 
s_sansanwalCommented:
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
 
testn1Author Commented:
that's exactly what I need but, automatically from the c# code.. before the excel file is created...
0
 
micaiahCommented:
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
 
testn1Author Commented:
ok,i prepended a ' and the outpput in excel is:   '0.00
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now