Read Excel data in Playwright



Read Excel data in Playwright

import {expect, Page, Browser, test} from ‘@playwright/test’;
import { readFile, utils, read as _read } from ‘xlsx’;
const xlsx = require(‘xlsx’);
//const path=”C:\\Users\\Anand.Gummadilli\\Documents\\Anand_Details\\PlaywrightDemo\\PlaywrightDemo-1\\tests2\\Anvesh.xlsx”;
const path=”C:\\Users\\anand\\OneDrive\\Documents\\PlaywrightDemo\\PlaywrightDemo\\tests2\\Anvesh.xlsx”;
const workbook = xlsx.read(path);
//const worksheet = workbook.Sheets[‘Sheet1’];
const worksheet = workbook.Sheets[workbook.SheetNames[0]];
const data = xlsx.utils.sheet_to_json(worksheet);
test(‘Read Excel’, async()=>{
   const lastCellName = xlsx.utils.encode_cell({ r:1,c:1})
   console.log(lastCellName);
   console.log(xlsx.utils.encode_range({ r:1,c:1}));
});
test(‘Read Excel with utils’, async()=>{
    console.log(workbook.SheetNames);
    //const data = xlsx.utils.sheet_to_json(worksheet);
    //console.log(data);
    console.log(Object.keys(data[0]));
    console.log(data[0].Name);
    console.log(data[0].Age);
});
Tags:
Leave a comment

Your email address will not be published. Required fields are marked *

Subscribe now

Receive weekly newsletter with educational materials, new courses, most popular posts, popular books and much more!