Creating Empty Datatable

I’m using UiPath to create a report twice a day.

Right now I’m taking the previous file then making my changes and saving to a new file.

I read an oracle database and save results from a query to a data table.

I need to clear a large section of data in order to the input new data but I cannot overwrite the data as the new data might have less rows than the current data. However when I use clear range activity all the formatting etc. goes away as well. I want to set each of the values in the range to null without affecting the current formatting of the cells. My current work around is using a copy/paste range activity and copying the empty cells below the table in excel and pasting the values only.

Is there a way to create a datable that only has null values to then use in a write data table to excel activity or is there a better solution?

We have understood so far

An existing Worksheet is to update
the new data is less and old rows are not deleted

When the idea is about creating a datatable with empty values and rows count of old data give a try at the following

Read range - dtOld
Assign Activity:
dtCleaner = Enumerable.Repeat(dtOld.NewRow, dtOld.Rows.Count).CopyToDataTable

No I’m Sorry.

I need to update a worksheet with data that is in a datable.

The current data in the worksheet may contain more or less rows than the data being inputted.

The old data is deleted.

I’m wondering if you can create a datatble with null values that is the same size as my datatable of results that are going to be inputted.

Hopefully that clears things up as I cannot describe this situation well.

Hi @simon.morley17 ,

Maybe if it is about clearing the sheet part, could also check the below method in post :

That doesn’t seem to cover what I’m looking for.

Basically all I’m needing to know is if there’s a way to create a data table of null values that can be entered into excel or a way of clearing an unknown size of data without using clear range activity as it gets rid of formatting also.

Thanks for the help.

HI @simon.morley17

You can use the Clone method to create a new DataTable with the same structure as the original DataTable. This new DataTable will have the same columns but no rows or data.

newDataTable = originalDataTable.Clone()

Now that you have a new DataTable with the same structure, you can replace the original DataTable with the new one.

Assign activity:
originalDataTable = newDataTable

Regards,
Gayathri M K