我开始研究Electron。
我试图:
打开文件并显示其内容。
但我面对Sub ShowHideWorksheets()
Dim Cell As Range
For Each Cell In Range("B6:B" & Range("B" & Rows.Count).End(xlUp).row)
If Sheets(Cell.Value).Visible = True Then
Sheets(Cell.Value).Visible = False
Else
Sheets(Cell.Value).Visible = True
End If
Next Cell
End Sub
。
这是项目结构:
Document is not defined Error
这是application_menu.js:
text_editor
---->main_process
---->menus
---->application_menu.js
---->renderer_process
---->open_file.js
---->index.html
---->main.js
---->package.json
这是open_file.js:
const { app, BrowserWindow, Menu } = require('electron')
const electron = require('electron')
const fs = require('fs')
const ipc = require('electron').ipcMain
const open_file = require('../../renderer_process/open_file')
const template = [{
label: 'File',
submenu: [{
label: 'Open File..',
click() {open_file.open()}
}, ]
}]
electron.app.on('ready', () => {
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
})
和index.html:
const ipc = require('electron').ipcRenderer
const electron = require('electron')
const fs = require('fs')
let open_file = {
open() {
console.log("reached here again");
electron.dialog.showOpenDialog(function(fileNames) {
if (fileNames === undefined)
return;
else {
var fileName = fileNames[0];
fs.readFile(fileName, 'utf-8', function(err, data) {
document.getElementById("editor").value = data;
})
}
})
}
}
module.exports = open_file
单击菜单栏中的“打开”时,会显示选择文件的对话框,但是当文件打开时,会引发文档未定义错误。