JSFile handles file creation, downloading and reading in the browser using the SheetJS/JS-XLXS & SheetJS/JS-XLX libraries.
js-file depends on Lodash, js-xlsx, js-xls
bower install js-file --save
<script src='bower_components/js-file/dist/js-file.min.js'></script>
Create an instance of window.JSFile.Workbook, and pass the following data as the first argument:
[
// repeat for each sheet
{
"name": "Sheet Name",
"headers": [
// repeat for each header row
[
// repeat for each header
{
"value": "First Name" // alternatives: displayName, display_name, name, label
}
]
],
"data": [
// repeat for each row
[
// repeat for each column
{
"value": "John"
}
]
],
"columns": [
// repeat for each column
{
"type": "string"
}
]
}
];
Call window.JSFile.FileDownloader.downloadWorkbook with the result of the above method as the first argument, and whatever you want the file to be called as the second argument.
Model used to create workbook.
Initiates a download when passed an instance of the JSFile.Workbook model.
param | type | description |
---|---|---|
workbook | JSFile.Workbook | Workbook created using JSFile.FileCreator.createWorkbook |
filename | string | Name of the file (May include extension) |
file_extension | string | Extension of the file (Optional) |
Externally provided fallback method when Modernizr.adownload fails
param | type | description |
---|---|---|
blob | Blob | file blobs |
filename | string | filename incuding extension |
Returns a file type (either xlxs, xlx, csv, ods or txt) by matching provided argument to list of known file types.
param | type | description |
---|---|---|
type | string | File type to use when matching against list |
Returns a list of worksheet names.
param | type | description |
---|---|---|
file_data | object | Data to read and analyse |
file_type | string | Type of file_data |
Converts a file into a javascript array. Currently supports xlxs, xlx, csv, ods, txt.
param | type | description |
---|---|---|
file_data | object | Data to read and convert to array |
file_type | string | Type of file_data |
worksheet_has_headings | array | boolean |
group_by | string | how to group the data (row or column) *coming soon |