Export a Json object to a text File - javascript

I'm trying to write a Json object (JsonExport) and I'd like to write its content into a text file.
I'm using max4live to export data from Audio DAW to Json in order to export to a server, but after that I would like to see the whole Json Object in a text file:
var txtFile = "test.txt";
var file = new File(txtFile);
var str = JSON.stringify(JsonExport);
file.open("write"); // open file with write access
file.write(str);
file.close();
The compiler runs with no error, but i can not get the text file. I have used as well path to some of my directories and nothing.
Any idea what's happening? Thanks

I know this question already has accepted answer but I think my answer could help someone. So, the problem is to export Json data to a text file. Once you execute the following code, file will be downloaded by the browser.
const filename = 'data.json';
const jsonStr = JSON.stringify(JsonExport);
let element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(jsonStr));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);

If you have access to an already existing file, just link to it. You can specify what the downloaded file name will be like this:
<a href="path/to/file.txt" download="example.json">
Download as JSON
</a>
If needed, you could also write out the dataURI as well
//Get the file contents
var txtFile = "test.txt";
var file = new File(txtFile);
var str = JSON.stringify(JsonExport);
//Save the file contents as a DataURI
var dataUri = 'data:application/json;charset=utf-8,'+ encodeURIComponent(str);
//Write it as the href for the link
var link = document.getElementById('link').href = dataUri;
Then just give the link an ID and a default href
<a href="#" id="link" download="example.json">
Download as JSON
</a>

Finally I got it! It worked by changing few parameters like this:
var txtFile = "/tmp/test.txt";
var file = new File(txtFile,"write");
var str = JSON.stringify(JsonExport);
log("opening file...");
file.open();
log("writing file..");
file.writeline(str);
file.close();
Path to my directories not allowed, so i had to save it on /tmp directory.
Thanks to all!

Related

Angular8 - Downloading Excel .xlsx saves base64 string in file

I've studied all of the SO Similar Questions about this problem, a few were helpful, but did not directly address the saving of an xlsx file to the local Win10 downloads folder.
The xlsx file sits on a CentOS 7 server. If I use Filezilla to copy it to Win10, it's fine.
Looking at the component code below, I am reading the xlsx from the server and getting its base64Str, which matches exactly what I used to store the file. I create a blob fine, but FileSaver, saves the Win10 file with its contents as the base64Str, instead of a an xlsx binary. Can FileSaver save binary content, or only text?
Thanks for helping!
Component Code
//INPUT DATA: docName: test.xlsx; mediaType: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; snippet base64Str: VUVzREJCUU...FBQUFBPQ=
//NOTE: input data is from a CentOS 7 filesystem
const byteStr = atob(base64Str);
const arrayBuffer = new ArrayBuffer(byteStr.length);
const int8Array = new Uint8Array(arrayBuffer);
for (let i = 0; i < byteStr.length; i++) {
int8Array[i] = byteStr.charCodeAt(i);
}
const blob = new Blob([arrayBuffer], { type: mediaType }); //also tried type: 'application/octet-stream'
//alternate technique that produces same corrupted result
//const base64Response = await fetch(`data:` +mediaType +`;base64,${base64Str}`);
//const blob = await base64Response.blob();
fileSaver.saveAs(blob, docName); //saves to Win10 downloads folder
Please try The below code. (Here in this example I have demonstrate the following 1) Input base64 string to a input text area 2) on click of download file link 3) will prompt to download the file into correct xlsx format without corrupted data).
Kindly modify the code as per your need . Example only demonstrate the file download feature.
Point to notice :
var mediaType="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,";
function saveAsXlsxFile(){
var mediaType="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,";
var userInp = document.getElementById('base64input');
// var userInp = "UEsDBBQABgAIAAAAIQBBN4LPbgEAAAQFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAiQwAAHhsL3dvcmtzaGVldHMvc2hlZXQxLnhtbFBLAQItABQABgAIAAAAIQDBFxC+TgcAAMYgAAATAAAAAAAAAAAAAAAAAEoPAAB4bC90aGVtZS90aGVtZTEueG1sUEsBAi0AFAAGAAgAAAAhACBSf139AgAAwgcAAA0AAAAAAAAAAAAAAAAAyRYAAHhsL3N0eWxlcy54bWxQSwECLQAUAAYACAAAACEAw//qhdEAAACPAQAAFAAAAAAAAAAAAAAAAADxGQAAeGwvc2hhcmVkU3RyaW5ncy54bWxQSwECLQAUAAYACAAAACEAO20yS8EAAABCAQAAIwAAAAAAAAAAAAAAAAD0GgAAeGwvd29ya3NoZWV0cy9fcmVscy9zaGVldDEueG1sLnJlbHNQSwECLQAUAAYACAAAACEAo9Y9cDYBAADkAgAAJwAAAAAAAAAAAAAAAAD2GwAAeGwvcHJpbnRlclNldHRpbmdzL3ByaW50ZXJTZXR0aW5nczEuYmluUEsBAi0AFAAGAAgAAAAhAFSTEGpDAQAAawIAABEAAAAAAAAAAAAAAAAAcR0AAGRvY1Byb3BzL2NvcmUueG1sUEsBAi0AFAAGAAgAAAAhAGFJCRCJAQAAEQMAABAAAAAAAAAAAAAAAAAA6x8AAGRvY1Byb3BzL2FwcC54bWxQSwUGAAAAAAwADAAmAwAAqiIAAAAA";
var a = document.createElement('a');
a.href = mediaType+userInp.value;
//a.href = mediaType+userInp;
a.download = 'filename.xlsx';
a.textContent = 'Download file!';
document.body.appendChild(a);
}
<textarea placeholder="paste the base64 data here, exclude readable headers" id='base64input' type="textarea"></textarea>
<br>
<input onclick="saveAsXlsxFile()" type="button" value="update content of link"></button>
HTML code for demo only ( not mandatory for your requirement)
<textarea placeholder="paste the base64 data here, exclude readable headers" id='base64input'></textarea>
<br>
<input onclick="saveAsXlsxFile()" type="button" value="update content of link"></button>
Sample userInp value Try this :
UEsDBBQABgAIAAAAIQBBN4LPbgEAAAQFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAA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AAAAAAAFtDb250ZW50X1R5cGVzXS54bWxQSwECLQAUAAYACAAAACEAtVUwI/QAAABMAgAACwAAAAAAAAAAAAAAAACnAwAAX3JlbHMvLnJlbHNQSwECLQAUAAYACAAAACEARbo8GF0DAABaCAAADwAAAAAAAAAAAAAAAADMBgAAeGwvd29ya2Jvb2sueG1sUEsBAi0AFAAGAAgAAAAhAIE+lJfzAAAAugIAABoAAAAAAAAAAAAAAAAAVgoAAHhsL19yZWxzL3dvcmtib29rLnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhAAdhSeKLAgAARAYAABgAAAAAAAAAAAAAAAAAiQwAAHhsL3dvcmtzaGVldHMvc2hlZXQxLnhtbFBLAQItABQABgAIAAAAIQDBFxC+TgcAAMYgAAATAAAAAAAAAAAAAAAAAEoPAAB4bC90aGVtZS90aGVtZTEueG1sUEsBAi0AFAAGAAgAAAAhACBSf139AgAAwgcAAA0AAAAAAAAAAAAAAAAAyRYAAHhsL3N0eWxlcy54bWxQSwECLQAUAAYACAAAACEAw//qhdEAAACPAQAAFAAAAAAAAAAAAAAAAADxGQAAeGwvc2hhcmVkU3RyaW5ncy54bWxQSwECLQAUAAYACAAAACEAO20yS8EAAABCAQAAIwAAAAAAAAAAAAAAAAD0GgAAeGwvd29ya3NoZWV0cy9fcmVscy9zaGVldDEueG1sLnJlbHNQSwECLQAUAAYACAAAACEAo9Y9cDYBAADkAgAAJwAAAAAAAAAAAAAAAAD2GwAAeGwvcHJpbnRlclNldHRpbmdzL3ByaW50ZXJTZXR0aW5nczEuYmluUEsBAi0AFAAGAAgAAAAhAFSTEGpDAQAAawIAABEAAAAAAAAAAAAAAAAAcR0AAGRvY1Byb3BzL2NvcmUueG1sUEsBAi0AFAAGAAgAAAAhAGFJCRCJAQAAEQMAABAAAAAAAAAAAAAAAAAA6x8AAGRvY1Byb3BzL2FwcC54bWxQSwUGAAAAAAwADAAmAwAAqiIAAAAA
Happy to help further if needed. :)
so I used this. Might also work for anyone trying to convert a static base 64 string to xlxs file. This solutions assumes that you know the file type.
let toConvert = 'UEsDBBQAAAgIABSJA..'//supply your full plain string here
let file = `data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,${toConvert}`;
setTimeout(() => {
fileSaver.saveAs(file, 'fileName');
}, 1300);//timeout is only added to simulate time to load. you can take it out
Regards
Not sure if this works , but try setting the mediaType like below :
const mediaType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';

Writing local files using javascript or other technology

I have seen lots of posting about people wanting to write text files using Javascript. It looks like this used to be possible. I have tried lots and lots of the examples, but can't get any to work short of Downloadify.
I am looking for something that will let me write a text value out to a local file on my own machine. I am running the Javascript locally and not on a web server. I would like this to be written out immediately and not require pressing a Download button like Downloadify.
Are there any options?
you can actually use html5 local storage
localStorage.setItem(KEY, VALUE);
to set the key/value pair(s) and
var result = localStorage.getItem(KEY);
to get the value of the key
The localStorage object stores the data with no expiration date.
I got this to work and write out a file using the following function:
function write_it(win){
var textToWrite = win;
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
var fileNameToSaveAs = "win.txt"
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
downloadLink.click();
}

Unable to export .csv file in IE browser

I'm trying to export my data as CSV file. I wrote below code, that is working fine in Firefox/Chrome but not in IE. I need to make work in IE8/9/10 versions. Thanks in advance.
JS code:
var CSVgen = function (CSV, ReportName) {
//Generate a file name if empty is replace by _.
var fileName = ReportName.replace(/ /g,"_");
//Initialize file format you want csv or xls
var uri = 'data:text/csv;Content-Type:application/octet-stream;Content-Disposition: attachment;charset=utf-8,' + escape(CSV);
//this trick will generate a temp <a /> tag
var link = document.createElement("a");
link.href = uri;
//set the visibility hidden so it will not effect on your web-layout
link.style = "visibility:hidden";
link.download = fileName + ".csv";
//this part will append the anchor tag and remove it after automatic click
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
And i tried below ways also:
var uri = 'data:text/csv;charset=utf-8,' + escape(CSV);
and
var uri = 'Content-Type:application/octet-stream;Content-Disposition:
attachment;' + escape(CSV);
But no luck. I'm getting below error page in IE:
The webpage cannot be displayed
Most likely cause:
•Some content or files on this webpage require a program that you don't have installed.
What you can try:
Search online for a program you can use to view this web content.
Retype the address.
Go back to the previous page.

How do I save a text file using an InDesign script?

I'm extracting some data from an InDesign INDD file using a script. I'd like to save my data in a txt or json file, but my file is not saving successfully.
var data = 'string of data';
var filename = 'CS111.json';
var file = new File(filename);
var path = file.saveDlg(); //returns a valid path, but with spaces as '%20'
file.changePath(path);
var write = file.write(data); //returns false
file.close();
What am I missing here? The file doesn't show up in the chosen folder.
There are at least four steps in saving a file using InDesign Javascript: get a path and filename, create a file object, open the file, write to the file, and close the file.
I find that the write step will sometimes fail if I don't set the encoding.
//Define path and file name
var path = '~/Documents/';
var filename = 'filename.txt';
//Create File object
var file = new File(path + filename);
file.encoding = 'UTF-8';
file.open('w');
file.write('data here');
file.close();
Documentation: File class, .open(), .write()

Generate office open XML excel file from javascript

Is there a way to generate an .xslx file from javascript and allow the user to download it by javascript? This page is geared towards being run offline in html 5 with no internet connectivity.
You could generate a data URI, and let the user save the link. However, IE8 has very limited support for data URIs. There is a 32 KB limit, and it's not allowed to be used with a href.
Also, you still need to find a actual XLSX JS library... But it is possible.
It has been done successfully by Ed Spencer. This project is using an EXT DataGrid as the source of the data, but I'm sure you could adapt it pretty easily.
**Yes You Can do it using javascript**
** call function expexcel('table_id','output_file_name');**
<script>
function expexcel(tableID, filename = ''){
var downloadLink;
var dataType = 'application/vnd.ms-excel';
var tableSelect = document.getElementById(tableID);
var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
// Specify file name
filename = filename?filename+'.xls':'excel_data.xls';
// Create download link element
downloadLink = document.createElement("a");
document.body.appendChild(downloadLink);
if(navigator.msSaveOrOpenBlob){
var blob = new Blob(['\ufeff', tableHTML], {
type: dataType
});
navigator.msSaveOrOpenBlob( blob, filename);
}else{
// Create a link to the file
downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
// Setting the file name
downloadLink.download = filename;
//triggering the function
downloadLink.click();
}
}
</script>
As Javascript has no file I/O, it's not going to be easy for your users to download. However, this kind of work is perfectly suited for a simple PHP script, which could generate your XSLX and save to your server dynamically.
You can generate any Office document with
OpenXML SDK for Javascript
http://openxmlsdkjs.codeplex.com/
As for allowing the user to save a file from JS I recommend FileSaver.js
https://github.com/eligrey/FileSaver.js/

Categories

Resources