Posted 28 February 2018, 2:59 pm EST
Hi,
Apologies for the delay in getting back to you.
1&3 - There’s no direct way to merge the sheets in Spread.Sheets and the imported excel file. What I would suggest you is to add a second spread to your page with its display set to none. Then import the excel file into this second spread and then add the sheets from this second spread to your actual spread. The code would look something like this:
<div id="ss" style="height: 80%; border: 1px solid #ddd;"></div>
<div id="ss2" style="height :0px;display:none"></div>
window.onload = function () {
spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
spread2 = new GC.Spread.Sheets.Workbook(document.getElementById("ss2"));
excelIO = new GC.Spread.Excel.IO();
};
function processFileSelected() {
var file = this.files[0],
action = $(this).data("action");
if (!file) return false;
// clear to make sure change event occures even when same file selected again
$("#fileSelector").val("");
if (action === "doImport") {
return ImportFile(file);
}
}
function ImportFile(excelFile) {
excelIO.open(excelFile, function (json) {
var workbookObj = json;
spread2.fromJSON(workbookObj);
var sheets = spread2.getSheetCount();
spread.addSheet(3, spread2.sheets[1]);
spread.addSheet(4, spread2.sheets[2]);
spread.addSheet(4, spread2.sheets[3]);
}, function (e) {
console.log(e);
});
}
- SpreadJS automatically picks up the filters applied in an imported excel file for better user experience. If you wish to ignore those filters, you’ll have to clear the filters once the excel file has been imported. The code would be something like below:
var activeSheet = spread.getActiveSheet();
var rowFilter = activeSheet.rowFilter();
if (rowFilter) {
var cols = activeSheet.getColumnCount();
for (var i = 0; i < cols; i++) {
if (rowFilter.isFiltered(i))
rowFilter.removeFilterItems(i);
}
rowFilter.filter();
}
Hope it helps