Skip to content

Instantly share code, notes, and snippets.

@theGove
Last active February 21, 2022 15:02
Show Gist options
  • Save theGove/cf0b94199b5b1a53a5abd7d7be0a4414 to your computer and use it in GitHub Desktop.
Save theGove/cf0b94199b5b1a53a5abd7d7be0a4414 to your computer and use it in GitHub Desktop.
Tools to help with the building of Excel myEducator assignments
function auto_exec(){
Jade.add_library("https://cdnjs.cloudflare.com/ajax/libs/yamljs/0.3.0/yaml.min.js")
const html=[]
html.push('<button onclick="showRangeForm()">Range Tools</button> ')
html.push('<button onclick="showRangeForm()">Task Tools</button> ')
Jade.open_canvas("Index", html.join(""))
}
//change and it is changed
function showRangeForm(){
/*Jade.listing:{"name":"Range Tools","description":"Show the tools for woring with ranges."}*/
const html = []
html.push(buildSelectedAddresses())
Jade.open_canvas("form", html.join(""))
}
async function selectedAddressesInteractive(format){
result=await selectedAddresses({format:format})
tag("pre-output").innerHTML = result
navigator.clipboard.writeText(result)
}
async function selectedAddresses(params){
return await Excel.run(async function(excel){
const range = excel.workbook.getSelectedRange()
range.load("address,formulas")
await excel.sync()
const addrparts = range.address.split('!')
const data = [
'data',
[addrparts[1]],
range.formulas,
]
if(params.format==="Object"){
return [data]
}else{
console.log('- ' + YAML.dump(data, 0).trim())
return '- ' + YAML.dump(data, 0).trim()
}
})
}
function buildSelectedAddresses(){
return html_panel("Build Selected Addresses",`Output Type: <select id="param"><option value="YAML">YAML</option><option value="Object">Object</option></select><button onClick="selectedAddressesInteractive(tag('param').value)">Convert</button>`)
}
function html_panel(title, html){
return `
<div id="div-4x" style="border: 1px solid; box-shadow: 5px 5px darkgrey;border-radius:.5rem; background-color:white;display:block;margin:2rem;padding:1rem;font-size:.8rem;">
<div style="margin-bottom:1rem;font-size:1rem;font-weight:bold">${title}</div>${html}<div style="margin-top:1rem;" id="output"><pre id="pre-output"></pre><div></div>`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment