<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Emmanuel David</title>
    <description>The latest articles on DEV Community by Emmanuel David (@emman1320).</description>
    <link>https://dev.to/emman1320</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F704465%2F04f43908-89f4-4d57-b3c0-573a30ff3433.png</url>
      <title>DEV Community: Emmanuel David</title>
      <link>https://dev.to/emman1320</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/emman1320"/>
    <language>en</language>
    <item>
      <title>Convert your Excel file to a Javascript object (Using React) - without storing the static file in your database!</title>
      <dc:creator>Emmanuel David</dc:creator>
      <pubDate>Tue, 14 Sep 2021 11:17:32 +0000</pubDate>
      <link>https://dev.to/emman1320/convert-your-excel-file-to-a-javascript-object-using-react-without-storing-the-static-file-in-your-database-24jk</link>
      <guid>https://dev.to/emman1320/convert-your-excel-file-to-a-javascript-object-using-react-without-storing-the-static-file-in-your-database-24jk</guid>
      <description>&lt;p&gt;My mom is working in an University and at the end of every semester she used to literally copy the results of hundreds of students from an excel file and mail them individually which costed her a lot of time. As I came to know about the problem I planned to create a mass email sender which would enable them to mail all candidates within a click of a button. I was a facing a few minor challenges with the excel file and that's what made me write this article! So let's discuss how I did that!&lt;/p&gt;

&lt;h1&gt;
  
  
  Create a React App
&lt;/h1&gt;

&lt;p&gt;Write the following command in your terminal to create a React app&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app excel-file-converter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can give any name of your choice.&lt;/p&gt;

&lt;p&gt;So let's go!!🚀&lt;/p&gt;

&lt;h1&gt;
  
  
  Workspace Setup
&lt;/h1&gt;

&lt;p&gt;We will be using &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt; for this demo and my workspace looks like this&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bmu2z0tj1tfwald9l1c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bmu2z0tj1tfwald9l1c.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I've created two component files: &lt;code&gt;UploadFile.js&lt;/code&gt; for uploading our file and &lt;code&gt;DisplayData.js&lt;/code&gt; for displaying the recieved data. I've also created some CSS files for them respectively.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Uploading the Excel file
&lt;/h2&gt;

&lt;p&gt;First we have to upload our file and we can do this either by dragging the file and dropping it in our app or by opening your files through our app, anyway we will be doing both the ways.&lt;/p&gt;

&lt;p&gt;Inside &lt;code&gt;UploadFile.js&lt;/code&gt; we are defining three functions to handle and extract the data&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;fileDropHandler&lt;/code&gt; =&amp;gt; triggered by &lt;code&gt;onDrop&lt;/code&gt; event&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fileDragOverHandler&lt;/code&gt; =&amp;gt; triggered by &lt;code&gt;onDragOver&lt;/code&gt; event&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;uploadFileHandler&lt;/code&gt; =&amp;gt; triggered by &lt;code&gt;onChange&lt;/code&gt; event from input field&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Dragging and dropping our files
&lt;/h3&gt;

&lt;p&gt;First, dragging and dropping the file triggers some default events &lt;br&gt;
which we don't need so we are preventing them first&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fileDragOverHandler = (event) =&amp;gt; {
    event.preventDefault();
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While dropping the files, the excel file is uploaded in binary format and we can extract it from the &lt;code&gt;event&lt;/code&gt; object by &lt;code&gt;event.dataTransfer.files[0]&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fileDropHandler = (event) =&amp;gt; {
    event.preventDefault();
    const file = event.dataTransfer.files[0];
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Opening the file through our app
&lt;/h3&gt;

&lt;p&gt;This is similar to the fileDropHandler as we extract the binary data from the event object by &lt;code&gt;event.target.files[0]&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const uploadFileHandler = (event) =&amp;gt; {
    const file = event.target.files[0];
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Processing the uploaded file
&lt;/h2&gt;

&lt;p&gt;Now we will be needing a package to handle the data we got now.&lt;br&gt;
I found a few but none of them were accepting data like this as they expect us to show the excel file location but it makes things complicated as we will have to store the static file using services like AWS.&lt;br&gt;
So I took the code from the npm package &lt;a href="https://www.npmjs.com/package/convert-excel-to-json" rel="noopener noreferrer"&gt;excelToJson&lt;/a&gt; github repository and found that it is taking the excel file from the given location and processing the binary data. But we already have that binary data! So all we need to do is to directly feed the data to the code rather than mentioning the file location. So I modified last few lines which was not super hard to do.&lt;br&gt;
You can visit their repository &lt;a href="https://github.com/DiegoZoracKy/convert-excel-to-json/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's the modified code which I stored in a file named &lt;code&gt;excelToJson.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const XLSX = require("xlsx");
const extend = require("node.extend");

const excelToJson = (function () {
  let _config = {};

  const getCellRow = (cell) =&amp;gt; Number(cell.replace(/[A-z]/gi, ""));
  const getCellColumn = (cell) =&amp;gt; cell.replace(/[0-9]/g, "").toUpperCase();
  const getRangeBegin = (cell) =&amp;gt; cell.match(/^[^:]*/)[0];
  const getRangeEnd = (cell) =&amp;gt; cell.match(/[^:]*$/)[0];
  function getSheetCellValue(sheetCell) {
    if (!sheetCell) {
      return undefined;
    }
    if (sheetCell.t === "z" &amp;amp;&amp;amp; _config.sheetStubs) {
      return null;
    }
    return sheetCell.t === "n" || sheetCell.t === "d"
      ? sheetCell.v
      : (sheetCell.w &amp;amp;&amp;amp; sheetCell.w.trim &amp;amp;&amp;amp; sheetCell.w.trim()) || sheetCell.w;
  }

  const parseSheet = (sheetData, workbook) =&amp;gt; {
    const sheetName =
      sheetData.constructor === String ? sheetData : sheetData.name;
    const sheet = workbook.Sheets[sheetName];
    const columnToKey = sheetData.columnToKey || _config.columnToKey;
    const range = sheetData.range || _config.range;
    const headerRows =
      (sheetData.header &amp;amp;&amp;amp; sheetData.header.rows) ||
      (_config.header &amp;amp;&amp;amp; _config.header.rows);
    const headerRowToKeys =
      (sheetData.header &amp;amp;&amp;amp; sheetData.header.rowToKeys) ||
      (_config.header &amp;amp;&amp;amp; _config.header.rowToKeys);

    let strictRangeColumns;
    let strictRangeRows;
    if (range) {
      strictRangeColumns = {
        from: getCellColumn(getRangeBegin(range)),
        to: getCellColumn(getRangeEnd(range)),
      };

      strictRangeRows = {
        from: getCellRow(getRangeBegin(range)),
        to: getCellRow(getRangeEnd(range)),
      };
    }

    let rows = [];
    for (let cell in sheet) {
      // !ref is not a data to be retrieved || this cell doesn't have a value
      if (
        cell === "!ref" ||
        (sheet[cell].v === undefined &amp;amp;&amp;amp;
          !(_config.sheetStubs &amp;amp;&amp;amp; sheet[cell].t === "z"))
      ) {
        continue;
      }

      const row = getCellRow(cell);
      const column = getCellColumn(cell);

      // Is a Header row
      if (headerRows &amp;amp;&amp;amp; row &amp;lt;= headerRows) {
        continue;
      }

      // This column is not _configured to be retrieved
      if (columnToKey &amp;amp;&amp;amp; !(columnToKey[column] || columnToKey["*"])) {
        continue;
      }

      // This cell is out of the _configured range
      if (
        strictRangeColumns &amp;amp;&amp;amp;
        strictRangeRows &amp;amp;&amp;amp;
        (column &amp;lt; strictRangeColumns.from ||
          column &amp;gt; strictRangeColumns.to ||
          row &amp;lt; strictRangeRows.from ||
          row &amp;gt; strictRangeRows.to)
      ) {
        continue;
      }

      const rowData = (rows[row] = rows[row] || {});
      let columnData =
        columnToKey &amp;amp;&amp;amp; (columnToKey[column] || columnToKey["*"])
          ? columnToKey[column] || columnToKey["*"]
          : headerRowToKeys
          ? `{{${column}${headerRowToKeys}}}`
          : column;

      let dataVariables = columnData.match(/{{([^}}]+)}}/g);
      if (dataVariables) {
        dataVariables.forEach((dataVariable) =&amp;gt; {
          let dataVariableRef = dataVariable.replace(/[\{\}]*/gi, "");
          let variableValue;
          switch (dataVariableRef) {
            case "columnHeader":
              dataVariableRef = headerRows
                ? `${column}${headerRows}`
                : `${column + 1}`;
            // break;
            default:
              variableValue = getSheetCellValue(sheet[dataVariableRef]);
          }
          columnData = columnData.replace(dataVariable, variableValue);
        });
      }

      if (columnData === "") {
        continue;
      }

      rowData[columnData] = getSheetCellValue(sheet[cell]);

      if (sheetData.appendData) {
        extend(true, rowData, sheetData.appendData);
      }
    }

    // removing first row i.e. 0th rows because first cell itself starts from A1
    rows.shift();

    // Cleaning empty if required
    if (!_config.includeEmptyLines) {
      rows = rows.filter((v) =&amp;gt; v !== null &amp;amp;&amp;amp; v !== undefined);
    }

    return rows;
  };

  const convertExcelToJson = function (config = {}) {
    _config = config.constructor === String ? JSON.parse(config) : config;

    // ignoring empty lines by default
    _config.includeEmptyLines = _config.includeEmptyLines || false;

    // source has to be defined and should have a value
    if (!(_config.source)) {
      throw new Error(":: 'source' required for _config :: ");
    }

    let workbook = XLSX.read(_config.source, {
      type: "array",
    });

    let sheetsToGet =
      _config.sheets &amp;amp;&amp;amp; _config.sheets.constructor === Array
        ? _config.sheets
        : Object.keys(workbook.Sheets).slice(
            0,
            (_config &amp;amp;&amp;amp; _config.sheets &amp;amp;&amp;amp; _config.sheets.numberOfSheetsToGet) ||
              undefined
          );

    let parsedData = {};
    sheetsToGet.forEach((sheet) =&amp;gt; {
      sheet =
        sheet.constructor === String
          ? {
              name: sheet,
            }
          : sheet;

      parsedData[sheet.name] = parseSheet(sheet, workbook);
    });

    return parsedData;
  };

  return convertExcelToJson;
})();

export default excelToJson;

//The MIT License (MIT)
// Copyright (c) 2015 INFOinvest http://infoinvest.com.br

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will be needing two dependencies to run the code&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;xlsx&lt;/li&gt;
&lt;li&gt;node.extend&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Write the following command to install them&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install xlsx node.extend
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are ready to process the data we recieved.&lt;br&gt;
I'm creating a function called &lt;code&gt;convertExcelToObject&lt;/code&gt; for converting the binary data to &lt;code&gt;Uint8Array&lt;/code&gt; which our package uses to convert the data to a javascript object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const convertExcelToObject = (file) =&amp;gt; {
    const reader = new FileReader();
    reader.onload = function (event) {
      const data = new Uint8Array(event.target.result);
      let result = excelToJson({ source: data });
      props.onUploadExcelFile(result.Sheet1);
    };
    reader.readAsArrayBuffer(file);
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this function we are converting the file to &lt;code&gt;Uint8Array&lt;/code&gt; type and passing it into the &lt;code&gt;excelToJson&lt;/code&gt; function that we exported from &lt;code&gt;excelToJson.js&lt;/code&gt;. The result is lifted up to our parent component &lt;code&gt;App.js&lt;/code&gt; so that we can display the given data.&lt;/p&gt;

&lt;p&gt;The object looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  Sheet1: [
      {
        A: 'data of cell A1',
        B: 'data of cell B1',
        C: 'data of cell C1'
      },
      {
        A: 'data of cell A2',
        B: 'data of cell B2',
        C: 'data of cell C2'
      }
   ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we are passing the file to &lt;code&gt;convertExcelToObject&lt;/code&gt; through our functions we defined earlier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const dropHandler = (event) =&amp;gt; {
    event.preventDefault();
    const file = event.dataTransfer.files[0];
    convertExcelToObject(file);
  };

  const uploadFileHandler = (event) =&amp;gt; {
    const file = event.target.files[0];
    convertExcelToObject(file);
  };

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So finally our &lt;code&gt;UploadFile.js&lt;/code&gt; looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "./UploadFile.css";
import excelToJson from "./excelToJson";

const UploadFile = (props) =&amp;gt; {
  const convertExcelToObject = (file) =&amp;gt; {
    const reader = new FileReader();
    reader.onload = function (event) {
      const data = new Uint8Array(event.target.result);
      let result = excelToJson({ source: data });
      props.onUploadExcelFile(result.Sheet1);
    };
    reader.readAsArrayBuffer(file);
  };
  const dropHandler = (event) =&amp;gt; {
    event.preventDefault();
    const file = event.dataTransfer.files[0];
    convertExcelToObject(file);
  };

  const uploadFileHandler = (event) =&amp;gt; {
    const file = event.target.files[0];
    convertExcelToObject(file);
  };

  const dragOverHandler = (event) =&amp;gt; {
    event.preventDefault();
  };

  return (
    &amp;lt;div className="uploadFile"&amp;gt;
      &amp;lt;label&amp;gt;Upload your Excel file:&amp;lt;/label&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;label onDrop={dropHandler} onDragOver={dragOverHandler} htmlFor="file"&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;input
              onChange={uploadFileHandler}
              id="file"
              type="file"
              accept=".xlsx, .xls, .csv"
            /&amp;gt;
            &amp;lt;div&amp;gt;or drop excel files here&amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/label&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default UploadFile;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;UploadFile.css&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.uploadFile &amp;gt; label {
  font-size: 1.4em;
}

.uploadFile &amp;gt; div {
  background-color: rgb(0, 211, 148);
  height: 11em;
  margin-top: 1em;
}

.uploadFile &amp;gt; div &amp;gt; label {
  border: 2px solid black;
  height: 98%;
  cursor: pointer;
  border-style: dashed;
  display: flex;
  justify-content: center;
}

.uploadFile &amp;gt; div &amp;gt; label &amp;gt; div {
  display: flex;
  justify-content: center;
  flex-direction: column;
}

.uploadFile input {
  margin-top: 1em;
  width: 13.2em;
}

.uploadFile input + div {
  text-align: center;
  margin-top: 0.6em;
  margin-bottom: 7px;
}

.uploadFile input::file-selector-button {
  width: 11em;
  height: 2.5em;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  color: rgb(51, 51, 51);
  background-color: white;
  cursor: pointer;
  font-weight: 600;
  text-transform: uppercase;
}

.uploadFile input::file-selector-button:hover {
  background-color: rgb(235, 235, 235);
  transition: all 0.1s ease-in-out;
}

.uploadFile input::file-selector-button:active {
  background-color: rgb(214, 214, 214);
  transition: all 0.2s ease-in-out;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And our upload part looks like:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62ks1xjbfnugjf8y89bl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62ks1xjbfnugjf8y89bl.png" alt="image"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Pretty cool right!!😉&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: Storing and Displaying the data:
&lt;/h2&gt;

&lt;p&gt;Now let's go to our &lt;code&gt;App.js&lt;/code&gt; file which looks like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";
import "./App.css";
import DisplayData from "./DisplayData";
import UploadFile from "./UploadFile";

function App() {
  const [uploadedExcelData, setUploadedExcelData] = useState([]);
  const uploadedExcelDataHandler = (data) =&amp;gt; {
    setUploadedExcelData(data);
  };
  return (
    &amp;lt;div className="container"&amp;gt;
      &amp;lt;UploadFile onUploadExcelFile={uploadedExcelDataHandler} /&amp;gt;
      &amp;lt;DisplayData excelData={uploadedExcelData} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;App.css&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  padding: 1.5em 3em;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are receiving the data we lifted in &lt;code&gt;UploadFile.js&lt;/code&gt; and storing it in a state and passing the data to the &lt;code&gt;DisplayData.js&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Inside first we have to make sure it doesn't if it finds no data to display by adding this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (!props.excelData.length) {
    return &amp;lt;div className="noFileContainer"&amp;gt;No File Uploaded&amp;lt;/div&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally we are using the data we recieved and displaying the data we got in a table:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DisplayData.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "./DisplayData.css";

const DisplayData = (props) =&amp;gt; {
  if (!props.excelData.length) {
    return &amp;lt;div className="noFileContainer"&amp;gt;No File Uploaded&amp;lt;/div&amp;gt;;
  }
  const table = props.excelData;
  const tableBody = table?.slice(1);
  const tableHead = table[0];
  const keys = Object.keys(tableHead);

  return (
    &amp;lt;div className="displayData"&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;thead&amp;gt;
          &amp;lt;tr&amp;gt;
            {keys.map((key) =&amp;gt; (
              &amp;lt;th&amp;gt;{tableHead[key]}&amp;lt;/th&amp;gt;
            ))}
          &amp;lt;/tr&amp;gt;
        &amp;lt;/thead&amp;gt;
        &amp;lt;tbody&amp;gt;
          {tableBody.map((row) =&amp;gt; (
            &amp;lt;tr&amp;gt;
              {keys.map((key) =&amp;gt; (
                &amp;lt;td&amp;gt;{row[key]}&amp;lt;/td&amp;gt;
              ))}
            &amp;lt;/tr&amp;gt;
          ))}
        &amp;lt;/tbody&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default DisplayData;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;DisplayData.css&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.displayData {
  margin-top: 2em;
  display: flex;
  justify-content: center;
}

.displayData thead th {
  text-align: left;
  transition: all 0.2s ease-in-out;
}

.displayData table {
  background-color: white;
  width: 100%;
  padding-top: 1em;
  border-spacing: 1px;
  border-collapse: collapse;
}

.displayData td,
.displayData th {
  border: 0.5px solid rgb(0, 0, 0);
  padding: 8px;
}

.displayData tr:nth-child(even) {
  background-color: #f2f2f2;
}

.displayData th {
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  background-color: rgb(0, 211, 148);
  color: white;
}

.noFileContainer {
  text-align: center;
  margin-top: 2em;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it!!&lt;/p&gt;

&lt;p&gt;I've created a excel file Test.xlsx to test our app which contains the following table:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx47xxsteavyw0hkuq4h4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx47xxsteavyw0hkuq4h4.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Initially our app looks like this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdxjrrgjq4n5rftv9ivdy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdxjrrgjq4n5rftv9ivdy.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now I can drag and drop our file or else I can open the file through our app. After uploading our Test.xlsx:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F347y1uedd1gv7okyv6f9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F347y1uedd1gv7okyv6f9.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So that's it!! We did it!!🥳 &lt;br&gt;
I know I didn't go in depth since I wanted this to be crisp and short, not confusing.&lt;br&gt;&lt;br&gt;
I hope you learnt how to handle excel files using React. This is my first post, so suggestions are most welcomed 🙏.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
