How do you prevent leading zeros from being stripped when importing an excel doc using c#

Question!

I'm able to connect to and read an excel file no problem. But when importing data such as zipcodes that have leading zeros, how do you prevent excel from guessing the datatype and in the process stripping out leading zeros?



Answers

Add "\t" before your string. It'll make the string seem in a new tab.



Sending value 00022556 as '=" 00022556"' from Sql server is excellent way to handle leading zero problem



Saving the file as a tab delimited text file has also worked well.

---old Unfortunately, we can't rely on the columns of the excel doc to stay in a particular format as the users will be pasting data into it regularly. I don't want the app to crash if we're relying on a certain datatype for a column.

prefixing with ' would work, is there a reasonable way to do that programatically once the data already exists in the excel doc?



This video can help you solving your question :)
By: admin