Im trying to export the data i have into an excel file without jquery. I've read you can use javascript but most example have jquery. The reason i don't want to use jquery is that the project is build with react.
I already have the data from the database, so i don't need to bring it again.
I want to take that data and make it into an excel file.
little bit of the code below.
<li className='col-md-3 col-height col-middle'>
<span>{fromTime}</span> //contains data
</li>
Some example use table, is it possible to export from
<div>
<li>
<span>
Would appreciate any tips, example or anything
The most common way to export data into excel would be to covert it into a csv (comma seperated values) file which can then be opened in excel.
There are plenty of tutorials on how to do this, there are many different ways with a simple google. In your case doing this in php will likely be best because your getting it from a database.
SheetJS seems perfect for this.
To export your table as an excel file use the code in this link(along with SheetJS)
Just plug in your table element's id into export_table_to_excel
Related
I have a React table like this. Do we have anyway to export this table to CSV file and keep the same structure.
Yes, but how easy it is really depends on how the underlying state is being stored in your app.
The react-csv package allows you to pass it an array of data and add a Download button to your site, but you first need to arrange/collect the data into the right format for it.
One of my requirement is I want to export image and store inside excel using javascript.
I am using export excel using saveAs(blob, filename) and I am able to export javascript data into the excel but I could not able to export image? There is no any server side.
Any body has any idea over this
You can use xlsx library https://www.npmjs.com/package/xlsx
$("[id$=mybutton]").click(function(e) {
window.open('data:application/vnd.ms-excel,' + encodeURIComponent( $('div[id$=image]').html()));
e.preventDefault();
});
Demo https://jsfiddle.net/viethien/dfb3n2x1/11
There is a JS library to create excel. I haven't tried it though. https://github.com/stephenliberty/excel-builder.js However, it should be fairly trivial to loop through your JSON and create a CSV file, which will ultimately open in excel. That might work better depending on your needs.
But to be clear, when you say store an image, do you mean a link to an image, or a base64 text of an image? The latter would be huge and probably break excel in some way.
Other Resources:
https://www.grapecity.com/blogs/how-to-importexport-excel-files-using-javascript-and-spread-sheets
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.
I am working on an angular js where I need to export an array of javascript objects. My code already has the provision to export is as a csv. To export as a csv the way is quite simple. I am building an object where each item is separated by a comma and each row by a new line and then using filewriter to write the file. For excel I came across an option like Alasql. Is there anyway I can do it? Is it possible to format the object in such a way so that we can directly use filewriter to save the object as an excel file?
There are 5 ways to export your data in excel.
read here for more information 5-Ways-to-export
And you can also use datatable plugin.
https://datatables.net/extensions/buttons/examples/initialisation/export.html
I'm in the process of teaching myself Javascript and I'm having a little trouble understanding something.
I'm trying to extract every one of the "Title" and "Instructor" values from this class registration page to make an enhanced scheduling tool for myself. However, in the examples I'm looking at, they all use the "getElementsByClassName(class)" and "getElementsById(id)" to extract specific information from an HTML table. When I look at the page source in chrome, I am not able to find either a unique class name or id to specify in these calls.
Would someone mind pointing me in the right direction? Am I using the page source code correctly or is there a better way of doing things?
EDIT: Here's the html of the page in question
view-source:https://admin.wwu.edu/pls/wwis/wwsktime.ListClass
You can use querySelectorAll to use CSS selectors.
document.querySelectorAll("tr>td:nth-child(3)") and document.querySelectorAll("tr>td:nth-child(8)") will give you all Title and Instructor elements
Here's a jsfiddle of it https://jsfiddle.net/n1fuo87p/
No you're not really doing anything wrong, but unfortunately the creators of the web page haven't made use of classes and ids in a way that will make them useful to you.
I'd recommend creating a Google Sheet to import the table. (See the importHTML function in Google sheets.) Then I'd retrieve the data as JSON and work with it that way. IMO you'll learn more valuable skills working with JSON than you will parsing HTML too. This article will take you through getting JSON out of your Google sheet: http://ctrlq.org/code/20004-google-spreadsheets-json