I am unable to find the solution for merging the cell by LINQ and as well in UiPath.
Check the data in a specific column(“ID”), and if they are the same, please merge the cells.
This is the current form
ID
Code
A
AB-776
A
ABC-123
B
BBB-666
B
DDD-8888
Output…
I am unable to fully convey the image I want.
ID
Code
AB-776
A
ABC-123
B
BBB-666
DDD-8888
Just need the solution in LINQ or UiPath.
Thanks in advance!
Using wb As New ClosedXML.Excel.XLWorkbook(filename)
Dim sheet As ClosedXML.Excel.IXLWorksheet = wb.Worksheet(sheetname)
Dim previous As String =""
Dim r As Int32 =1
Dim c As Int32 =targetColumnIndex
Dim cLetter As String = UiPath.Excel.Helpers.ExcelUtilities.ConvertColumnIndexToColumnLetter(c)
Dim startRow As Int32 =1
Dim mergeHeight As Int32 =1
While(True)
Dim cell As ClosedXML.Excel.IXLCell = sheet.Cell(r,c)
If (cell.Value.ToString<>previous) Then
If mergeHeight>1 Then
Dim range As ClosedXML.Excel.IXLRange = sheet.Range(cLetter+startRow.ToString+":"+cLetter+(startRow+mergeHeight-1).ToString)
range.Merge()
End If
mergeHeight =1
startRow=r
r=r+1
previous =cell.Value.ToString
Else
r=r+1
mergeHeight =mergeHeight+1
End If
If(cell.Value.ToString="") Then Exit While
End While
wb.Save()
End using
Does the above sample work? or throw error?
If you use another input file, can you share it? It’s no problem dummy data if the issue can be reproduced.