How to append string in the for loop?

I am beginner of RPA but I can handle python.

I would like to use RPA instead of python to control code below.

import pandas as pd

df = pd.read_excel(‘wdwdwd.xlsx’) # only one column ‘A’
str_a = ‘’
for num in range(df.shape[0]) :
str_a = str_a + df[‘A’].iloc[num] + ‘\n’

I would like to get ‘str_a’.
but I can not find the way to do same above.

@SH_K

  1. use read range activity to read the excel into datatable dt
  2. use requiredstr = String.Join(Environment.NewLine,dt.AsEnumerable.Select(function(x) x(0).ToString))

this will get full first column values concatenated with newline character

cheers

Hi,

Can you try the following?

 strResult = String.Join(vbCrLf,dt.AsEnumerable.Select(Function(r) r(0).ToString))

Regards,

Hi @SH_K ,

Try using the Combination of Read Range Workbook and For Each Row in Datatable activities as a First Try, you should be able to get the idea and work towards building the same logic for concatenating values to the variable.

@SH_K

  1. Use the “Read Range” activity to read the Excel file into a DataTable.
  2. Initialize a variable (let’s call it str_a) as an empty string.
  3. Use a “For Each Row” activity to loop through the DataTable.
  4. Inside the loop, append the value from column A of each row to the str_a variable with a line break.

cheers…!