FlexGridXlsxConverter Class

File
wijmo.grid.xlsx.js
Module
wijmo.grid.xlsx

This class provides static load and save methods for loading and saving FlexGrid controls from and to Excel xlsx files.

The example below shows how you can use the FlexGridXlsxConverter to export the content of a FlexGrid control to XLSX:

{@sample Grid/ImportExportPrint/Excel/Async/purejs Example}

Methods

Methods

Static cancelAsync

cancelAsync(done?: ()): void

Cancels the task started by the saveAsync method.

Parameters
Returns
void

Static load

load(grid: FlexGrid, workbook: Workbook, options?: IFlexGridXlsxOptions): void

Loads a Workbook instance or a Blob object containing xlsx file content to the FlexGrid instance. This method works with JSZip 2.5.

For example:

// This sample opens an xlsx file chosen through Open File
// dialog and fills FlexGrid with the content of the first

// sheet.
 

// HTML
<input type="file" 
    id="importFile" 
    accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" 
/>
<div id="flexHost"></>
 

// JavaScript
var flexGrid = new wijmo.grid.FlexGrid("#flexHost"),
    importFile = document.getElementById('importFile');
 
importFile.addEventListener('change', function () {
    loadWorkbook();
});
 
function loadWorkbook() {
    var reader,
        file = importFile.files[0];
    if (file) {
        reader = new FileReader();
        reader.onload = function (e) {
            wijmo.grid.xlsx.FlexGridXlsxConverter.load(flexGrid, reader.result,
                { includeColumnHeaders: true });
        };
        reader.readAsArrayBuffer(file);
    }
}
Parameters
Returns
void

Static loadAsync

loadAsync(grid: FlexGrid, workbook: string | ArrayBuffer | Blob | wijmo.xlsx.Workbook, options?: IFlexGridXlsxOptions, onLoaded?: Workbook), onError?: (reason?: any)): void

Asynchronously loads a Workbook or a Blob representing an xlsx file into a FlexGrid.

This method requires JSZip 3.0.

Parameters
Returns
void

Static save

save(grid: FlexGrid, options?: IFlexGridXlsxOptions, fileName?: string): Workbook

Save the FlexGrid instance to the Workbook instance. This method works with JSZip 2.5.

For example:

// This sample exports FlexGrid content to an xlsx file.
// click.
 

// HTML
<button 
    onclick="saveXlsx('FlexGrid.xlsx')">
    Save
</button>
 

// JavaScript
function saveXlsx(fileName) {

    // Save the flexGrid to xlsx file.
    wijmo.grid.xlsx.FlexGridXlsxConverter.save(flexGrid,
            { includeColumnHeaders: true }, fileName);
}
Parameters
Returns
Workbook

Static saveAsync

saveAsync(grid: FlexGrid, options?: IFlexGridXlsxOptions, fileName?: string, onSaved?: (base64: string, workbook?: Workbook), onError?: (reason?: any), onProgress?: (value: number), asyncWorkbook?: boolean): Workbook

Asynchronously saves the content of a FlexGrid to a file.

This method requires JSZip 3.0.

The return value depends on the asyncWorkbook parameter. If it is false (default) then the method returns the Workbook instance. If it is true then the method returns a null value and the Workbook instance should be obtained in the onSaved callback.

If asyncWorkbook parameter is true then, once started, the task will be automatically restarted when changes in the grid are detected.

Parameters
Returns
Workbook