Conversion of General Data Type to an Integer

Hi All,

I am reading excel file through read range and then placed “For Each Row Loop” and inside this loop, I have put the If condition, pl. see below:

If row(“Excel_Column_Name”).Equals(0) Then Message Box.

But before or after this If condition I want to convert each cell value to an integer so that I should make further calculations. My Excel column’s data type is General not number.

Many thanks,

Hi @Dr_Raza_Abidi_PhD

Give try on below format!

Cint(row(“yourColumnName”).toString).Equals(0)

Regards

2 Likes

Hi @Dr_Raza_Abidi_PhD

Try this as well based on your convivence,

Int32.Parse(row(“yourColumnName”).toString).Equals(0)

OR

Int64.Parse(row(“yourColumnName”).toString).Equals(0)

1 Like

@pravin_calvin : Really grateful to you. Mission accomplished. But could you please also guide how to handle Null values? Because in my excel column there are null values exist other than zero.

Many thanks,

@Jobin_Joy : Really grateful to you. Mission accomplished. But could you please also guide how to handle Null values? Because in my excel column there are null values exist other than zero.

Many thanks,

You can filter your DataTable like this.

ExcelData.Rows.Cast(Of DataRow)().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or field.Equals(“”))).CopyToDataTable()

Hope this will helpful. Thank you.

Hi @Dr_Raza_Abidi_PhD

You Can try like below!

In If condition Not String.IsNullOrEmpty(Currentrow(“YourColumnname”).tostring)

Then part will return the values other than Null

Regards

@pravin_calvin : Thanks but I have a column, pl. see below and I want wherever my cell is empty/null or having zero value, I should replace with the value available in other column.

Column 1
0
7000000
1800000
5000000
1600000

100000
0
image

Hi @Dr_Raza_Abidi_PhD

Clarification needed! Do you need to fill the Corresponding cell value in the place of Empty cell?

Regards

Yes, indeed, I want to fill in the numeric values in the empty or zero values cell. These numeric values are already available in the adjacent column.

Hi @Dr_Raza_Abidi_PhD

Try using both the condition in if activity

String.IsNullOrEmpty(Currentrow(“YourColumnname”).tostring) or Cint(row(“yourColumnName”).toString).Equals(0)

Then Part proceed with

Currentrow(“Yourcolumnname”) =Currentrow(“yourAdjacent Column name”).ToString

Out side the loop Use write range and with Read range path and DT.

Regards

1 Like

Thanks,

This message received:

image

In my excel column there is one cell value is empty and others have zero values.

@Dr_Raza_Abidi_PhD

Try Debugging and get the error screen from Your flow for better understanding!

Regards

You are assigning a string value to a variable of type integer. Kindly debug and narrow down the place where exactly the error is occurred.

1 Like

@Jobin_Joy : Thank you very much. But my excel column has General data type. So, for this what should I do?

That’s only in excel file point of view, once the excel data loaded into DataTable things will change. In the DataTable, the data type will be DataColumnCollection object, then we are parsing to specific type. Ex: Int, Double etc based on our need/data.

Okay, got it but I am giving this condition

string.IsNullOrWhiteSpace(row(“My_Excel_Column”).ToString) Or String.IsNullOrEmpty(row(“My_Excel_Column”).ToString) Or Cint(row(“My_Excel_Column”).ToString).Equals(0)

But, It captures only zero cell values and replace the value. The last command is running and ignoring the two conditions, i.e., IsNullOrWhiteSpace and IsNullOrEmpty.

Can you please share the sample xaml file here. It will help us to understand the issue more precisely?

May be you can create a sample excel file based on your original and replicate the flow.

Thank you.

Hi @Dr_Raza_Abidi_PhD

Try replacing the first Condition ie String.IsNullOrEmpty with

Currentrow(“YourColumnName”) is Nothing

Regards