Exporting Data in Excel, Javascript table - javascript

I am using angularjs and exporting data in excel from the table that has been uploaded.
I am using the following code:
function (e)
{
window.open('data:application/vnd.ms-excel,' + encodeURIComponent($('div[id$=exportable]').html()));
e.preventDefault();
It is allowing me to download the file but extension is missing. Can you pls guide me how to change file name and extension both for the same?
Thanks

Excel to JSON
This is basically what you are looking for, some way to turn excel to JSON data with JavaScript. Here is a link to an article about how it can be done using XLSXReader in a web app along with AngularJS.
Sample Code
$(function() {
$("#xlsxFile").change(function(event) {
var file = this.files[0],
sheets;
XLSXReader(file, true, function(xlsxData) {
sheets = xlsxData.sheets;
// Do somehting with sheets. It's a
// Javascript object with sheet names
// as keys and data as value in form of 2D array
});
});
});
Working Example
Here is a working example of the code. You can upload a csv file and have it turned into JSON.
I hope this helps.

Related

convert document file into JSON

I am working on a ReactJS project and in that, I have to fetch (by JS fetch API) a document (.docx/.doc) file from the server and convert it into JSON. After some research, I got to know that document files are unstructured that's why we can't convert them into JSON. So my question is.
-Is it true that document files could not be converted into JSON by JS?
I used the below code but it's not working. The same code is working with excel files.
fetch("url/container/file.docx").then(res => {
return res.arrayBuffer()
}).then(result => {
const _Uint8Array = new Uint8Array(result);
//for xlsx here i am using xlsx.utils.sheet_to_json
console.log(_Uint8Array);
})
I found the same questions on the internet but I didn't get any proper solution to my issue.

Export all data to excel including data from pagination

I'm working on a table that can export data to excel using js excel generator. It work somehow, my problem is I cant display all the data, it only display the current data shown.
hope you help me.
thanks.
$("#toExcel").click(function () {
var filename = $('title').text();
excel = new ExcelGen({
"src_id": "excelGen_table",
"show_header": true
});
excel.generate();
});

Upload csv file using javascript and d3

I am new to JavaScript and D3 and cannot figure out how to allow users to upload a csv file and displaying a scatterplot using d3. I am using the tag to allow user to select file. But I am not sure on what the next step should be. Is there a way to read the csv file and store it's contents in a d3 array and then displaying a graph using that array ??
Thanks in advance
Look into the d3.csv function (https://github.com/mbostock/d3/wiki/CSV). Here is a simple example
//load up the example.csv file
d3.csv('example.csv',
function(data){
//this is an object, the contents of which should
//match your example.csv input file.
console.log(data);
// do more stuff with 'data' related to
// drawing the scatterplots.
//
//-----------------------
},
function(error, rows) {
console.log(rows);
};
);
There are a number of examples online showing you how to go from a data array to a scatterplot...it's a matter of modifying those examples to fit your specific data format.

Extracting data from excel sheet into csv (or) Json using Javascript

I need to extract the data from an excel sheet into csv or json format and then display the content in the form of charts(bar, pie and line) using javascript. I have been working on it since 2 days and not able to find any good source. Any help regarding this would be appreciated. Thank you.
You can also pull data from a google spreadsheet as CSV data like this:
var spreadsheet = "https://docs.google.com/spreadsheet/pub?key=youruniquekeyhere&single=true&gid=2&output=csv"
d3.csv(spreadsheet, function (error, data) {
// use your data here
});
Notice the output=csv at the end of that URL.
gid=0 is worksheet 1, gid=1 is worksheet 2 and so on. You must publish your worksheet to the web first to make it available.
In addition to Christophe Viau's tutorials, here are more resources:
https://github.com/mbostock/d3/wiki/Gallery#basic-charts
http://www.d3noob.org

reading data from external file

I am new to both three.js and javascript so this might be a very noob question.
I have a list of json objects in a file which contains data as following:
[
{ "x":x,"y":y,"z":z ,"r":r},
{ "x":x2,"y":y2,"z":z2 ,"r":r2},
{ "x":x3,"y":y3,"z":z 3,"r":r3}
]
And render it on screen.
Its exactly an example here: http://mrdoob.github.com/three.js/examples/webgl_materials2.html
except that sphere values I am reading from a file?
How do i tweak the example above that i read the values from this file instead of directly hardcoding these values in js?
Please help
THanks
If all you want to do is separate the data from your application logic, then you don't need to create a JSON file and load it via Ajax, you can just create another JavaScript file and put the data in there.
For example:
// myData.js
var myData = [
{ "x":x,"y":y,"z":z ,"r":r},
{ "x":x2,"y":y2,"z":z2 ,"r":r2},
// ...
];
// --------------
// myApplication.js
// Here goes the three.js code and you can access the data here, for example
alert(myData[0].x);
In your HTML file, you have to include the data file first, so that all following scripts have access to the myData variabe:
<script src="myData.js"></script>
<script src="myApplication.js"></script>
<!-- this works to: -->
<script>
alert(myData.length);
</script>
If you want to or have to load the file via Ajax, have a look at this question: How do I load a JSON object from a file with ajax?.

Categories