jQuery Grid: Data Import from Excel

Import from Excel with jqxGrid.

A live JavaScript/jQuery example of jqxGrid, the jQWidgets Grid component, with its complete source code below. It is one of 139 jqxGrid demos for jQuery.

jqxGrid API used in this demo

Source code

To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxGrid shows the setup step by step.

The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxbuttons.js, jqxscrollbar.js, jqxmenu.js, jqxcheckbox.js, jqxgrid.js, jqxgrid.selection.js, jqxgrid.columnsresize.js, jqxdata.js, jqxdata.export.js, jqxgrid.export.js, jqxgrid.sort.js, jqxexport.js, jqximport.js.

It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers), jszip.min.js, pdfmake.min.js, vfs_fonts.js, generatedata.js (generatedata(), random sample rows).

script.js

window.onload = function() {
      // prepare the data
    
var source = new jqx.dataAdapter({
datatype: 'xlsx',
url: '../../scripts/data.xlsx',
datafields: [
              { name: 'id', type: 'number' },
              { name: 'firstName', type: 'string' },
              { name: 'lastName', type: 'string' },
              { name: 'productName', type: 'string' },
              { name: 'quantity', type: 'number' },
              { name: 'price', type: 'number' },
{ name: 'total', type: 'string' }
          ]
});

var grid = new jqxGrid("#grid", {
source: source,
autoheight:true,
width: '100%',
columns: [
{ text: 'id', dataField: 'id'},
{ text: 'First Name', dataField: 'firstName'},
{ text: 'Last Name', dataField: 'lastName' },
{ text: 'Product', dataField: 'productName' },
{ text: 'Quantity', dataField: 'quantity', align: 'right', cellsAlign: 'right', },
{ text: 'Unit Price', dataField: 'price', align: 'right', cellsAlign: 'right', cellsFormat: 'c2' },
{ text: 'Total', dataField: 'total', align: 'right', cellsAlign: 'right', cellsFormat: 'c2' }
]
});			
  }

body.html

<div id="grid"></div>

Learn more

More jQuery Grid demos