未验证 提交 5b1440a1 编写于 作者: S Srijon Saha 提交者: GitHub

Update electron demo (#2027)

* Update electron demo to version 9

[ci skip]
Co-authored-by: NIan Jennings <ian@meetjennings.com>
上级 9ec9f4fe
# Electron # Electron
This library is compatible with Electron and should just work out of the box. This library is compatible with Electron and should just work out of the box.
The demonstration uses Electron 1.7.5. The library is added via `require` from The demonstration uses Electron 9.0.5. The library is added via `require` from
the render process. It can also be required from the main process, as shown in the renderer process. Note that Electron now requires `nodeIntegration: true`
this demo to render a version string in the About dialog on OSX. in order to `require('XLSX')` in the renderer process. It can also be required
from the main process, as shown in this demo to render a version string in the
About dialog on OSX.
The standard HTML5 `FileReader` techniques from the browser apply to Electron. 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 This demo includes a drag-and-drop box as well as a file input box, mirroring
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Security-Policy" content="script-src 'self' https:">
<title>SheetJS Electron Demo</title> <title>SheetJS Electron Demo</title>
<style> <style>
#drop{ #drop{
......
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */ /* xlsx.js (C) 2013-present SheetJS -- https://sheetjs.com */
/*global Uint8Array, console */ /* global Uint8Array, console */
/* exported export_xlsx */ /* exported export_xlsx */
/* eslint no-use-before-define:0 */ /* eslint no-use-before-define:0 */
var XLSX = require('xlsx'); var XLSX = require('xlsx');
...@@ -19,16 +19,6 @@ var process_wb = (function() { ...@@ -19,16 +19,6 @@ var process_wb = (function() {
}; };
})(); })();
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36810333-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
var do_file = (function() { var do_file = (function() {
return function do_file(files) { return function do_file(files) {
var f = files[0]; var f = files[0];
...@@ -64,8 +54,8 @@ var do_file = (function() { ...@@ -64,8 +54,8 @@ var do_file = (function() {
(function() { (function() {
var readf = document.getElementById('readf'); var readf = document.getElementById('readf');
function handleF(/*e*/) { async function handleF(/*e*/) {
var o = electron.dialog.showOpenDialog({ var o = await electron.dialog.showOpenDialog({
title: 'Select a file', title: 'Select a file',
filters: [{ filters: [{
name: "Spreadsheets", name: "Spreadsheets",
...@@ -73,7 +63,7 @@ var do_file = (function() { ...@@ -73,7 +63,7 @@ var do_file = (function() {
}], }],
properties: ['openFile'] properties: ['openFile']
}); });
if(o.length > 0) process_wb(XLSX.readFile(o[0])); if(o.filePaths.length > 0) process_wb(XLSX.readFile(o.filePaths[0]));
} }
readf.addEventListener('click', handleF, false); readf.addEventListener('click', handleF, false);
})(); })();
...@@ -87,18 +77,18 @@ var do_file = (function() { ...@@ -87,18 +77,18 @@ var do_file = (function() {
var export_xlsx = (function() { var export_xlsx = (function() {
var HTMLOUT = document.getElementById('htmlout'); var HTMLOUT = document.getElementById('htmlout');
var XTENSION = "xls|xlsx|xlsm|xlsb|xml|csv|txt|dif|sylk|slk|prn|ods|fods|htm|html".split("|") var XTENSION = "xls|xlsx|xlsm|xlsb|xml|csv|txt|dif|sylk|slk|prn|ods|fods|htm|html".split("|")
return function() { return async function() {
var wb = XLSX.utils.table_to_book(HTMLOUT); var wb = XLSX.utils.table_to_book(HTMLOUT);
var o = electron.dialog.showSaveDialog({ var o = await electron.dialog.showSaveDialog({
title: 'Save file as', title: 'Save file as',
filters: [{ filters: [{
name: "Spreadsheets", name: "Spreadsheets",
extensions: XTENSION extensions: XTENSION
}] }]
}); });
console.log(o); console.log(o.filePath);
XLSX.writeFile(wb, o); XLSX.writeFile(wb, o.filePath);
electron.dialog.showMessageBox({ message: "Exported data to " + o, buttons: ["OK"] }); electron.dialog.showMessageBox({ message: "Exported data to " + o.filePath, buttons: ["OK"] });
}; };
})(); })();
void export_xlsx; void export_xlsx;
...@@ -7,14 +7,20 @@ var app = electron.app; ...@@ -7,14 +7,20 @@ var app = electron.app;
var win = null; var win = null;
function createWindow() { function createWindow() {
if(win) return; if (win) return;
win = new electron.BrowserWindow({width:800, height:600}); win = new electron.BrowserWindow({
width: 800, height: 600,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
}
});
win.loadURL("file://" + __dirname + "/index.html"); win.loadURL("file://" + __dirname + "/index.html");
win.webContents.openDevTools(); win.webContents.openDevTools();
win.on('closed', function() { win = null; }); win.on('closed', function () { win = null; });
} }
if(app.setAboutPanelOptions) app.setAboutPanelOptions({ applicationName: 'sheetjs-electron', applicationVersion: "XLSX " + XLSX.version, copyright: "(C) 2017-present SheetJS LLC" }); if (app.setAboutPanelOptions) app.setAboutPanelOptions({ applicationName: 'sheetjs-electron', applicationVersion: "XLSX " + XLSX.version, copyright: "(C) 2017-present SheetJS LLC" });
app.on('open-file', function() { console.log(arguments); }); app.on('open-file', function () { console.log(arguments); });
app.on('ready', createWindow); app.on('ready', createWindow);
app.on('activate', createWindow); app.on('activate', createWindow);
app.on('window-all-closed', function() { if(process.platform !== 'darwin') app.quit(); }); app.on('window-all-closed', function () { if (process.platform !== 'darwin') app.quit(); });
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
"version": "0.0.0", "version": "0.0.0",
"main": "main.js", "main": "main.js",
"dependencies": { "dependencies": {
"electron": "~1.7.x", "xlsx": "*",
"xlsx": "*" "electron": "^9.0.5"
},
"scripts": {
"start": "electron ."
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册