Read Value From Excel File Step

Answered
0
0

Hi

I am encountering the following problem. I read a date value from an Excel file using the step “Read Value From Excel File Step”. This value is passed into a string variable within the step itself. However, when I try to extract only the date without the timestamp afterward, I get the following error:
“Unable to cast object of type ‘System.DateTime’ to type ‘System.String’”.

This happens when i try the “Get Subtext Step” or “Trim Text”.

This also happens if value is number in excel file, then i get the following error;

System.InvalidCastException: Unable to cast object of type ‘System.Double’ to type ‘System.String’.

  • You must to post comments
Great Answer
0
0

This issue is most likely caused by a data type mismatch. Even though the value is assigned to a String variable in the “Read Value From Excel File” step, the step actually returns the real data type from Excel, such as System.DateTime for date cells or System.Double for numeric cells, which can be verified in the Variable Repository. When text actions like Get Subtext or Trim Text are used, they expect a String but receive a DateTime or Double instead, resulting in the casting error. The solution is to explicitly convert the value to a string first, for example by using a “Convert DateTime to String” or “Convert Number to String” action, before applying any text operations.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.