Write to excel just 1 row from datatable

Now im creating a report for rpa process. I have a datatable contains those report and the status (DTForReport).
Imagine the dt like this;

image

Robot must write the DTForReport to excel report file. The excel have same column like DT. This excel report file will always update. The objective are:

  1. check a reference from DTForReport to Excel Report file. If exist, robot must update/change value in the column status and remarks in Excel file with the new one from DTForReport.
    I have no issue for this.

  2. check a reference from DTForReport to Excel Report file. If NOT exist, robot must add those reference (complete row) to the excel file. Im a little bit confuse how to do this.

so my workflow came from for each row in DTForReport .
a. first, look up a reference in excel. if found, robot will use write cell to update status & remarks column in spesific row.–> DONE
b. if not found, how to add the current row ??? cause if u use write range, u have to provide datatable for input, however u are in the for each row activity, same with append range.If u use write cell, it will be to long, cause i have more than 20 columns.

image

appreciate for the answer. thx

@llayla

When row not found…use as below

Have a datatable newdt

Now newdt = dt.Clone() this will ensure newdt has same structure as dt and creates a empty datatable…this can be used before for loop

Then use add data row activity with datatable as newdt and array row with values {currentrow(0).ToString,currentrow(1).ToString,so on… ,varstatus}…thsi is to be used inside for loop

Then use append range with newdt this can be used after for loop to add all new rows at once

Hope this helps

Cheers

good idea, thank u for your help

You could try the below Linq too:

Dt = yourDt.AsEnumerable.Take(1).CopyToDataTable

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.