Urgent.News

What's breaking now, across thousands of outlets.

Tech

A Real .xlsx With Working Formulas in Plain JavaScript, No Library

I run a small free website, a time card calculator. You type in when you clocked in and out each day, it adds up the week, splits regular hours from overtime, and gives you something to hand over. It's built for hourly workers checking their pay, and for small business owners doing payroll for a handful of staff on a Friday afternoon. That last part, "something to hand over", is the bit that…

The author of a time card calculator website aimed to provide a proper .xlsx file for users to download their timesheets. Unlike CSV, which can misinterpret formatted cells as text or incorrect times, an .xlsx offers real dates, time cells, and accurate =SUM() formulas. The author achieved this using only 177 lines of code and a file size of 9 KB, without relying on any external JavaScript libraries.

The .xlsx file format is essentially a zip archive containing six essential files. The core file is the sheet data, written in XML format, containing the actual cells, strings, formulas, and their results. In the author's implementation, formulas and their answers coexist in the same cells, with the result cached in a variable for immediate display in Excel.

A key challenge was formatting the time durations correctly. Excel's default h:mm format wraps at 24 hours, leading to incorrect displays for longer durations. To resolve this, the author used a custom number format with square brackets: [h]:mm, which accurately represents durations longer than 24 hours.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Our lock expired while the first worker was still writing invoices

On the second of June two hundred and twelve of our business customers received their May invoice twice. Nine of them received it three times.

  • 212 clients received duplicate May invoices
  • Locks expired despite workers still invoicing
  • Issue resolved with fencing token and expiry alerts

More from Tuesday 13 October →