| 
									
										
										
										
											2017-09-12 20:02:06 +00:00
										 |  |  | # Electron
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This library is compatible with Electron and should just work out of the box. | 
					
						
							| 
									
										
										
										
											2022-03-07 07:36:36 +00:00
										 |  |  | The demonstration uses Electron 17.1.0.  The library is added via `require` from | 
					
						
							| 
									
										
										
										
											2021-09-08 01:43:05 +00:00
										 |  |  | the renderer process. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The library can also be required from the main process, as shown in this demo | 
					
						
							|  |  |  | to render a version string in the About dialog on OSX. | 
					
						
							| 
									
										
										
										
											2017-09-12 20:02:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | The standard HTML5 `FileReader` techniques from the browser apply to Electron. | 
					
						
							|  |  |  | This demo includes a drag-and-drop box as well as a file input box, mirroring | 
					
						
							| 
									
										
										
										
											2021-09-08 01:43:05 +00:00
										 |  |  | the [SheetJS Data Preview Live Demo](http://oss.sheetjs.com/sheetjs/) | 
					
						
							| 
									
										
										
										
											2017-09-12 20:02:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-24 23:40:09 +00:00
										 |  |  | The core data in this demo is an editable HTML table.  The readers build up the | 
					
						
							|  |  |  | table using `sheet_to_html` (with `editable:true` option) and the writers scrape | 
					
						
							|  |  |  | the table using `table_to_book`. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Reading and Writing Files
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-12 20:02:06 +00:00
										 |  |  | Since electron provides an `fs` implementation, `readFile` and `writeFile` can | 
					
						
							| 
									
										
										
										
											2017-09-24 23:40:09 +00:00
										 |  |  | be used in conjunction with the standard dialog windows.  For example: | 
					
						
							| 
									
										
										
										
											2017-09-12 20:02:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							| 
									
										
										
										
											2017-09-24 23:40:09 +00:00
										 |  |  | /* from app code, require('electron').remote calls back to main process */ | 
					
						
							| 
									
										
										
										
											2017-09-12 20:02:06 +00:00
										 |  |  | var dialog = require('electron').remote.dialog; | 
					
						
							| 
									
										
										
										
											2017-09-24 23:40:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* show a file-open dialog and read the first selected file */ | 
					
						
							|  |  |  | var o = dialog.showOpenDialog({ properties: ['openFile'] }); | 
					
						
							| 
									
										
										
										
											2018-03-07 17:21:48 +00:00
										 |  |  | var workbook = XLSX.readFile(o[0]); | 
					
						
							| 
									
										
										
										
											2017-09-24 23:40:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* show a file-save dialog and write the workbook */ | 
					
						
							|  |  |  | var o = dialog.showSaveDialog(); | 
					
						
							|  |  |  | XLSX.writeFile(workbook, o); | 
					
						
							| 
									
										
										
										
											2017-09-12 20:02:06 +00:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2017-09-24 23:40:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-07 07:36:36 +00:00
										 |  |  | ## Breaking Changes in Electron
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The first version of this demo used Electron 1.7.5. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Electron 9.0.0 and later require the preference `nodeIntegration: true` in order | 
					
						
							|  |  |  | to `require('XLSX')` in the renderer process. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Electron 12.0.0 and later also require `worldSafeExecuteJavascript: true` and | 
					
						
							|  |  |  | `contextIsolation: true`. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Electron 14+ must use `@electron/remote` instead of `remote`. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-24 23:40:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [](https://github.com/SheetJS/js-xlsx) |