Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
This forum is where any logged-in member can create a knowledge article.
inspired by Useful Qlikview Macros
These javascript code snippets can be used in the ajax client in Chrome. (not webview since that is IE and making things work in IE is painful)
All of these are wrapped in anonymous function that are immediately called, so they can be used in a button 'open URL' action in the same window like below so you don't have to install any extensions. You have to modify to code to do more things together for it to be useful since single actions can be done without any javascript coding.
1) Download a pivot table or straight table chart object as csv:
(function(){
let convertObjectDataToCSV = function (data) {
let result,columnDelimiter, lineDelimiter, strDataCell;
columnDelimiter = ',';
lineDelimiter = '\n';
let wrapCSVCell = function(strCell){
if( typeof strCell === "string") {
strCell = strCell.replace(/"/g, '""');
if (strCell.search(/("|,|\n)/g) >= 0){
strCell = '"' + strCell + '"';
}
}
return strCell;
};
result = '';
result += data.HeaderRows.map(r => r.map(c => wrapCSVCell(c.text)).join(columnDelimiter)).join(lineDelimiter);
result += lineDelimiter;
result += data.Rows.map(r => r.map(c => wrapCSVCell(c.text)).join(columnDelimiter)).join(lineDelimiter);
return result;
};
let saveAsCsv = function(filename, data) {
let blob = new Blob([data], {type: 'text/csv'});
let elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = filename;
document.body.appendChild(elem);
elem.click();
window.URL.revokeObjectURL(elem.href);
document.body.removeChild(elem);
};
let GetObject = function(doc,objectID){
return new Promise(function(resolve){
doc.GetObject(objectID,function(){
this.DocumentMgr.RemoveFromManagers(this.ObjectMgr);
this.DocumentMgr.RemoveFromMembers(this.ObjectMgr);
resolve(this);
});
});
};
let GetObjectFullDataPage = async function (doc,objectID){
let tableObj = await GetObject(doc,objectID);
tableObj.Data.SetPagesize(tableObj.Data.TotalSize);
return GetObject(doc,objectID);
};
let exportTableAsCSV = async function(doc, objectID, filename){
saveAsCsv(filename,convertObjectDataToCSV((await GetObjectFullDataPage(doc,objectID)).Data));
};
exportTableAsCSV(Qv.GetCurrentDocument(),"CH01","export.csv");
}());