I’m providing a screenshot of the current state of my report.. to what i needs to be. Basically, need a script that appends line number 2 into number one, separated with a comma. All in one line.
Merge Line 2 into Line 1 with Comma
- Read Text File → fileContent (String)
- Assign → modifiedContent:
Dim lines = fileContent.Split({Environment.NewLine}, StringSplitOptions.None)
If lines.Length >= 2 Then
lines(0) = lines(0).TrimEnd() + ", " + lines(1).Trim()
String.Join(Environment.NewLine, lines)
Else
fileContent
End If
- Write Text File → same path, modifiedContent (overwrite)
Test: Debug → Breakpoint on Assign → Check Locals panel. Works for any 2+ line file. Copy file first!
Hi ![]()
You can achieve this by reading the file, merging line 2 into line 1 with a comma, and then writing it back.
Steps in UiPath:
Use Read Text File → store output in a String variable (e.g., fileContent)
Use an Assign activity with the below logic
Use Write Text File to overwrite the same file
Dim lines = fileContent.Split({Environment.NewLine}, StringSplitOptions.None)
If lines.Length >= 2 Then
lines(0) = lines(0).Trim() & ", " & lines(1).Trim()
fileContent = lines(0)
End If
This will merge line 2 into line 1, separated by a comma, and keep everything in a single line.
This (Screenshot) is where I’m currently at the script. Please forgive me but im fairly new to the app. saying that, Where do i place the provided lines?. Also, im working on excel, not text. it’s already on a DataTable.
Hello @jans.delossantos
You could:
- Clone the structure from your initial/current datatable
- Create a new row in the finished datatable
- Iterate the Rows and Columns in the initial datatable
- Add/append values in the row
- Add data row to datatable for finished report
See attached image for reference.
You can download the file below.
Download here: Report.xaml (12.7 KB)
Regards
Soren
Forgive me but where do i plug this??
1/ What is format of your source data? Excel? Text file?
2/ What is format of your result data? Excel? Text file?
3/ Source is always header + two lines?
If possible provide source and result mockups
Cheers
Im doing a Dispatcher to it can send this information to the Orchestrator and my Performer can grab from there on. That’s the basic.
The Source is Microsoft Excel Comma Separated Values File (.csv)
I need to format the content as shown in screenshot, so i only have 1 line instead of 2 or 5 or more, for it can vary (unfortunately).
Attached its where I’m in the code, i know is not much that’s why I’m kindly asking for assistance.
Here’s a simple VBA script to combine row 3 into row 2, separated by commas, all in one line per column:
Sub CombineSecondRowIntoFirst()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets(“Sheet1”)
Dim lastCol As Long
lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
Dim col As Long
For col = 1 To lastCol
Dim firstValue As String
Dim secondValue As String
firstValue = ws.Cells(2, col).Value
secondValue = ws.Cells(3, col).Value
If firstValue <> “” And secondValue <> “” Then
ws.Cells(2, col).Value = firstValue & ", " & secondValue
ElseIf firstValue = “” Then
ws.Cells(2, col).Value = secondValue
End If
ws.Cells(3, col).ClearContents
Next col
End Sub
Run this in Excel VBA to merge the data.
In the current datatable, even if there are multiple same rows of same value, you want to merge it into one. Eg: you have three rows of same value, even then you want it in output as three values separated by comma ?
Is their a specific reason you are doing it ?
Also, if not, you can just filter datatable using linq to remove duplicates and process only one row.
in row3 add this formula in each of the columns that you need…
=CONCAT(TEXT(A1,“0”),“,”,TEXT(A2,“0”))
it converts you text representation of your number in both row1 and row2 to number and then concats it with comma(,), adds the result to row3.
SG.




