I have an Excel 2000 file with around 25 columns. In column18 the column name is "MONTH" and its data开发者_StackOverflow type is Date Time. The value is displayed as (1/5/2009) in format(dd/mm/yyyy).
I need to change its data type to string and display the data in this format: (01-05-2010).
Can anyone tell me how to change the data type and change the way we display the data?
- read the cell value
- depending on a number of factors, the datatype in .net will either be DateTime, string, or double.
- if type is not DateTime, then convert to DateTime. If string, then simply DateTime.Parse(), if double then use function here
- Convert DateTime to string with desired format. DateTime.ToString("yyyy'-'MM'-'dd"). This is a good resource for formatting dates.
- Set the cell's value to this string value.
精彩评论