c# – How to export a Datatable to Excel without it formatting the information?

Question:

I need to export a number to Excel but it always formats improperly.

Expected shape: -8,0902322222234

Received: -809.023.222.222.234

Datatable columns data are string typed. Data is displayed in a DatagridView .

Before being exported, they appear as expected.

Answer:

Prefix the data with a single quote ' in the export.

For Excel, data prefixed with ' is interpreted as text, and will not be formatted or interpreted.

The single quote, when in the 1st character, does not appear on the display.

Important:

Being strings , numeric data will no longer be right-aligned by default in LTR languages, nor will dates and percentages work as such.

Scroll to Top