The base-26 part that trips everyone
Spreadsheet columns look like base-26 with the letters A-Z standing in for digits, but they aren't quite. Real base-26 has a zero; spreadsheet columns don't. There's no column whose label is empty, and after Z (26) you get AA (27), not BA. That off-by-one is why a naive String.fromCharCode(64 + column) falls apart the instant you cross column 26 and starts emitting punctuation like '[' for column 27.
The fix is the (n - 1) % 26 and Math.floor((n - 1) / 26) pair. Subtracting 1 before each step shifts the math into a system where A behaves like 0 inside the digit, but the labels still read 1-based. So 27 becomes remainder 0 (an 'A') plus a carry of 1 (another 'A'), giving 'AA'. The loop prepends each letter because we generate the least-significant digit first, same as you would converting any number to a positional base by hand.
I keep this exact function in a utilities file and have copied it into more projects than I can count. It is fifteen lines, it has no dependencies, and it is correct up to column 16384 (XFD), which is as far as Sheets goes anyway.