Updating Excel Spreadsheet with specific variables

I am working on getting numbers from certain sources and building out a report from the results. I have 4 variables that need to update a specific spreadsheet. The row they update will depend on the hour it is run. ColumnA will have certain hours in the following format: 7:00AM, if the job runs at 7:05AM it should input the variables into the 7:00AM row into Columns B,C,D,E respectively. Was wondering if there is any way to complete this as I am having a tough time. I can build out a database and input into the spreadsheet by specifying the specific cells but need this to be more dynamic.

Any help will be much appreciated.

Thank you!

Ok so i figured part of it out. I create a DataTable with all four variables and then i can use write range to input into the Spreadsheet. I also was able to read range inside the spreadsheet to turn the first column into a datetime datatable and compare the current hour to the hour in the first column whether or not to insert into the spreadsheet.

The only issue now is, how do I write to the cell of that row that has the current hour? I am only stuck on this part now.

Any advice would be greatly appreciated.

Thank you!

Hello,

You could get the current time of your system using

System.DateTime.Now.ToString(“hh”)

From this variable you could create a switch statement or dynamic selector using the current time to enter data into the correct rows and cells in your excel table

So I got the current time part now. I just can’t update the spreadsheet within the same row of that current hour now.

I just started to try datatable.rows.indexof(row) but unfortunately this is not working either. Wondering if there was any example of how that should work or if it could work here?