c# – HTML table copy paste data to Excel without 1000s separator-ThrowExceptions

Exception or error:

Server code generates HTML table (Bootstrap 3), where numbers for easy reading are formatted with 1000s / group separator as space. This is done with .ToString("#,0.00"). However space is encoded in HTML as  . This creates a problem once copied and pasted into Excel, as is not recognised as a number.

I am looking for a solution how to solve this, so that the numbers in html table pasted into Excel will be recognised as numbers, without need for cleaning it up in Excel.

Update 1.

This legacy ASP.NET WebForms application. I have tried both <%# %> (data-binding expression) and <%#: %> (HTML encoded data-binding expression) server-side scripting delimiters. However both to my surprise encode space as &nbsp;.

How to solve:

Are ordinary spaces pasted into Excel correctly? You can create a custom culture with thousand separator set to ordinary space instead of non-breaking one and use it when converting numbers to string then

Leave a Reply

Your email address will not be published. Required fields are marked *