You can easily import data from an Excel file into SpreadSheet.
To load data from Excel into SpreadSheet, you can choose one of the ways below:
a) specifying the necessary file in the SpreadSheet constructor with the help of the url parameter:
webix.ui({
view:"spreadsheet",
url: "binary->../common/test.xlsx",
datatype:"excel"
});
The notation "binary->../common/test.xlsx" allows loading compiled files from the computer and get their content.
The "excel" datatype allows parsing the content of a binary file and getting it in the form necessary for SpreadSheet.
b) calling the load method:
$$("ssheet").load("binary->../common/test.xlsx", "excel");
The parameters are:
c) using the parse method to load data to the component:
{ view:"uploader", value:"Load from Excel file", on:{
onBeforeFileAdd: function(upload){
$$("ssheet").reset();
$$("ssheet").parse(upload.file, "excel");
return false;
}
}}
Parameters of the parse method are the following:
SpreadSheet allows importing a range of settings from an Excel file. Styles, column width and row heights are imported by default. You can also import:
You need to set the math:true property in the SpreadSheed configuration, if it is disabled by some reason.
webix.ui({
view: "spreadsheet",
data: base_data,
math: true
});
To import spans, you should set the spans:true property in the SpreadSheet config:
webix.ui({
view: "spreadsheet",
data: base_data,
spans: true
});
By default, Spreadsheet shows only the first imported sheet. In order to browse all of them, you need to set either the bottombar:true or toolbar:"full" properties in the SpreadSheet configuration:
webix.ui({
view:"spreadsheet",
data: base_data,
toolbar: "full" // or bottombar:true
});
You can also switch between the sheets via the showSheet(name) method:
$$("ssheet").showSheet("Tab 1");
SpreadSheet allows importing Webix-formatted dates from an Excel file.
You can customize the presentation of the loaded data: set the name of the sheet and control the number of the loaded rows.
webix.ui({
view:"spreadsheet",
url: "binary->../common/test.xlsx@Data[0-10]",
datatype:"excel"
});
The string value of the url property "binary->files/data.xlsx@Data[1-10]" includes the following parts:
To render rows starting from a certain row, you can set the rows array as [8-].
Related sample: Import from Excel
The dependencies which are necessary to import data from Excel files into SpreadSheet are generally taken from Webix CDN online catalog. If you need to import data offline, you should complete the following steps:
1. Download the package with CDN files from https://github.com/webix-hub/cdn-extras
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.
2. Rename the folder to "extras" and move it to the desired directory.
3. Set the path to the local CDN repository as:
webix.env.cdn = "/local_folder";
Note that specifying the path to the local CDN repository has some peculiarities:
webix.env.cdn = "../../../../local_folder";
webix.env.cdn = "http://localhost/local_folder";
You can compare elements and settings supported by SpreadSheet for import and export to Excel.
Back to top