=ARRAYFORMULA(
REGEXREPLACE(
TRANSPOSE(QUERY(TRANSPOSE(D1:G&"|"),,COLUMNS(D1:G))),
"(\|\s*)+",
", " )
)
={"В строку";ARRAYFORMULA(REGEXREPLACE(
REGEXREPLACE(
TRIM(TRANSPOSE(QUERY(TRANSPOSE(D2:G&"|");;COLUMNS(D2:G))));
"(\|\s*)+";
", " );
"(^,\s*)|(,\s*$)";
""
))}