Datable to excel Issue

Hey all. I have this group of validations to run and they all have try catches to them. If it catches any errors, it writes them to a data table and writes that data table to an Excel file. This is causing many issues.

the first thing I do is create a datable, then I add the contents of the caught error to the database row


then I append that data to the Excel file


whenever I use append range. 1. it always adds all the headers to each new error which I would like to remove. Is there a way I can write range (so it adds headers for the first one) and then use append for the others? I might not have described it well but I could use some help

Show us your Build Data Table, how it’s configured.

Screenshot 2023-09-19 092559

@cemenike

Looks like some where the header is being written as a row again…can you debug and check that please

cheers

Put a breakpoint on the Append Range activity then run in Debug. When it pauses, click the pencil next to the dataRow_toAppend variable, and show us what’s in the datatable.

Also, what’s the point of the Output Data Table? That’s not necessary.

I originally had the first row saved as “Filename”, “ValidationName” and “ExceptionMessage” because append does not give me the option to add headers.

That’s because you’re appending and it expects headers to already be there. You’ll need to set up your logic so that if it’s the first time you’re writing to the Excel file (can be done with File Exists) it uses Write Range with headers, and if it’s not the first time you use Append Range.

Yes i figured this might solve that. Would I just simply read the excel file and check if data row 0 is empty and write range for that one and for ELSE: append range?

The first time you write to Excel, the file doesn’t exist, right? Just check if the file exists.

If System.IO.File.Exists(destinationPathAndFilename)
Then Append Range
Else Write Range with headers