1

I am trying to learn how to put in a html page a local .csv file using javascript. I am using the Electron framework, and I aim to handle everything locally. What I need to do is:

  • Read the CSV file.
  • Be able to change the datas (delete rows for exemple)
  • Use innerHTML to insert the csv data into a div. My problem is in reading the CSV file. All of the examples I have found I think will only work if there is a web server running, which I prefer to avoid.
2

1 Answer 1

1

You can try this papapase.com. Below is a simple example:

const data = [];
const fileInput = document.querySelector('.fileInput');
fileInput.addEventListener('change', () => {
  Papa.parse(fileInput.files[0], {
    download: true,
    header: true,
    keepEmptyRows: false,
    skipEmptyLines: true,
    step: function(row) {
      data.push(row.data);
    },
    complete: function(results) {
      document.querySelector("code").innerHTML = JSON.stringify(data);
      console.log(data);
    }
  });
});
<script src="https://www.papaparse.com/resources/js/papaparse.js"></script>
<input type="file" class="fileInput" />
<br>
<code>

</code>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.