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

 

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″;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: