Excel Automation: Merge the cells into single row

image
I am trying to write the item in single cell for every DO

String.Join(“,”, dt_InputDO.AsEnumerable().Where(Function(row) Not String.IsNullOrEmpty(Convert.ToString(row(“Itm”)))).Select(Function(row) Convert.ToString(row(“Itm”))).ToArray())

with the help of above code, I’m able to write into single cell for whole column. But I want write for every DO

OUTPUT has look like this
image

Hi @Sai17

Try this:

dt_InputDO = (From row In dt_InputDO.AsEnumerable()
              Group row By Key = Convert.ToString(row("DO")) Into Group
              Let ItmValues = String.Join(", ", Group.Select(Function(r) Convert.ToString(r("Itm"))))
              Let Email = Group.First(Function(r) Not String.IsNullOrEmpty(Convert.ToString(r("email"))))("email")
              Let Mobile = Group.First(Function(r) Not String.IsNullOrEmpty(Convert.ToString(r("mobile"))))("mobile")
              Select dt_InputDO.Rows.Add(Key, ItmValues, Email, Mobile)
             ).CopyToDataTable()

Assign: Sequence contains no matching element
throwing this error

@Sai17

Try this:

dt_InputDO = (From row In dt_InputDO.AsEnumerable()
              Group row By Key = Convert.ToString(row("DO")) Into Group
              Let ItmValues = String.Join(", ", Group.Select(Function(r) Convert.ToString(r("Itm"))))
              Let Email = Group.FirstOrDefault(Function(r) Not String.IsNullOrEmpty(Convert.ToString(r("email"))))
              Let Mobile = Group.FirstOrDefault(Function(r) Not String.IsNullOrEmpty(Convert.ToString(r("mobile"))))
              Where Email IsNot Nothing AndAlso Mobile IsNot Nothing
              Select dt_InputDO.Rows.Add(Key, ItmValues, Convert.ToString(Email("email")), Convert.ToString(Mobile("mobile")))
             ).CopyToDataTable()
1 Like

image
this is the output