Skip to content

Instantly share code, notes, and snippets.

@mjschutz
Created May 4, 2022 13:16
Show Gist options
  • Save mjschutz/4bbf89a37183fb63e649bcfe1ca8204a to your computer and use it in GitHub Desktop.
Save mjschutz/4bbf89a37183fb63e649bcfe1ca8204a to your computer and use it in GitHub Desktop.
<script src="http://cdn.jsdelivr.net/g/filesaver.js"></script>
<script src="https://cdn.jsdelivr.net/npm/exceljs@4.3.0/dist/exceljs.min.js" integrity="sha256-wJUdjGj95YIQF7RrY8E0M/aU998QyfG6xYKtQLp05/I=" crossorigin="anonymous"></script>
<script>
function SaveAsFile(t,f,m) {
try {
var b = new Blob([t],{type:m});
saveAs(b, f);
} catch (e) {
window.open("data:"+m+"," + encodeURIComponent(t), '_blank','');
}
}
async function saveAsExcel() {
const wb = new ExcelJS.Workbook()
const ws = wb.addWorksheet()
const row = ws.addRow(['a', 'b', 'c'])
row.font = { bold: true }
const buf = await wb.xlsx.writeBuffer()
SaveAsFile(buf,"abc.xlsx","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment