[]
        
(Showing Draft Content)

Wijmo_Xlsx.Workbook

Workbook Class

Represents an Excel workbook.

Heirarchy

  • Workbook

Constructors

constructor

Properties

activeWorksheet

activeWorksheet: number

Gets or sets the index of the active sheet in the xlsx file.

application

application: string

Gets or sets the name of application that generated the file that appears in the file properties.

colorThemes

colorThemes: string[]

Gets the color of the workbook themes.

company

company: string

Gets or sets the name of company that generated the file that appears in the file properties.

created

created: Date

Gets or sets the creation time of the xlsx file.

creator

creator: string

Gets or sets the creator of the xlsx file.

definedNames

definedNames: DefinedName[]

Gets the defined name items of the workbook.

lastModifiedBy

lastModifiedBy: string

Gets or sets the last modifier of the xlsx file.

modified

modified: Date

Gets or sets the last modified time of the xlsx file.

reservedContent

reservedContent: any

Gets or sets the reserved content from xlsx file that flexgrid or flexsheet doesn't support yet.

sheets

sheets: WorkSheet[]

Gets the WorkSheet array of the workbook.

styles

styles: WorkbookStyle[]

Gets the styles table of the workbook.

Methods

cancelAsync

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

    Parameters

    • Optional done: Object

      Callback invoked when the method finishes executing.

    Returns void

load

  • load(data: string | ArrayBuffer, includeStyles?: boolean): void
  • Loads from ArrayBuffer, base-64 string or data url. This method works with JSZip version 2.* only.

    For example:

    // This sample opens an xlsx file chosen from Open File
    // dialog and creates a workbook instance to load the file.
     
    // HTML
    <input type="file"
        id="importFile"
        accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    />
     
    // JavaScript
    var workbook, // receives imported IWorkbook
        importFile = document.getElementById('importFile');
     
    importFile.addEventListener('change', function () {
        loadWorkbook();
    });
     
    function loadWorkbook() {
        var reader,
            workbook,
            file = importFile.files[0];
        if (file) {
            reader = new FileReader();
            reader.onload = function (e) {
               workbook = new wijmo.xlsx.Workbook(),
               workbook.load(reader.result);
            };
            reader.readAsDataURL(file);
        }
    }

    Parameters

    • data: string | ArrayBuffer

      ArrayBuffer or base-64 string that contains the xlsx file content.

    • Optional includeStyles: boolean

      Indicates whether styles should be imported from xlsx file. The default value is true.

    Returns void

loadAsync

  • loadAsync(data: string | ArrayBuffer, onLoaded: Object, onError?: Object, includeStyles?: boolean): void
  • Loads from ArrayBuffer or base-64 string or data url asynchronously. This method works with JSZip version 3.* only.

    Parameters

    • data: string | ArrayBuffer

      ArrayBuffer or base-64 string that contains the xlsx file content.

    • onLoaded: Object

      This callback provides an approach to get an instance of the loaded workbook. Since this method is an asynchronous method, user is not able to get instance of the loaded workbook immediately. User has to get the instance through this callback. This has a single parameter, instance of the loaded workbook. It will be passed to user.

    • Optional onError: Object

      This callback catches error information when loading. This has a single parameter, the failure reason. Return value is be passed to user, if he wants to catch the load failure reason.

      For example:

      workbook.loadAsync(base64, 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 load failure is ' + reason);
      });
      
    • Optional includeStyles: boolean

      Indicates whether styles should be imported from xlsx file. The default value is true.

    Returns void

save

  • save(fileName?: string): string
  • Saves the book to a file and returns a base-64 string representation of the book. This method works with JSZip version 2.* only.

    For example, this sample creates an xlsx file with a single cell:

    function exportXlsx(fileName) {
        var book = new wijmo.xlsx.Workbook(),
            sheet = new wijmo.xlsx.WorkSheet(),
            bookRow = new wijmo.xlsx.WorkbookRow(),
            bookCell = new wijmo.xlsx.WorkbookCell();
        bookCell.value = 'Hello, Excel!';
        bookRow.cells.push(bookCell);
        sheet.rows.push(bookRow);
        book.sheets.push(sheet);
        book.save(fileName);
    }

    The file name is optional. If not provided, the method still returns a base-64 string representing the book. This string can be used for further processing on the client or on the server.

    Parameters

    • Optional fileName: string

      Name of the xlsx file to save.

    Returns string

    A base-64 string that represents the content of the file.

saveAsync

  • saveAsync(fileName?: string, onSaved?: Object, onError?: Object, onProgress?: Object): void
  • Saves the book to a file asynchronously. This method works with JSZip version 3.* only.

    Parameters

    • Optional fileName: string

      Name of the xlsx file to save.

    • Optional onSaved: Object

      This callback provides an approach to get the base-64 string that represents the content of the saved workbook. Since this method is an asynchronous method, user does not get the base-64 string immediately. User has to get the base-64 string via this callback. This has a single parameter, the base-64 string of the saved workbook. It will be passed to user.

    • Optional onError: Object

      This callback catches error information when saving. This has a single parameter, the failure reason. Return value will be passed to user, if he wants to catch the save failure reason.

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

      For example:

      workbook.saveAsync('', function (base64){
           // User can access the base64 string in this callback.
           document.getElementByID('export').href = 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;' + 'base64,' + base64;
      }, function (reason){
           // User can catch the failure reason in this callback.
           console.log('The reason of save failure is ' + reason);
      });
      

    Returns void

Static fromXlsxFormat

  • fromXlsxFormat(xlsxFormat: string): string[]
  • Converts the xlsx multi-section format string to an array of corresponding wijmo formats.

    Parameters

    • xlsxFormat: string

      The Excel format string, that may contain multiple format sections separated by a semicolon.

    Returns string[]

    An array of .Net format strings where each element corresponds to a separate Excel format section. The returning array always contains at least one element. It can be an empty string in case the passed Excel format is empty.

Static tableAddress

  • Convert Excel's alphanumeric cell, row or column index to the zero-based row/column indices pair.

    Parameters

    • xlsxIndex: string

      The alphanumeric Excel index that may include alphabetic A-based column index and/or numeric 1-based row index, like "D15", "D" or "15". The alphabetic column index can be in lower or upper case.

    Returns ITableAddress

    The object with row and col properties containing zero-based row and/or column indices. If row or column component is not specified in the alphanumeric index, then corresponding returning property is undefined.

Static toXlsxDateFormat

  • toXlsxDateFormat(format: string): string
  • Converts the wijmo date format to Excel format.

    Parameters

    • format: string

      The wijmo date format.

    Returns string

    Excel format representation.

Static toXlsxNumberFormat

  • toXlsxNumberFormat(format: string): string
  • Converts the wijmo number format to xlsx format.

    Parameters

    • format: string

      The wijmo number format.

    Returns string

    Excel format representation.

Static xlsxAddress

  • xlsxAddress(row: number, col: number, absolute?: boolean, absoluteCol?: boolean, isWholeRow?: boolean): string
  • Converts zero-based cell, row or column index to Excel alphanumeric representation.

    Parameters

    • row: number

      The zero-based row index or a null value if only column index is to be converted.

    • col: number

      The zero-based column index or a null value if only row index is to be converted.

    • Optional absolute: boolean

      True value indicates that absolute indices is to be returned for both, row and column (like $D$7). The absoluteCol parameter allows to redefine this value for the column index.

    • Optional absoluteCol: boolean

      True value indicates that column index is absolute.

    • Optional isWholeRow: boolean

      Indicates whether the Cell reference is whole row, whole column or specific cell range. If isWholeRow is true means the cell reference is whole row. If isWholeRow is false means the cell reference is whole column. If isWholeRow is null means the cell reference is specific cell range.

    Returns string

    The alphanumeric Excel index representation.