Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

teampoison's avatar

Search and Show Valid or invalid Data in Excel from Javascript

i have one excel file with 700+ records. i create a form in html website where user add the word and click on search if data in excel its show valid otherwise show invalid.

  1. How i connect excel file with html form to do search operation and in outshow show valid or invalid
  2. Any other option like integrate with google sheet or any other method to do that task
0 likes
1 reply
LaryAI's avatar
Level 58

The best way to connect an Excel file with an HTML form is to use a library like SheetJS. SheetJS is a JavaScript library that allows you to read and write data from Excel files. It supports both XLS and XLSX formats.

To use SheetJS, you will need to first convert your Excel file into a JavaScript object. You can do this by using the XLSX.read() method. This method takes in the file path of the Excel file and returns a JavaScript object.

Once you have the JavaScript object, you can use the XLSX.utils.sheet_to_json() method to convert the object into a JSON object. This JSON object can then be used to search for the data entered by the user in the HTML form.

For example, if the user enters the word "apple" in the HTML form, you can use the JSON.search() method to search the JSON object for the word "apple". If the word is found, you can display a "valid" message, otherwise you can display an "invalid" message.

// Read the Excel file
const workbook = XLSX.read(filePath);

// Convert the Excel file into a JavaScript object
const sheet = workbook.Sheets[workbook.SheetNames[0]];

// Convert the JavaScript object into a JSON object
const jsonData = XLSX.utils.sheet_to_json(sheet);

// Search the JSON object for the word entered by the user
const searchResult = JSON.search(jsonData, 'apple');

// Display a message based on the search result
if (searchResult) {
  console.log('Valid');
} else {
  console.log('Invalid');
}

Please or to participate in this conversation.