Linq UI path

How to merge two sheets and write into one using linq and also how can we get empty fields in excel in Ui Path

Hey @Taruna_Gupta ,

Try using

dt1.AsEnumerable().Union(dt2.AsEnumerable())

Hi @Taruna_Gupta

For Merging two sheets use the below linq:
// Assuming dtSheet1 and dtSheet2 are your DataTable variables

var mergedData = dtSheet1.AsEnumerable().Concat(dtSheet2.AsEnumerable()).CopyToDataTable()

For getting empty fields try in this way:

// Assuming dtExcelData is your DataTable variable
foreach (DataRow row in dtExcelData.Rows)
{
    foreach (DataColumn col in dtExcelData.Columns)
    {
        if (string.IsNullOrEmpty(row[col.ColumnName].ToString()))
        {
            // Handle empty field, e.g., add to a list or perform some action
        }
    }
}

Hope it helps!!

@Taruna_Gupta

Gives you the common rows oftwo datatable
dt1.AsEnumerable().Intersect(dt2.AsEnumerable(),System.Data.DataRowComparer.Default).CopyToDataTable

gives you entire rows of two datatable

dt1.AsEnumerable().Union(dt2.AsEnumerable(),system.Data.dataRowComparer.Default).copyTo Datatable

to get only empty rows

DataTableName=DataTableName.Rows.Cast(Of DataRow)().Where(Function(row) row.ItemArray.All(Function(a) a.Equals(“”))).CopyToDataTable()

hope this helps