How to write excel file with chart using js-xlsx - javascript

Using SheetJS js-xlsx "xlsx": "0.15.1" js is there a way to write excel file with chart.
Basically I want to export html page that contains chart into an excel file.
HTML page is getting exported successfully but the chart in the page is not getting displayed.
Here is the code I have used
let wb =XLSX.utils.book_new();
let element: any = document.getElementById('page1');
let ws = XLSX.utils.table_to_sheet(element);
XLSX.utils.book_append_sheet(wb,ws,'page1');

Are you using the Community build or the Pro?
As stated here, The Community build reflects the data cached in charts as worksheets. Other chart-related features, including writing and reading metadata, are included in the Pro compendium.
Remember to include your work as Chartsheet, just in case. It will continue to render it as a Worksheet if you are using the community version, but it will help us to understand the desired behavior that you are seeking.
If you provide more reference for the code, maybe we can show you some shortcuts to make it work.

Related

Why does my D3 code break when I set the script type to module?

I am working on a project built with Javascrpt, jQuery, and Vite.js. My colleague built a data visualization using D3 - a US states map - that I need to implement in the project on a specific page. They built the component using test data, my job is basically to load the component onto a page passing it actual returned data from an API call.
Everything in the test project works perfectly, but when I tried to implement this code into a script file in the project - literally copying and pasting from the working version - I got an error saying certain properties could not be read. After failing to debug for sometime, I randomly tried removing type="module" from the script tag link in HTML, and boom, everything worked. Does anyone have an idea of why this would be? I cannot get this code to run when the script type is set to module, except I need the script type to be set to module since I'm importing lots of components for other aspects of the page.
With the way the CodePen is set up, I couldn't replicate the issue since the HTML and JS files are automatically linked. But if you copy this code into your editor, and then in the html, set the the JS file to a module ` You'll see the issue.
Thanks. I'm at a total loss for what to do here. I could put all the D3 code in it's own script file, but then I have no way pass it variables from other files if it's not a module.
Per the comments, the following lines in my original code were not working in strict mode:
this.uStates = uStates;
this.uStatePaths = uStatePaths;
The fix was simple, I just needed to write the following instead:
window.uStates = uStates;
window.uStatePaths = uStatePaths;

unable to download XLSX.Full.Min.JS

I am using below referenced code for Export to Excel:
How to export HTML tables to a single excel workbook with different sheets?
To execute this code we need the JS "xlsx.full.min" as mentioned below
<script>
src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.10.3/xlsx.full.min.js">
</script>
But I am getting a corrupt version of the js from given path and unable to find the correct format or correct version.
Please suggest the correct path where I can get the js in a right format.
Here is the Image of xlsx.full.min.js....

How to upload and convert XLSX file to JSON using ember.js

I am trying to allow the user to upload an XLSX file to be converted to a JSON or CSV file to be parsed through on the back-end. I am using node.js, and tried several packages including the read-excel-file
(https://github.com/catamphetamine/read-excel-file/blob/master/README.md)
readXlsxFile(file).then(function(data) {
let jsondata = JSON.parse(data);
-do something with jsondata-
});
The usual place to look for add-ons would be Ember Observer but the options available seem have a status of Work In Progress - they might be a useful place to look though to get some inspiration for how to proceed.
There are plenty of options on npm. You can import one of those into your project using the new add-on ember-auto-import or, if you'd rather do the hard work yourself, the Ember guides provide some guidance on manually importing.
You can use js-xlsx. Add it as bower dependecy and add its imports to your ember-cli-build file as:
app.import('bower_components/js-xlsx/dist/jszip.js');
app.import('bower_components/js-xlsx/dist/xlsx.min.js');
Handle it as the documentation's parsing-workbooks section shows. (handleFile function is explaining it well.)

Save a pivottablejs figure to file

I have started using the package pivottablejs to manipulate and visualize pivot tables in python.
from pivottablejs import pivot_ui
pivot_ui(df) # where df is a pandas dataframe
will produce an interactive pivot table/plot in a jupyter notebook.
Is there any pythonic way to save the figures produced by this package to (say) png from within the jupyter notebook? I am looking for something similar to the classic plt.savefig('file.png'). The front-end is essentially javascript, and I do not know how (or if it is possible) to access a javascript figure through python.
This is too long for a comment, so I'm adding it as an answer. pivottablejs creates images as svgs and they do not provide any download/export mechanism for the images. But what you can do is inject js into the cell and download the svg using that.
One simple way of doing this is using svg-crowbar.js. After you generate the chart using pivot_ui and the output is displayed on the screen, run the following in the next cell to download the svg.
In [10]: %%javascript
var e = document.createElement('script'); e.setAttribute('src', 'https://nytimes.github.io/svg-crowbar/svg-crowbar.js'); e.setAttribute('class', 'svg-crowbar'); document.body.appendChild(e);
Note: This only works on chrome.
you can save it as html by specifying outfile_path
pivot_ui(df, outfile_path="yourpathname.html")

Learning Leaflet. Noticed examples add a var name to the GeoJson file. Necessary?

I'm learning Leaflet, JS, etc. Am testing using code examples from the Leaflet site, modified for my use. In all the example I've looked at, the JSON file has a var added in front of the initial bracket ([). Is this necessary to work with a JSON file? It sure would be nice to have the JSON files work as they are generated. ArcMap Desktop, for example, has a tool called Feature-to-JSON and the output does not have a "var = name" as the first data. Can I avoid the step of adding the var? If so, I'd appreciate code examples.
You definitely don't have to save your JSON files as JavaScript files. It is used in the examples just for simplicity. Normally, you have your JSON file on your server or accessible with some REST API. This file can be asynchronously downloaded and used in your map like this:
myHttpService.get(myFileUrl).then(function(jsonData) {
L.geoJson(jsonData).addTo(map);
});

Categories

Resources