Assuming you were backing up the computer using Time Machine ( Back up your Mac with Time Machine ) then your data is safe. However if you were not backing up the computer and the HD has failed on the 2007 then all of the data on the HD is gone and cannot be recovered. If the HD is NOT why the computer failed then you can remove the HD from the computer using the directions in:
2007 20" iMac instructions for removing the HD:https://eshop.macsales.com/installvideos/imac_20_0708_hd/iMac7-1-20/
2007 24" iMac instructions for removing the HD: https://eshop.macsales.com/installvideos/imac_24_0708e09_hd/iMac7-1-24/
You can put the HD in an enclosure ( https://eshop.macsales.com/item/OWC/ME3NH7T00/ ) and connect it to another Mac and recover your data. This assumes that the HD is still working okay.
On such an old Mac you would best be served to take it to your local independent Apple Authorized Service Provider ( Apple Authorized Service Provider Locator (AASP) & Genius Appointment ) and have them diagnose it.
Good luck, you have quite a project on your hands!