Article : Avoid default formatting when exporting data from datagrid to excel

October 14, 2010

 

After one year I wrote an article in CodeProject . I used to wrote articles during my stay in Proteans.After that I joined in Skelta. Now I left

And the link is :

 http://www.codeproject.com/Tips/118240/Avoid-default-formatting-when-exporting-data-from-.aspx 

Content of the application :

RenderControl method of Datagrid : Helps in exporting the grid data to excel.

But for dates,currencies, numbers it will automatically formats that data. The user has little or no control on that through code.

Say for eg: 123343423434 number converts into exponential number.

If the user doesnt deserves the formatting

either one has to preface the data with an apostrophe.

or select the column Format cells->General->Select the required one (Number ,Currency,Date) as per the requirement.

One cannot “set” Excel to stop thinking those are dates.

The work around is

For formatting the text use

mso-number-format:”\@”;

For formatting the currency use

mso-number-format:”022$022\#\,\#\#0\.00″;


Follow

Get every new post delivered to your Inbox.