Import Excel file in JavaScript - javascript

I have a plunker attached herewith.
http://plnkr.co/edit/RkUCchxd6UghOTclMDFj?p=preview
I am able to import a text file properly without any errors. However, when I try to import an Excel file, it imports random alphanumeric values and unrelated data.
Can you please let me know if there is an easy way out there to import and Excel file (csv and xlsx file )?
I read online and found this document but I am not sure how it is used in JavaScript and HTML. Can anyone help?
http://psjinx.com/programming/2014/01/04/parsing-excel-workbooks-using-javascript/
<html>

You may use js-xlsx library to parse excel file to json using javascript
js-xlsx
the readme file explain how to use the library, or you may refer to the following article which talks about the library usage
Parse and Read Excel Files (xls/xlsx) With JavaScript

Related

Npm FileSaver CSV file encoding for Excel

I'm using FileSaver library on my React application to export data to CSV, the data have characters with accent and when i open it with Excel it doesn't show properly (like this: é) however it shows properly when i open it with another text editor like VS Code
Here's the code i use :
FileSaver.saveAs(new Blob([csv], {type: "text/plain;charset=utf-8"}),"id_physique_"+ this.props.secuFoncierExportName+".csv");
FileSaver.saveAs(new Blob([csv_legal], {type: "text/plain;charset=utf-8"}),"id_morale_"+ this.props.secuFoncierExportName+".csv");
Does anyone have a solution for this issue ?
Thanks in advance
I had a similar problem with this library trying to export CSV files which afterwards are imported to Microsoft Excel.
file-saver exports the data in UTF-8 encoding. It seems like Microsoft Excel doesn't use the correct encoding while reading the file via File -> Open.
If you import the file in Microsoft Excel via the provided import functionality, you can specify the encoding. You can find the functionality via the menu (Data -> From Text/CSV).

Tabulator: Download Error - No such download type found

Would like to ask for some help I am currently using Tabulator (4.9) along with Vue. I am having trouble downloading/exporting my data to Excel. I have already included SheetJS on my project as stated from Tabulator's page.
The following gives me an error that the XLSX is not defined:
import 'xlsx/dist/xlsx.full.min.js'
this.tabulator.download('xlsx', 'data.xlsx')
But once I include the XLSX, then it tells me "Download Error - No such download type found":
import XLSX from 'xlsx/dist/xlsx.full.min.js'
this.tabulator.download(XLSX, 'data.xlsx')
Would really like to know if I am missing something.
Thanks.
Your first approach is correct, you should be calling the download function and passing in the xlsx string
this.tabulator.download('xlsx', 'data.xlsx');
The issue is that Tabulator is expecting to find the XLSX object on the window object (or global object if this is a node project) as that is where the library is put when pulled in from the CDN.
So in you case your import should be:
import XLSX from 'xlsx/dist/xlsx.full.min.js';
window.XLSX = XLSX;
I haven't tried using tabulator. You could look over its documentation again to see if you are missing something. Otherwise, I have used vue-json-csv. You can import it globally and call it anywhere you want to in your templates.
<DownloadCsv :data="exportData" name="export.csv">
<button class="mr-2">Export to csv</button>
</DownloadCsv>
It takes a data prop, which would be the json data set you wish to export to excel. And the name prop, this is going to be the name of the export file when it is generated.

How to generate Excel xlsx files from JavaScript

We are currently Exporting to Excel from ui-grid custom menus. The xls Excel file is generated from JavaScript (in the UI); however, we need to support the xlsx format. Problem is when we change the extension to xlsx, opening the file in Excel 2013is generates an error.
Here's a JavaScript code snippet show how we save the xls file:
var blob = new Blob([html], { type: 'data:application/vnd.ms-excel;base64,' });
saveAs(blob, "exported.xls");
Can we accomplish export to xlsx from JavaScript, without relying on some third party package?
I'm looking into Open XML file formats on msdn but it appears to be server-side oriented; that is, generating xlsx files from c#.
Here's an example generating from c# - https://msdn.microsoft.com/en-us/library/office/gg278309.aspx
I apologize if the question is too generic, as I'm struggling to find a proper solution.
regards
Javascript running where? If you mean in your browser then the short answer is no - the security model does not allow Javascript to create files.
But presumably the data is getting onto your page where javascript can read it from somewhere - so just generate the file there.

Export array to excel xlsx in javascript

There is one requirement in javascript to export the data (array or array of objects) to excel xlsx. I already exported the data to csv but unable to do same for xlsx. I tried many api from github so that I can used the libraries and export it to xslx but there are little help for it. I tried using stephen-hardy/xlsx.js, SheetJS/js-xlsx etc.
For exporting to csv I used this Click here! but the same cant be done for xlsx.
I tried xlsxwriter also to convert and write javascript array or array of object to xlsx but no result.
Now I m badly stuck because of the requirement. I also found out the similar post as of mine requirement Click here!
Please guys give me solution if any
A while ago, I wrote the following article, which described how to export data from a jqGrid to a "real" .xlsx file:
Export jqGrid to Excel
This basically cached the jqGrid's data into a JavaScript variable, posted it back to a server, to save into Excel. The Excel file is created using the OpenXML libraries.
This should point you in the right direction.
Alternatively, you might like to try this library:
AlaSQL
(I haven't tried this though.)
Try excelbuilderjs, I have done the same of downloading a Json Object with array of items into an excel sheet using this library.If you can please share the code on Jsfiddle, i can take a look at it and help you out
http://excelbuilderjs.com/

Looking for suggestions. Javascript object data to xls

I´ve a Javascript object with all the data that I need to store on xls file. What could be the better way? Apache POI? Jasper-Reports? I´m not sure about the correct choice.
Thanks!
If you just need to import it with Excel I would suggest creating an CSV file out of the data instead.
This can easily be done with JavaScript and Excel can import that format.

Categories