ComponentOne ASP.NET MVC Controls
Workbook Class
File
wijmo.xlsx.js
Module
wijmo.xlsx
Implements
IWorkbook

Represents an Excel workbook.

Constructor

Properties

Methods

Constructor

constructor

constructor(): Workbook

Initializes a new instance of the Workbook class.

Returns
Workbook

Properties

activeWorksheet

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

Type
number

application

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

Type
string

colorThemes

Gets the color of the workbook themes.

Type
string[]

company

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

Type
string

created

Gets or sets the creation time of the xlsx file.

Type
Date

creator

Gets or sets the creator of the xlsx file.

Type
string

definedNames

Gets the defined name items of the workbook.

Type
DefinedName[]

lastModifiedBy

Gets or sets the last modifier of the xlsx file.

Type
string

modified

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

Type
Date

reservedContent

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

Type
any

sheets

Gets the WorkSheet array of the workbook.

Type
WorkSheet[]

styles

Gets the styles table of the workbook.

Type
WorkbookStyle[]

Methods

 

Static fromXlsxFormat
fromXlsxFormat(xlsxFormat: string): string[]

Converts the xlsx multi-section format string to an array of corresponding wijmo formats.

Parameters
Returns
string[]

load

load(base64: string): void

Loads from base-64 string or data url. This method works with JSZip 2.5.

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
Returns
void

loadAsync

loadAsync(base64: string, onLoaded?: (workbook: Workbook), onError?: (reason?: any)): void

Loads from base-64 string or data url asynchronously. This method works with JSZip 3.0.

Parameters
Optional

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.

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);
});
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 2.5.

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
Returns
string

saveAsync

saveAsync(fileName?: string, onSaved?: (base64?: string), onError?: (reason?: any)): void

Saves the book to a file asynchronously. This method works with JSZip 3.0.

Parameters
Returns
void

Static tableAddress

tableAddress(xlsxIndex: string): ITableAddress

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

Parameters
Returns
ITableAddress

Static toXlsxDateFormat

toXlsxDateFormat(format: string): string

Converts the wijmo date format to Excel format.

Parameters
Returns
string

Static toXlsxNumberFormat

toXlsxNumberFormat(format: string): string

Converts the wijmo number format to xlsx format.

Parameters
Returns
string

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
Returns
string