#reading a csv file from the local filesystem using electron and electron forge

5 messages · Page 1 of 1 (latest)

rapid citrus
#

Hello guys i am trying to add a button in my main menu to import/export data and the button to import data should read a csv file from the filesystem by opening a dialog where the user can select the choosen file.
I can't integrate this after a long period of searching for solution.
can anyone show me how to do it please?
here is my index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
   <!-- head code -->
  </head>
  <body>
      <!-- body -->
    <div class="main">
      <a href="#"><button class="btn">Import</button></a>
    </div>
  </body>
</html>

here is the index.js

const { app, BrowserWindow } = require('electron')
const path = require('path')
const createWindow = () => {
   const mainWindow = new BrowserWindow({
    width: 1200,
    height: 900,
    resizable:false,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    },
    icon: path.join(__dirname, 'assets/icons/logo.png')   
  })
  mainWindow.loadFile('index.html')
  mainWindow.setMenu(null);
}
app.whenReady().then(() => {
  createWindow()
  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })
})
app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') app.quit()
})

preload.js

window.addEventListener('DOMContentLoaded', () => {
    const replaceText = (selector, text) => {
      const element = document.getElementById(selector)
      if (element) element.innerText = text
    }
    for (const dependency of ['chrome', 'node', 'electron']) {
      replaceText(`${dependency}-version`, process.versions[dependency])
    }
  })
halcyon schooner
#

Read the electron docs about ipc communication and in the invoke example use dialog api from electron

#

Then use fs to read the file

halcyon schooner
#

@limpid sky this one spams everywhere. Ban and delete all messages would be nice.
Btw there is no @ admin role ping available though you mentioned that earlier

analog beacon
#

Actually, you can ping if you type a space after Admin: <@&745038904532402237>