When I built the time card calculator on mytimecardcal.com, the export button was an afterthought. The calculator already did the hard work: it added up the hours, split regular time from overtime, and showed the weekly total. Printing felt like enough. Then a friend who runs payroll for a small cleaning company told me the printout was useless to her. She did not want a picture of the week. She wanted the numbers in a file she could open, check, and feed into her payroll software. That file is a CSV, and building a good one taught me more than I expected.
A CSV looks simple. It is just rows of values separated by commas. The trouble starts with the details that spreadsheet software cares about and that a hand-rolled export gets wrong.
The first problem is the header row. A CSV with no headers is a guessing game, so the export starts with plain column names: Date, Clock in, Clock out, Break (mins), Regular hours, Overtime hours, Total hours. Every row after that follows the same order, one row per day. Keeping the columns fixed matters more than it sounds. Payroll software maps columns by position, not by name, so a missing column in the middle silently shifts every value after it. I build each row from a fixed array of fields rather than stringing values together by hand, so a blank field still leaves its comma in place.
The second problem is the comma itself. Times like 9:00 AM are safe, but a notes field or a shift label can contain a comma, and one stray comma breaks the whole row. The rule I coded is simple: if a value contains a comma, a quote, or a line break, wrap it in double quotes and double any quotes inside it. That is the whole of the RFC 4180 quoting rule, and it is the difference between a file Excel opens cleanly and one that scatters a single shift across three columns.
The third problem is the way Excel reads numbers. A time like 08:30 typed into a cell gets treated as a time of day, not eight and a half hours. So the export writes hours as plain decimal numbers — 8.5, not 8:30 — and leaves the clock times in their own columns as text. The decimals are rounded to two places with toFixed(2) before writing, because a value like 7.999999999 from floating point maths looks like a bug to anyone reading the sheet, even though the total underneath is right.
The fourth problem is the download itself. The whole calculator runs in the browser, with no server, so there is nowhere to ask for a file. The fix is a Blob: build the CSV string in memory, wrap it in new Blob([csv], { type: 'text/csv' }), create an object URL, and trigger a download from a temporary anchor element. The filename carries the week, something like timecard-2026-11-16.csv, so a folder full of exports stays readable. The one extra line that mattered most was prepending a UTF-8 byte order mark (\uFEFF) to the file. Without it, Excel on Windows opens the file and mangles any non-English characters in a name or note. With it, the same file opens cleanly.
None of this is clever code. It is about forty lines of JavaScript, and most of it is edge cases. But it changed how the calculator gets used. A printout is a dead end: you can look at it, and that is all. A CSV is a handoff. The worker checks their hours, the manager opens the same file, and the numbers move on to payroll without anyone retyping them. That is the whole point of a tool like this — not to be impressive, but to fit into the boring, real workflow that already exists.
If you are building any kind of calculator or tracker in the browser, add the export early. The users who need it will not ask for it twice, and the format they want is almost always the dullest one available.