Akhilesh
Akhilesh

Reputation: 55

How to read specific from and to rows in sheetjs

I am using https://github.com/sheetjs/sheetjs . Here I want read specific from and to rows ,. So suppose I want to read 10000 to 20000 rows record.

var workbook = XLSX.readFile('test.xlsx', { sheetRows: 10 });

The above script only allow me to set to rows limit but I also want to set from limit too

Upvotes: 1

Views: 8522

Answers (1)

Tanmay Patil
Tanmay Patil

Reputation: 699

const X = require('xlsx');
const fileName = './add.xlsx';
const workbook = X.readFile(fileName);
var sheet_name_list = workbook.SheetNames;
console.log(sheet_name_list);

/*****  orig data ******
   (A)     (B)     (C)
   num1   num2     val
(2) 1       1        2
(3) 2       2        4
(4) 3       3        6
(5) 4       4        8
***********************/

let sheet = '1_ADD';
let ws = workbook.Sheets[sheet];
ws['!ref'] = "A2:C3" // change the sheet range to A2:C3
// expecting only first 2 rows 
const data_1 = X.utils.sheet_to_json( ws,{header:1});
console.dir(data_1, {depths: null , colors : true});

We can give specific range of cells to select which can be used for specific row selection.

Upvotes: 4

Related Questions