Excel File keep loaded in background? #573

Closed
opened 2017-02-28 06:08:41 +00:00 by WildDusk · 2 comments
WildDusk commented 2017-02-28 06:08:41 +00:00 (Migrated from github.com)

Is there a way to load the file once and use it without reloading every time I need to retrieve something?

Is there a way to load the file once and use it without reloading every time I need to retrieve something?
reviewher commented 2017-02-28 06:27:56 +00:00 (Migrated from github.com)

You can always store the workbook in a global variable when you read the data. For example, in node using readFile:

function read_file() {
    var wb_local = XLSX.readFile('foo.xlsx');
    wb_global = XLSX.readFile('foo.xlsx');
}
read_file();
// at this point in the code wb_global is available but not wb_local

In the browser, you can use the same technique. For example, in the web demo http://oss.sheetjs.com/js-xlsx you can save the workbook to a global variable: https://github.com/SheetJS/js-xlsx/blob/gh-pages/index.html#L195

 function process_wb(wb) {
+        wb_global = wb;
         var output = "";

In fact, you can even serialize the object with JSON.stringify and later reload it with JSON.parse -- that's actually how we pass data from web worker to the main browser thread

You can always store the workbook in a global variable when you read the data. For example, in node using readFile: ```js function read_file() { var wb_local = XLSX.readFile('foo.xlsx'); wb_global = XLSX.readFile('foo.xlsx'); } read_file(); // at this point in the code wb_global is available but not wb_local ``` In the browser, you can use the same technique. For example, in the web demo http://oss.sheetjs.com/js-xlsx you can save the workbook to a global variable: https://github.com/SheetJS/js-xlsx/blob/gh-pages/index.html#L195 ```diff function process_wb(wb) { + wb_global = wb; var output = ""; ``` In fact, you can even serialize the object with `JSON.stringify` and later reload it with `JSON.parse` -- that's actually how we pass data [from web worker to the main browser thread](https://github.com/SheetJS/js-xlsx/blob/gh-pages/xlsxworker.js#L15)
SheetJSDev commented 2017-03-27 15:52:44 +00:00 (Migrated from github.com)

@WildDusk the suggestion from @reviewher is probably the best bet: just store the workbook somewhere as a global (as @reviewher explained), then attach an event handler to the select box that calls process_wb(wb_global). If you would like to submit a PR with that change to the demo, we'll accept it :)

@WildDusk the suggestion from @reviewher is probably the best bet: just store the workbook somewhere as a global (as @reviewher explained), then attach an event handler to the select box that calls `process_wb(wb_global)`. If you would like to submit a PR with that change to the demo, we'll accept it :)
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#573
No description provided.