[]
        
(Showing Draft Content)

FlexGridXlsxConverter Class

FlexGridXlsxConverter Class

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:

Example

Heirarchy

  • FlexGridXlsxConverter

Methods

Static cancelAsync

  • cancelAsync(done?: Object): void
  • Cancels the task started by the FlexGridXlsxConverter.saveAsync method.

    Parameters

    • Optional done: Object

      Callback invoked when the method finishes executing.

    Returns void

Static load

  • 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 | mXlsx.Workbook, options?: IFlexGridXlsxOptions, onLoaded?: Object, onError?: Object): void
  • Asynchronously loads a Workbook or a Blob representing an xlsx file into a FlexGrid.

    This method requires JSZip 3.0.

    Parameters

    • grid: FlexGrid

      FlexGrid that loads the Workbook object.

    • workbook: string | ArrayBuffer | Blob | mXlsx.Workbook

      Workbook, Blob, base-64 string, or ArrayBuffer representing the xlsx file content.

    • Optional options: IFlexGridXlsxOptions

      IFlexGridXlsxOptions object specifying the load options.

    • Optional onLoaded: Object

      Callback invoked when the method finishes executing. The callback provides access to the workbook that was loaded (passed as a parameter to the callback).

    • Optional onError: Object

      Callback invoked when there are errors saving the file. The error is passed as a parameter to the callback.

      For example:

      wijmo.grid.xlsx.FlexGridXlsxConverter.loadAsync(grid, blob, null, function (workbook) {
           // user can access the loaded workbook instance in this callback.
           var app = worksheet.application ;
           ...
      }, function (reason) {
           // User can catch the failure reason in this callback.
           console.log('The reason of save failure is ' + reason);
      });
      

    Returns void

Static save

  • 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 mXlsx.Workbook

    A Workbook object that can be used to customize the workbook before saving it (with the Workbook.save method).

Static saveAsync

  • saveAsync(grid: FlexGrid, options?: IFlexGridXlsxOptions, fileName?: string, onSaved?: Object, onError?: Object, onProgress?: Object, asyncWorkbook?: boolean, batchSize?: number): mXlsx.Workbook
  • Asynchronously saves the content of a FlexGrid to a file.

    This method requires JSZip 3.0.

    The return value depends on the {@link 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 {@link onSaved} callback.

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

    Parameters

    • grid: FlexGrid

      FlexGrid that will be saved.

    • Optional options: IFlexGridXlsxOptions

      IFlexGridXlsxOptions object specifying the save options.

    • Optional fileName: string

      Name of the file that will be generated.

    • Optional onSaved: Object

      Callback invoked when the method finishes executing. The callback provides access to the content of the saved workbook (encoded as a base-64 string and passed as a parameter to the callback).

    • Optional onError: Object

      Callback invoked when there are errors saving the file. The error is passed as a parameter to the callback.

    • Optional onProgress: Object

      Callback function that gives feedback about the progress of a task. The function accepts a single argument, the current progress as a number between 0 and 100. Can be used only if the {@link asyncWorkbook} parameter is set to true.

    • Optional asyncWorkbook: boolean

      Indicates whether Workbook genaration should be performed asynchronously or not. The default value is false.

      For example:

      wijmo.grid.xlsx.FlexGridXlsxConverter.saveAsync(flexGrid,
          { includeColumnHeaders: true }, // options
          'FlexGrid.xlsx', // filename
          function (base64) { // onSaved
              // User can access the base64 string in this callback.
              document.getElementByID('export').href = 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;' + 'base64,' + base64;
          },
          function (reason) { // onError
              // User can catch the failure reason in this callback.
              console.log('The reason of save failure is ' + reason);
          }
       );
    • Optional batchSize: number

    Returns mXlsx.Workbook