Available only in PRO Edition
Since 3.0
The widget is available in the Webix Pro edition.
ExcelViewer is an extension tool intended for viewing Excel files.
The constructor of the viewer is the following:
{
view:"excelviewer",
toolbar:"toolbar",
excelHeader:true,
url:"binary->files/data.xlsx"
}
The configuration properties are:
Binary proxy is used for loading the file, which allows to get its contents as ArrayBuffer.
The default datatype for Excel Viewer is excel. It is strongly recommended not to change it manually to avoid parsing inconsistency.
loads an excel file to the viewer
parameters:
$$("viewer").load("binary->data.xlsx", "excel");
parses file data to the viewer
parameters:
{
view:"uploader", value:"Select Excel File", width:200,
on:{
onBeforeFileAdd:function(upload){
$$("excel").clearAll();
$$("excel").parse(upload.file, "excel");
return false;
}
}
}
Related sample: Excel File Uploading and Downloading
switches to the specified sheet
parameters:
$$("viewer").showSheet("Data");
It's possible to show a toolbar with tabs that correspond to the Excel sheets. In order to render such a toolbar, the dedicated excelbar view should be initialized.
{
view:"excelbar",
id:"toolbar"
}
returns the toolbar object
$$("toolbar").getInput();
returns:
returns the currently selected tab
$$("toolbar").getValue();
returns:
sets tabs in the toolbar (should correspond to excel sheets)
parameters:
$$("toolbar").setSheets(["Data", "Files"]);
sets the selected tab within a toolbar
parameters:
$$("toolbar").setValue(value);
There are three possible ways of loading data to Excel Viewer:
{
view:"excelviewer",
url:"binary->files/data.xlsx"
}
{ view:"excelviewer", id:"excel", editable:true, header:false },
...
$$("excel").load("binary->files/data.xlsx", "excel");
Binary proxy is used for loading the file, which allows getting its contents as ArrayBuffer. The datatype is "excel".
{ view:"uploader", value:"Select Excel File", width:200,
on:{
onBeforeFileAdd:function(upload){
$$("excel").clearAll();
$$("excel").parse(upload.file, "excel");
return false;
}
}
}
Related sample: Excel File Uploading and Downloading
Excel Viewer allows importing a range of settings from an Excel file. Styles, column width and row heights are imported by default. You can also import:
webix.ui({
view: "excelviewer",
data: base_data,
spans: true
});
Related sample: Excel File Uploading and Downloading
By default, Excel Viewer shows only the first imported sheet. In order to browse all of them, you need to set an excelbar:
// setting an excelbar
{
view:"excelbar",
id:"toolbar1"
}
// applying the excelbar to the excelviewer
{
view:"excelviewer",
toolbar:"toolbar1"
}
Excel Viewer allows importing Webix-formatted dates from an Excel file.
You can customize the presentation of the loaded data, such as displaying headers and controlling the number of the loaded rows.
{
view:"excelviewer",
url:"binary->files/data.xlsx@Data[1-10]"
}
The string value of the url property binary->files/data.xlsx@Data[1-10]" includes the following parts:
Excel Viewer allows exporting a range of settings into an Excel file. Styles and column width are exported by default. You can also export:
webix.toExcel($$("excelviewer"), { heights:true});
In case the styles:true option is set, the heights option is automatically set to "all".
To export spans, you should set the spans:true property in the second parameter of the toExcel method:
webix.toExcel($$("excelviewer"), { spans:true});
By default, Excel Viewer exports the currently active sheet to an Excel file. You have several other options:
1) to export all the sheets, set the sheets:true option in the second parameter of the toExcel method
webix.toExcel($$("excelviewer"), { sheets:true});
2) to export separate sheets, set an array with sheets ids as a value of the sheets option:
webix.toExcel($$("excelviewer"), { sheets:["s1","s2"]});
3) to export a certain sheet, set its id as a value of the sheets option:
webix.toExcel($$("excelviewer"), { sheets:"s2"});
The dependencies which are necessary for working with Excel Viewer are generally taken from Webix CDN online catalog. If you need to view and download files via Excel Viewer offline, you should complete the following steps:
If you use Webix version 5.0 or later, use the file xlsx.core.styles.min.js.
In case of a version earlier than 5.0, choose the file xlsx.core.min.js.
webix.env.cdn = "/local_folder";
Note that specifying the path to the local CDN repository has some peculiarities:
1) in case you set the path relative to the current page, it should be specified as:
webix.env.cdn = "../../../../local_folder";
2) the absolute path to the repository should be specified as follows:
webix.env.cdn = "http://localhost/local_folder";
Back to top