What is the best way to access an excel file using JavaScript and Protractor?

Is it possible to read an Excel file dynamically in JavaScript and iterate through cell values using row and column counts, without converting it into a JSON object? I have searched through several posts on Stack Overflow but have not found a solution yet. Any suggestions would be greatly appreciated.

Thank you.

Answer №1

If you're looking for a perfect npm package that fits your needs, I recommend checking out the xlsx package. I have personally used it and can provide code examples if needed.

For instance, here's a simple example of how to parse an xlsx file: This code reads the value of cell 'B1' from the first sheet of the file test.xlsx

'use strict';
var XLSX = require('xlsx');
var workbook = XLSX.readFile('test.xlsx');
var sheetName = workbook.SheetNames[0];
var worksheet = workbook.Sheets[sheetName];
var redValue = worksheet['B1'];
console.log(redValue); 

Answer №2

After some research, I discovered a solution for parsing Excel files using the 'kexcel' npm package. This package has been helpful in my tasks so far. However, I have encountered an issue - I need to find out how to retrieve the last row number from an Excel file using this package.

Answer №3

If you want to access data from an excel file, there are two methods to do so.

The first method involves using the xlsx package. To begin, navigate to your project folder and run the command 'npm i xlsx' in the terminal to install the necessary packages.

var XLSX = require('xlsx');
var UserCred = XLSX.readFile('ExcelFile/UserLogin.xlsx');
var UserLoginWorksheet= UserCred.Sheets['Sheet1'];
var BaseUrl=UserLoginWorksheet['B1'].v;
console.log(BaseUrl);

In this code snippet, 'BaseUrl' stores the value located at column B1 in the excel file.

The second method utilizes the exceljs package. Similarly, go to your project folder and run 'npm i excel' in the terminal to install the required packages.

var Excel = require("exceljs");
 var filePath = 'ExcelFiles/StaffDetails.xlsx';
 var workbook = new Excel.Workbook();
 await workbook.xlsx.readFile(filePath).then(function () {
 worksheet = workbook.getWorksheet("Sheet1"); //Use sheetName in getWorksheet function
 let cellValue1 = worksheet.getRow(1).getCell(1).value;
 console.log(cellValue1+"4");
 })
let  cellValue2 = worksheet.getRow(2).getCell(2).value;

Here, cellvalue1 represents the value of cell A1, while cellvalue2 represents the value of cell B2 in the excel file.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In React, what is the correct term for "selection boxes" when choosing multiple items in Finder?

I'm in search of a React component that allows me to select multiple elements on the screen by clicking, holding, and forming a square around them. I've tried searching for terms like 'selection box' and 'React select elements,&apo ...

What is the best way to retrieve parameters from a URI using AngularJS?

I'm brand new to Angular, so most concepts are unfamiliar to me at this point. Currently, I am working on a page with the following URL: http://domain/araneum/page/show/1 Is there a simple way to extract the '1' from the URL? From what I ...

I encountered a validation error and a 404 error while trying to input data into all fields. Kindly review and check for accuracy. Additionally, I have included an

click here for image description Despite providing all details in the form fields, I keep receiving an error message prompting me to enter all fields... I am also encountering a "/api/user 404 Not Found" error and unsure of the reason. Interestingly, wh ...

Uploading and cropping multiple images in AngularJS

Currently in search for quality Angularjs code that offers support for multiple image uploads along with cropping capabilities. After extensive searching, I have come across either solutions that excel at multiple image uploading or ones that specialize i ...

Node's Object.prototype function returns an empty object

When I run Object.prototype in the browser console, I see all the properties and methods within it. However, when I do the same thing in the NodeJS terminal, I get an empty object {}. Can someone explain why this difference occurs? Attached are screenshots ...

Exporting a class from an index.ts file may result in a problem where the injected constructor is

Utilizing an index.ts file to manage exports, following the guidelines outlined in the Angular 2 style guide (https://github.com/mgechev/angular2-style-guide/blob/master/old/README.md#directory-structure), has been successful throughout my application deve ...

Having difficulty including a new key-value pair to a JSON object while using another JSON object

Looking to merge key value pairs from one JSON object into another. I've searched through various stackoverflow threads for solutions, but haven't found one that works for my specific scenario. const primaryObject = { name: "John Doe", ag ...

Adding new pages in express.js without increasing the complexity of the routes

I am currently developing a project using Express.js and have been enjoying the experience. While the site is running smoothly, I am now looking for a way to allow users to contribute by adding pages to the site through either a form with set fields or by ...

Tips for integrating new channels and categories using a Discord bot

Hey there! I'm trying to add channels and categories, but I can't seem to get the function ".createChannel" working. The console keeps telling me that the function doesn't exist. I've been referencing the documentation at https://discor ...

Is it possible to extract tooltip text from a website using Python and Selenium, specifically when the text is generated by JavaScript?

Can anyone help me retrieve the tooltip text that appears when I hover over the time indicating how long ago a game was played? You can find my summoner profile here. I have noticed that the tooltip text is not visible in the HTML code and suspect it may ...

What is the process for reducing the value displayed on the label?

I have three labels and I would like to subtract the value of two labels and place the result in the third label. $(document).ready(function() { //Retrieve the values from both labels var value1 = document.getElementById("addition").innerText; ...

Angular's ui-grid column menu functionality allows users to easily customize

Issue with Angular ui-grid column menu position in Chrome and Firefox was observed when using version 4.0.4. You can reproduce this problem by following the steps outlined in the tutorial: RTL Support ...

Using jQuery to target nested HTML elements is a great way to efficiently manipulate

Within the code below, I have a complex HTML structure that is simplified: <div id="firstdiv" class="container"> <ul> <li id="4"> <a title="ID:4">Tree</a> <ul> <li id="005"> ...

The parameters 'event' and 'event' are not compatible with each other

I'm currently working on a page that involves submitting a form: import React from 'react'; import Form from 'react-bootstrap/Form'; import { useSignIn } from '../../hooks/Auth/useSignIn'; import { useHistory } from &apos ...

What is the best way to create a directive that replaces not only the contents of a DIV but also the DIV itself

Below is the directive call that I am currently using: <div data-my-activity></div> This is how the directive looks in my code: app.directive('myActivity', function () { return { restrict: "A", template: "<di ...

Choose from a dropdown menu to either activate or deactivate a user account

I'm new to php and I need help getting this code to function properly delete.php <?php include_once 'dbconfig.php'; if($_POST['del_id']) { $id = $_POST['del_id']; $stmt=$db_con->prepare("UPDATE tbluse ...

Tips for organizing a list of strings into columns within a React Bootstrap Table 2 without overflowing the designated columns

While working on rendering data in tabular form using react-bootstrap-table, I encountered an issue where the data in one column was overlapping with data from other columns. In order to maintain a fixed layout, I added the CSS layout:fixed, which was a ne ...

Encountering a "variable not found" error when trying to run the JavaScript code to manipulate the web element

Upon executing the command to change the value of a web element text, I encountered an error stating "Can't find variable: e." sel=webdriver.PhantomJS() sel.get=('http://stackoverflow.com/questions?pagesize=50&sort=newest') elements=sel ...

Adding properties to Vue.js component in the script section without affecting rendering

How can I import component A with props and pass it to another component B for rendering? import MyComponent from '/MyComponent.vue' computed: { compnt: function () { var comp = MyComponent // How can I set props to MyC ...

Saving a revised JSON file using AngularJS

Currently, I am in the process of developing a phonegap application using AngularJS that relies on a .json file to store an array of entries. The main goal I am aiming for is to enable users to mark specific entries as favorites and then utilize that data ...