Here's another solution. It's a little known fact that Google Sheets supports conditional formatting rules for borders when those rules have been imported from an Excel file.
I took your sample spreadsheet and exported it as an Excel file. Once opened in Excel, I created the following three CF rules.
First row: For C10:G10, I applied the solid top, left, and right border along with the dotted line for the bottom using custom formula:
=COUNTA($C10:$G10)>0.
Mid rows: For C11:G100, I used the solid left and right borders plus the dotted top and bottom border using custom formula:
=COUNTA($C11:$G11)>0.
Bottom row: For the same range, I used the custom formula:
=(COUNTA($C11:$G11)=0)*(COUNTA($C10:$G10)>0)>0
This identified the bottom row, for which I made the top border dotted and the left, right, and bottom borders solid.
Once those were created, I downloaded the .xlsx file and imported it into Sheets.
The result, instant dynamic borders without the use of Apps Script.