Petter Duffett-Smith wrote a book, Practical Astronomy With Your Calculator which includes algorithms for calculating sunrise and sunset, and many other astronomical events. A later version with co-author Jonathan Zwart includes instructions on using spreadsheets to calculate events. I used the...