Last active
February 21, 2022 15:02
-
-
Save theGove/ca0159f2543a9b2b4271d280fa7c0aa1 to your computer and use it in GitHub Desktop.
A JADE module to download a pdf of the currently selected range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function auto_exec(){ | |
Jade.open_automations(true, "Automations", [ | |
{action:"Excel.run(make_pdf)", | |
name:"Make a PDF", | |
description:"Builds and downloads a PDF file"} | |
]) | |
Jade.add_library('https://cdn.jsdelivr.net/npm/pdfmake@latest/build/pdfmake.min.js') | |
Jade.add_library('https://cdn.jsdelivr.net/npm/pdfmake@latest/build/vfs_fonts.min.js') | |
Jade.add_library('https://cdn.jsdelivr.net/npm/html-to-pdfmake/browser.js') | |
} | |
async function make_pdf(){ | |
const html = await range_to_html_table() | |
const val = htmlToPdfmake(html); | |
createPdf({content:val}).download(); | |
} | |
async function range_to_html_table(){ | |
return await Excel.run(async function(excel){ | |
const range = excel.workbook.getSelectedRange() | |
range.load("values") | |
await excel.sync(); | |
const table=['<table style="border-collapse: collapse;border: 1px solid black;">'] | |
for(const row of range.values){ | |
table.push("<tr>") | |
for(const col of row){ | |
table.push("<td>") | |
table.push(col) | |
table.push("</td>") | |
} | |
table.push("</tr>") | |
} | |
table.push("</table>") | |
return table.join("") | |
}) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment