Hello!
I need to read some dates from excel and put them in another excel but I need to keep the format. The problem is that not always I get a date cause some dates are not set yet, so sometimes I read a date and sometimes I get a -
I try many things but I just can’t make it work as I want… I’ll explain
My columns in the data table of Uipath and Excel need to be datetime type, cause I have to use them on a formula in another cell.
- If I read the cells as a string, and then use a write range, if excel cells are date format, it always write them as MM/dd/yyyy when I want to keep the format dd/MM/yyyy. But it writes the “-” correct as it is a string.
So I need to manage them as DateTime variables
-
If I make a variable type datetime called X and convert the string variable Yey of the excel (22/01/2022) it with X = DateTime.ParseExact(Yey,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
it works fine, the write range activity keeps the format en excel, the problem is that convert every cell is not an option cause I have these values “-”, so when the assign activity tries to convert X=DateTime.ParseExact(“-”,"dd/MM/… It gets an error, and I cant put another value to that variable cause it is a “-” not a date -
I tried to replace the “-” with another date, so now I can convert all X variables to Datetime but when I try to replace them again with a “-” it puts the wrong format in the others cause its making them a string again
-
i tried to use “format value” activity with generic value so I can "if X <> “-”, then convert value to date, else nothing, but I get an error “cant convert generic value to datetime”
-
I tried “try catch” try parse the generic value to a date, exception “-” … nothing, got an error cant convert generic to datetime
I surrender, I just dont know what to do
How read a cell, if its a date, keep the format dd/MM/yyyy and if its not, leave the “-” as they are?
Thanks for reading me.
Sorry if I wrote something wrong, not my language.