@@ -215,6 +215,7 @@ The [`demos` directory](demos/) includes sample projects for:
215215- [ ` Headless Browsers ` ] ( demos/headless/ )
216216- [ ` canvas-datagrid ` ] ( demos/datagrid/ )
217217- [ ` Swift JSC and other engines ` ] ( demos/altjs/ )
218+ - [ ` internet explorer ` ] ( demos/oldie/ )
218219
219220### Optional Modules
220221
@@ -339,7 +340,7 @@ var worksheet = XLSX.read(htmlstr, {type:'string'});
339340 <summary ><b >Browser download file (ajax)</b > (click to show)</summary >
340341
341342Note: for a more complete example that works in older browsers, check the demo
342- at < http://oss.sheetjs.com/js-xlsx/ajax.html > ). The < demos/xhr/> directory also
343+ at < http://oss.sheetjs.com/js-xlsx/ajax.html > ). The [ ` xhr ` demo ] ( demos/xhr/ )
343344includes more examples with ` XMLHttpRequest ` and ` fetch ` .
344345
345346``` js
@@ -414,6 +415,8 @@ input_dom_element.addEventListener('change', handleFile, false);
414415
415416</details >
416417
418+ More specialized cases, including mobile app file processing, are covered in the
419+ [ included demos] ( demos/ )
417420
418421### Parsing Examples
419422
@@ -590,8 +593,7 @@ Assuming `workbook` is a workbook object:
590593<details >
591594 <summary ><b >nodejs write a file</b > (click to show)</summary >
592595
593- ` writeFile ` is only available in server environments. Browsers have no API for
594- writing arbitrary files given a path, so another strategy must be used.
596+ ` XLSX.writeFile ` uses ` fs.writeFileSync ` in server environments:
595597
596598``` js
597599if (typeof require !== ' undefined' ) XLSX = require (' xlsx' );
@@ -603,7 +605,7 @@ XLSX.writeFile(workbook, 'out.xlsb');
603605</details >
604606
605607<details >
606- <summary ><b >Browser add to web page</b > (click to show)</summary >
608+ <summary ><b >Browser add TABLE element to page</b > (click to show)</summary >
607609
608610The ` sheet_to_html ` utility function generates HTML code that can be added to
609611any DOM element.
@@ -614,29 +616,10 @@ var container = document.getElementById('tableau');
614616container .innerHTML = XLSX .utils .sheet_to_html (worksheet);
615617```
616618
617-
618- </details >
619-
620- <details >
621- <summary ><b >Browser save file</b > (click to show)</summary >
622-
623- Note: browser generates binary blob and forces a "download" to client. This
624- example uses [ FileSaver] ( https://github.com/eligrey/FileSaver.js/ ) :
625-
626- ``` js
627- /* bookType can be any supported output type */
628- var wopts = { bookType: ' xlsx' , bookSST: false , type: ' array' };
629-
630- var wbout = XLSX .write (workbook,wopts);
631-
632- /* the saveAs call downloads a file on the local machine */
633- saveAs (new Blob ([wbout],{type: " application/octet-stream" }), " test.xlsx" );
634- ```
635-
636619</details >
637620
638621<details >
639- <summary ><b >Browser upload to server </b > (click to show)</summary >
622+ <summary ><b >Browser upload file (ajax) </b > (click to show)</summary >
640623
641624A complete example using XHR is [ included in the XHR demo] ( demos/xhr/ ) , along
642625with examples for fetch and wrapper libraries. This example assumes the server
@@ -658,6 +641,65 @@ req.send(formdata);
658641
659642</details >
660643
644+ <details >
645+ <summary ><b >Browser save file</b > (click to show)</summary >
646+
647+ ` XLSX.writeFile ` wraps a few techniques for triggering a file save:
648+
649+ - ` URL ` browser API creates an object URL for the file, which the library uses
650+ by creating a link and forcing a click. It is supported in modern browsers.
651+ - ` msSaveBlob ` is an IE10+ API for triggering a file save.
652+ - ` IE_FileSave ` uses VBScript and ActiveX to write a file in IE6+ for Windows
653+ XP and Windows 7. The shim must be included in the containing HTML page.
654+
655+ There is no standard way to determine if the actual file has been downloaded.
656+
657+ ``` js
658+ /* output format determined by filename */
659+ XLSX .writeFile (workbook, ' out.xlsb' );
660+ /* at this point, out.xlsb will have been downloaded */
661+ ```
662+
663+ </details >
664+
665+ <details >
666+ <summary ><b >Browser save file (compatibility)</b > (click to show)</summary >
667+
668+ ` XLSX.writeFile ` techniques work for most modern browsers as well as older IE.
669+ For much older browsers, there are workarounds implemented by wrapper libraries.
670+
671+ [ ` FileSaver.js ` ] ( https://github.com/eligrey/FileSaver.js/ ) implements ` saveAs ` .
672+ Note: ` XLSX.writeFile ` will automatically call ` saveAs ` if available.
673+
674+ ``` js
675+ /* bookType can be any supported output type */
676+ var wopts = { bookType: ' xlsx' , bookSST: false , type: ' array' };
677+
678+ var wbout = XLSX .write (workbook,wopts);
679+
680+ /* the saveAs call downloads a file on the local machine */
681+ saveAs (new Blob ([wbout],{type: " application/octet-stream" }), " test.xlsx" );
682+ ```
683+
684+ [ ` Downloadify ` ] ( https://github.com/dcneiner/downloadify ) uses a Flash SWF button
685+ to generate local files, suitable for environments where ActiveX is unavailable:
686+
687+ ``` js
688+ Downloadify .create (id,{
689+ /* other options are required! read the downloadify docs for more info */
690+ filename: " test.xlsx" ,
691+ data : function () { return XLSX .write (wb, {bookType: " xlsx" , type: ' base64' }); },
692+ append: false ,
693+ dataType: ' base64'
694+ });
695+ ```
696+
697+ The [ ` oldie ` demo] ( demos/oldie/ ) shows an IE-compatible fallback scenario.
698+
699+ </details >
700+
701+ The [ included demos] ( demos/ ) cover mobile apps and other special deployments.
702+
661703### Writing Examples
662704
663705- < http://sheetjs.com/demos/table.html > exporting an HTML table
@@ -705,7 +747,8 @@ Parse options are described in the [Parsing Options](#parsing-options) section.
705747
706748` XLSX.write(wb, write_opts) ` attempts to write the workbook ` wb `
707749
708- ` XLSX.writeFile(wb, filename, write_opts) ` attempts to write ` wb ` to ` filename `
750+ ` XLSX.writeFile(wb, filename, write_opts) ` attempts to write ` wb ` to ` filename ` .
751+ In browser-based environments, it will attempt to force a client-side download.
709752
710753` XLSX.writeFileAsync(filename, wb, o, cb) ` attempts to write ` wb ` to ` filename ` .
711754If ` o ` is omitted, the writer will use the third argument as the callback.
@@ -2015,6 +2058,7 @@ produces HTML output. The function takes an options argument:
20152058
20162059| Option Name | Default | Description |
20172060| :---------- | :------: | :-------------------------------------------------- |
2061+ | ` id ` | | Specify the ` id ` attribute for the ` TABLE ` element |
20182062| ` editable ` | false | If true, set ` contenteditable="true" ` for every TD |
20192063| ` header ` | | Override header (default ` html body ` ) |
20202064| ` footer ` | | Override footer (default ` /body /html ` ) |
0 commit comments