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.
Related
I am trying to read turn a CSV file, the file is on local, could be same folder with the script file. Since I am writing JSX for photoshop, I couldn't use any other library. And there are a lot of tutorial out there using input element which is not what I need. The path of the file could be hard coded. What I am trying to do is read the CSV, and take out some data. Please advise!
Let me explain it clearly!
I am writing JSX for photoshop script which has no browser element - input tag something like that. And it must be pure Javascript no library such as jQuery. I did a lot of google search what they do is taking the input tag from browser let user select the CSV file, I just want the file path is hard code, it is a fixed path and filename. And I don't see any tutorial for read CSV file and turn into array via vanilla javascript.
You can use the File class. How this works is explained in the ExtendScript toolkit docs which are installed on your computer alongside Creative Cloud. An online version can also be found here. (The scripting guide references this under the File object on page 110, referring to a section about JavaScript on different platforms on page 32, which then refers to the ExtendScript docs.)
Example:
const file = new File("/c/Users/user/Desktop/text.csv");
file.encoding = 'UTF-8';
file.open("r");
const contents = file.read();
file.close();
alert(contents);
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).
I'm using NodeJS to do an app that finds and replaces a text in a pdf. I have found some approaches:
Using some npm package, like pdfReader, that converts pdf to json. So I get the text and replaces it with what I want. The problem it's convert the output back to pdf.
The possible solution for the first item it's to convert the PDF to HTML, edit the HTML and convert it back to pdf. But most of the tutorials using NodeJS it's about convert HTML to PDF, not PDF to HTML.
Any solutions for this problem?
Update
I ended up using PDFKit to create the pdf files that i need. In my case, this solution don't to cover all the possibles. But if you have to find a word and replace it in an unpredictable pdf file, maybe this problem has no solution in nodeJS. The PDFKit lib has an open issue for this feature.
Look at this approach how to export json data to pdf file with specify format with Nodejs?. Basically uses your idea. Convert PDF to JSON and then render the JSON in html, then convert the HTML to pdf.
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
so I have an IQY file (Internet Query file), it's found locally on my computer. This file when opened in excel will show me a table of a SharePoint list. I would like to use JavaScript, in IE browser (I can use ActiveXObject if needed) to search the resulted table for a value.
I already know how to search in excel, So that's not the problem. How can I turn this IQY file into an temp excel sheet with JavaScript? If it's not possible, is there a way to read from the table using the IQY file without using excel?
I hope my question is understandable.
Thank you.
So I've found a way to overcome this problem. In the file data there's an href, that when opened by a browser will display the data in excel format. So I've used this data to get the information I needed.