//Controls Declaration
var gFlexGrid = null,
    IncludeHeaderExport = null,
    IncludeHeaderImport = null;

//Controls Initialization
function InitialControls() {
    gFlexGrid = wijmo.Control.getControl("#gFlexGrid");
    IncludeHeaderImport = document.getElementById('IncludeHeaderImport');
    IncludeHeaderExport = document.getElementById('IncludeHeaderExport');
}

// export 
function exportExcel() {
    var result = wijmo.grid.xlsx.FlexGridXlsxConverter.export(gFlexGrid, { includeColumnHeader: IncludeHeaderExport.checked });

    if (navigator.msSaveBlob) {
        // Saving the xlsx file using Blob and msSaveBlob in IE.
        var blob = new Blob([result.base64Array]);

        navigator.msSaveBlob(blob, $('#export').attr("download"));
    } else {
        $('#export')[0].href = result.href();
    }
};

// import
function importExcel() {
    if (gFlexGrid) {
        var reader = new FileReader(),
            fileData;

        reader.onload = function (e) {
            wijmo.grid.xlsx.FlexGridXlsxConverter.import(reader.result, gFlexGrid, { includeColumnHeader: IncludeHeaderImport.checked });
        };
        if ($('#importFile')[0].files[0]) {
            reader.readAsArrayBuffer($('#importFile')[0].files[0]);
        }
        else
            alert('Select an Excel file to Import.');
    }
};
