Skip to content

Instantly share code, notes, and snippets.

@theGove
Last active February 21, 2022 15:02
Show Gist options
  • Save theGove/85e5314f59bc821533b11687fd616585 to your computer and use it in GitHub Desktop.
Save theGove/85e5314f59bc821533b11687fd616585 to your computer and use it in GitHub Desktop.
A JADE module to export the active worksheet as a tab-separated-variable file
function auto_exec(){
const data=[
{action:"Excel.run(save_as_tsv)",
name:"Save as TSV",
description:"Saves the data on the active sheet as a tab-seaparated-varible file"}
]
Jade.open_automations(true, "Automations", data)
}
async function save_as_tsv(excel){
/*Jade.listing:{"name":"Save as TSV","description":"Saves the data on the active sheet as a tab-seaparated-varible file"}*/
const sheet = excel.workbook.worksheets.getActiveWorksheet()
const range = sheet.getUsedRangeOrNullObject(true)
range.load("values")
sheet.load("name")
await excel.sync();
if(range.isNullObject){
alert("No data on active sheet")
}else{
const table_data=[]
for(const row of range.values){
const row_data=[]
for(const col of row){
row_data.push(col)
}
table_data.push(row_data.join("\t"))
}
download_tsv(table_data.join("\n"), sheet.name)
}
}
function download_tsv(tsvString, filename){
var a = document.createElement('a');
a.href = 'data:attachment/tsv,' + encodeURIComponent(tsvString);
a.target = '_blank';
a.download = filename + '.tsv';
document.body.appendChild(a);
a.click();
}
@theGove
Copy link
Author

theGove commented Jan 2, 2022

This code is designed to work with the JavaScript Automation Development Environment (JADE) add-in for Microsoft Excel Install the add-in from the add-in store then select "Import a Code Module" and enter the id of this Gist: 85e5314f59bc821533b11687fd616585 Then click the "Run" button. More information at https://support.jsvba.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment