Skip to content

Instantly share code, notes, and snippets.

@sancarn
Created January 2, 2026 17:36
Show Gist options
  • Select an option

  • Save sancarn/d47e4c361dc87e295640fc4a2a260fe4 to your computer and use it in GitHub Desktop.

Select an option

Save sancarn/d47e4c361dc87e295640fc4a2a260fe4 to your computer and use it in GitHub Desktop.
How to use Proj4 in OfficeScript
type Proj4 = (from: string, to: string, coords: [number, number]) => [number, number];
let loadedProj4 = false;
async function getProj4(): Promise<Proj4> {
if (!loadedProj4) {
const r = await fetch("https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.19.10/proj4.js");
new Function(await r.text())();
loadedProj4 = true;
}
return (globalThis as { proj4?: Proj4 }).proj4;
}
async function main(workbook: ExcelScript.Workbook) {
// Get the active cell and worksheet.
const selectedCell = workbook.getActiveCell();
const proj4 = await getProj4()
const [x, y] = proj4('EPSG:4326', 'EPSG:3857', [-0.1278, 51.5074]);
selectedCell.setValue(x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment