Answered by:
Issue with date format when exporting to excel

Question
-
User1267402261 posted
Hi,
I have a grid where i have to filter the columns like multiple search filter and what ever records i get in the grid i am doing export to excel in c#Everything was went well except the date column in the grid the date column data is in this format 2014/11//15
here is my c# code which i am using to remove special charactersprivate void getfilterdata(string filter, out string key, out string val) { key = string.Empty; val = string.Empty; if (!string.IsNullOrEmpty(filter)) { string[] retval2 = filter.Split(new string[] { "data" }, StringSplitOptions.RemoveEmptyEntries); if (retval2 != null && retval2.Count() > 1 && !string.IsNullOrEmpty(retval2[1])) { string[] strkeys = retval2[0].Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries); if (strkeys.Length >= 3 && !string.IsNullOrEmpty(strkeys[3])) { key = strkeys[3]; val = RemoveSpecialCharacters(retval2[1]); } } } } In the key its shows column name and in the val it shows data.. in the val i am getting data as 20141115. So its not matching and while exporting its empty i am not getting any records becaus e of this this is my code for RemoveSpecialCharacters public static string RemoveSpecialCharacters(string str) { return Regex.Replace(str, "[^a-zA-Z0-9_.]+", "", RegexOptions.Compiled); }
Any help plz.....
Saturday, November 15, 2014 12:25 PM
Answers
-
User1508394307 posted
Well, the "workaround" is not to use that method (at least not for the date column) because / is not a special character. In other case, just add / in
[^a-zA-Z0-9_./]+
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, November 17, 2014 11:10 AM
All replies
-
User1508394307 posted
You replace all characters except a-zA-Z0-9_. and that's why / was replaced in 2014/11/15
Saturday, November 15, 2014 4:00 PM -
User1267402261 posted
What is the workaround now....what is the new method i can use for removingspecialcharacters..
Monday, November 17, 2014 10:25 AM -
User1508394307 posted
Well, the "workaround" is not to use that method (at least not for the date column) because / is not a special character. In other case, just add / in
[^a-zA-Z0-9_./]+
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, November 17, 2014 11:10 AM -
User-1910946339 posted
What result do you want?
Show us some sample input and the result that you want generated for each sample input.
Friday, November 21, 2014 12:52 AM