xml alternative for javascript app used on IE? - javascript

What would be the best alternative to xml for a javascript app. The app parse the data then uses Highcharts framework to show some charts.
I can't use xml because it has problems running locally on Internet Explorer (access denied error and other problems ....see my other question here).
Also this new thing that should replace xml in this situation should be exported from excel.
I was thinking about csv... but csv can be a little bit messy an not as easy to use as xml.
Thanks!

The best data format that you can use with JavaScript is JSON (JavaScript Object Notation) - it was designed for it.

Related

Java object to javascript

I have a core java project, in which I have to create a data visualization in form of a graph.
This data visualization (a graph) is dumped in HTML file(in Plantuml format), which renders the graph in visual graph.
Now I am looking for a way where I can dump this graph data structure as well(which is actually interlinked java objects) in some format, such that I can read it in java script/jquery thereby reconstructing the whole graph, along with loading the HTML file and update the graph in HTML dynamically, using the graph data structure based on some input from user.
Since plantuml doesn't support dynamic events.
And since the HTML file generated dynamically, so creating JSP and dynamically loading it on server is not feasible.
I have seen some answers suggesting use of JAXB, JSON, but the question wasn't exactly as I needed.
I am thinking to dump it in xml and then read that xml in java script.But not sure how good this idea is.
Is there a better way?
JavaScript is not good at reading XML. The ECMA-357 standard was designed for this, but is all but forgotten. You can still find it in Rhino, but that doesn't suit your purposes.
JSON is really the language to use these days.
GSON or Jackson are common libraries for turning Java objects into JSON.
ECMA-357 - E4X
GSON
Jackson

Exporting data to excel using javascript under following constraint

I have a project on exporting data to excel using JavaScript. But the constraints are : It should work for all browsers unlike ActiveXObject(that works only for Internet Explorer), window.open(that doesn't works for internet explorer).
It should not depend on other applications like Flash (I have seen a code using jQuery and Flash, but I can't use that in my project) e.t.c.
Please tell me whether it is possible and if it is, then suggest me a method to do this...
And one more thing, Manual work shouldn't be there or if it is, then it should be very less. In other words, it should be completely automated.
Suggestions:
use CSV file format and write a CSV writer in JavaScript yourself
use Microsoft's Office Open XML file format (xlsx) and write JavaScript code that generates such a file (should not be too difficult as it is XML based and there should be a lot of code around generating XML in JavaScript)

In-browser conversion of MS Word document to PDF

I would like to implement an in-browser Microsoft Word document merge feature that will convert the merged document into PDF and offer it to the user for download. I would like to this process to be supported in Google Chrome and Firefox. Here is how I would like it to work:
Client-side JavaScript obtains the Word template document in docx format, either from a server, or by asking the user for a file upload (which it can then read using the FileReader API)
The JavaScript uses its local data structures (e.g., data lists it has obtained via Ajax) to expand the template into a document. It can do this either directly, by unzipping the docx file and processing its contents, or using DOCx.js. The template expansion is just a matter of substituting template variables with values obtained from the local data structures.
The JavaScript then converts the expanded template into PDF.
The JavaScript offers the PDF file to the user for download, e.g., using Downloadify.
The difficulty I am having is in step 3. My understanding (based on all the Googling I have done so far) is that I have the following options:
Require that the local machine is a Windows machine, and invoke Word on it, to convert to PDF. This can be done using a little bit of scripting using WScript.shell, and it looks doable with Internet Explorer. But based on what I have read, it doesn't look like I can call WScript.shell from within either Chrome or Firefox, because of their security constraints.
I am open to trying Silverlight to do the conversion, but I have not found enough documentation on how to do this. Ideally, if I used Silverlight, I would like to write the Silverlight code in JavaScript, because (a) I don't know much CSharp, and (b) I think it would be much easier in JavaScript.
Create a web service that will convert a given docx file to a pdf file, and invoke that service via Ajax. I would rather not do this, if possible, for a few reasons: (a) I tried using docx4java (I am a reasonably skilled Java programmer) but the conversion process is far too slow, and it does not preserve document content very well; and (b) I would like to avoid a call out to the network, to avoid security issues. It does seem possible to write a little service on a Windows server for doing the conversion, and if there is no other good option, I might go that route.
If I have been unclear about anything, please let me know. I would appreciate your ideas and feedback.
I love command line tools.
Load the doc to your server and use LibreOffice to convert it to PDF via the command line
soffice.exe --headless --convert-to pdf --outdir E:\Docs\Out E:\Docs\In\a.doc
You can display a progress bar to the user and when complete give them the option to download the doc.
More info on LibreOffice's command line parameters go here
Done.
Old old question now, but for anyone who stumbles across this, web assembly (wasm) now makes this sort of approach possible.
We've just released https://www.npmjs.com/package/#nativedocuments/docx-wasm which can perform the conversion locally.

Excel Module For NodeJS

I want to create .xls .xlsx file from NodeJS but i can't find any stable module for do that.
Is there any stable nodejs module for generating simple excel pages ?
The Excel format is published by Microsoft as an open specification. You can get the spec here in a nicely formatted, intimidating 1200 page PDF.
I've used Microsoft spec documents before to figure out how to implement partial (incomplete) systems that just serve my specific use cases. In other words, if you can figure out the exact bits you need (i.e. just convert a 2d array into some excel rows), then you can often ignore rest of the spec as it doesn't apply to you.
I've also found that looking at solutions written in other languages has helped me - for example, here's a project that uses c#.
Depending on whats available on your backend system, you could spawn a child process that handles the conversion.
Or, you could offload the whole thing to a web service. Google Documents List API allows you to store and manipulate files Google Docs, and then with Google Spreadsheets API you can read and modify the data in Google Spreadsheets.
I realize none of this really addresses your question of the availability of a library, but might give you a new way of solving the problem.
Did you tried the sheetjs? It is the best lib ever!
I also wrote a simple formula parser if you need to evaluate some formula on nodejs server side.
OpenXML SDK for javascript
Use this.

How to parse an excel file in JavaScript?

I am trying to write a small web tool which takes an Excel file, parses the contents and then compares the data with another dataset. Can this be easily done in JavaScript? Is there a JavaScript library which does this?
How would you load a file into JavaScript in the first place?
In addition, Excel is a proprietary format and complex enough that server side libraries with years in development (such as Apache POI) haven't yet managed to correctly 100% reverse engineer these Microsoft formats.
So I think that the answer is that you can't.
Update: That is in pure JavaScript.
Update 2: It is now possible to load files in JavaScript: https://developer.mozilla.org/en-US/docs/DOM/FileReader
In the past four years, there have been many advancements. HTML5 File API has been embraced by the major browser vendors and performance enhancements actually make it somewhat possible to parse excel files (both xls and xlsx) in the browser.
My entries in this space:
http://oss.sheetjs.com/js-xls/ (xls)
http://oss.sheetjs.com/js-xlsx/ (xlsx)
Both are pure-JS parsers
To do everything in js, you'll have to use ActiveX and probably the office web components as well. Just a suggestion, but you probably don't want to go this route; it'll be inefficient and IE/Win only. You'll be better off with a server based solution.
You will need to use ActiveX (see W3C Schools on the use of AJAX) and register the file in the hosting computers Dataconnectors (only the computer hosting the file). Unlike mentioned before, this method is not Microsoft platform dependant (for the client anyways) and you do not need to have Office components installed.
This can be done for most datafiles registered in Windows, including MDB's, and allows you as much control as you want, as you can assign different Windows Accounts for different purposes.
Like I said before, this all is serverside and has no impact on the client, apart from maybe retrieving credentials, actions and all that.
This method uses JavaScript, SQL (no, not even MSSQL, just SQL standard) and requires only that the hosting computer is running ANY Microsoft NT platform.
What Windows dataconnectors do is provide a generalised interface for various data components much like DirectX does for videocards and other peripherals. You can also use it to link an MDB (Microsoft Access) to a MySQL server and feed data live that way, which I believe is even simpler than using XLS spreadsheets...especially since you can import XLS into MDB.
Do you really need an Excel file? Why not use Excel to export the data in CSV or XML and load that?
The Excel file format is very specific to Excel's implementation. If you just need the data, use a file format that just contains the data.

Categories