I am writing Protractor e2e testing .I need to Dynamically read the values from Excel .Can anyone help me out from this..
Asked
Active
Viewed 337 times
-1
-
4possible duplicate of [How to read/write from/to an excel using NodeJS - Protractor?](http://stackoverflow.com/questions/26616522/how-to-read-write-from-to-an-excel-using-nodejs-protractor) – alecxe Sep 16 '15 at 16:56
-
1Also do take a look at [xlsjs npm module](https://www.npmjs.com/package/xlsjs). It works well too. – giri-sh Sep 16 '15 at 17:47
1 Answers
0
Inititally add xlsjs to node, and then try this code
var sheetNumber = 0;
//Define file Path name
var path = require('path');
var fileNamePath = path.resolve(__dirname, 'E:/excel.xls');
//NodeJs read file
var XLS;
if (typeof require !== 'undefined') {
XLS = require('E:/node/node_modules/xlsjs');
}
//Working with workbook
var workbook = XLS.readFile(fileNamePath);
var sheetNamelist = workbook.SheetNames;
var value = workbook.Sheets[sheetNamelist[sheetNumber]][cellId].v;
In the above sheet number means, in the Excel sheet your data is located in which sheet and cellId is in that sheet which shell data do you want. your data was stored in the variable value, you can use that data in any type.

rajana sekhar
- 511
- 5
- 21
-
From this i could read the values. But i want to save the same value in "Grid"(ag-grid).. i could locate the cell value in grid. How should i send the value which is read from excel?? – Noor Sep 27 '15 at 15:11
-
-
Thanks for your input. Its working for me.But if my excel has no value in any of the column, getting error like "undefined" . How should i address that – Noor Oct 06 '15 at 17:12
-
-
as normal sendkeys, select locator then send keys into search field – rajana sekhar Oct 09 '15 at 04:56
-
Yes.. i did like that only.. But when excel has values , it accepting . If some of the column of excel does not have value mean,It showing error like 'undefined' is not a function... – Noor Oct 09 '15 at 17:42
-
-
write a condition, if not equal to null run the logic, otherwise go to next column value, – rajana sekhar Oct 10 '15 at 07:06