Posted 10 December 2018, 4:59 am EST
Hello,
I am using the library to display the name of the sheets of an excel, and also to display the N first rows of a determined sheet.
That is working correctly, but when I load a very big excel it takes a long time. That´s to be expected, since apparently is processing the WHOLE excel. But given that actually I do not need to read ALL the data in the Excel, but only a subset (first hundred of rows, I can do without the 500.000 that follow) I was wondering if there is a more efficient way of loading the file.
My current code:
public onFileChange(evt: any) {
const target: DataTransfer = <DataTransfer>(evt.target);
if (target.files.length !== 1) throw new Error('Cannot use multiple files');
console.log(target.files.item(0).name);
this.readMyExcel(target.files.item(0));
}
private readMyExcel(myFile)
{
this._excelIO.open(myFile, (json) => {
console.log(json);
console.log(json.sheetCount);
var mySheets = json.sheets;
this.myExcelSheets = [];
var countersheet = 0;
for (var x in mySheets) {
this.myExcelSheets.push({name:x,position:countersheet});
countersheet = countersheet + 1;
}
console.log(this.myExcelSheets);
this.cdr.detectChanges();
});
}
-
How could I modify the code above so that when reading a big file, I can still list the sheets names, without actually having to load all the data? Notice tha in the sample above I do not ven use the actual data of any sheet, I am only interested in the sheet name.
-
In the above example I am using only ‘@grapecity/spread-excelio’. since I am only trying to parse some information from h excel, but I am not actually to display it I am not using the graphical component in “@grapecity/spread-sheets”. Is this a good practice? Should I be accesing the ‘json’ object the way I do, or is that a frail hack, and I must do this:
this._spread.fromJSON(json, {});
And then obtain the data from this._spread (GC.Spread.Sheets.Workbook)
Thanks for your help