ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   setting cell contents to text using C# (https://www.excelbanter.com/excel-programming/285703-setting-cell-contents-text-using-c.html)

No Name

setting cell contents to text using C#
 
When dumping data into an excel
sheet programmatically using C#,
I run into the problem of
Excel auto-formatting the cells
based on the contents of the cells.
For example, when placing a string
of numbers such as '0000234', the
cell will turn it into the number 234.
We need to keep the preceding 0's for
data integrity. Is there a way in C#
to programmatically specify the cell format (such
text, number, etc.) so that Excel will
not automatically decide the cell's data format?

Thanks.


Bill Manville

setting cell contents to text using C#
 
When dumping data into an excel
sheet programmatically using C#,
I run into the problem of
Excel auto-formatting the cells
based on the contents of the cells.


I guess the question is how you are "dumping" the data.
If you can set the NumberFormat of the cell to "@" (for text) before
setting its Value property then the leading zeros should remain.

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup



All times are GMT +1. The time now is 04:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com