Use below C# code in invoke code activity
where io_dt is In Out parameter of type DataTable
DataTable dt = io_dt;
dt.Columns.Add("Category");
string currentSection = ""; // Variable to track the current section
try{
foreach (DataRow row in dt.Rows)
{
// Check if the current row is a section header (i.e., column 3 (total) is null)
if (string.IsNullOrEmpty(row[2].ToString()) && !string.IsNullOrEmpty(row[0].ToString()))
{
// Current row is a section header, set the section name from Invoice# (Column 0)
currentSection = row[0].ToString();
Console.WriteLine("currentSection: "+currentSection);
continue; // Skip the section header itself
}
// Skip the second row of each section (i.e., the headers like "Invoice#", "Vendor", etc.)
if (row[0].ToString() == "Invoice#")
{
continue;
}
// Set the value of (Column 3) based on the section name
if (!string.IsNullOrEmpty(currentSection))
{
row[3] = currentSection; // Set Category in Column 3
Console.WriteLine(row[3].ToString());
}
}
}
catch(Exception ex){
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
io_dt = dt;