finalized version of spreadsheet.php

to be debugged