question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I access a row?

See original GitHub issue

I have:

var xls = require('xlsjs');
var workbook = xls.readFile('lp.xls');
var sheet_name_list = workbook.SheetNames;
var sheet = workbook.Sheets[sheet_name_list[0]];

I need a function that lets me iterate over each row, as in:

sheet.rows.forEach(function(row) {
   //do something with row.
})

Is this possible?

By the way, my file doesn’t have a proper column with header format so I can’t use the function in utils.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
SheetJSDevcommented, May 27, 2014

@arg20 to answer your question:

var xls = require('xlsjs');
var workbook = xls.readFile('lp.xls');
var sheet_name_list = workbook.SheetNames;
var sheet = workbook.Sheets[sheet_name_list[0]];
var data = xls.utils.sheet_to_json(sheet, {header:1}); // <-- this is an array of arrays that you can use

Also, feel free to delete your older comment

1reaction
SheetJSDevcommented, May 27, 2014

@arg20 @notatestuser I played with it a bit and settled on the following options:

  • opts.header = 1 generates an array of arrays
  • opts.header = ‘A’ generates a structure using the column headers as keys
  • opts.header = [‘header1’, ‘header2’, …] will use the specified labels

(default behavior remains: use the first row)

As for controlling the row @notatestuser there is a range option:

  • opts.range = n starts from row n (0-indexed), so in your case it would be range=2
  • opts.range = range_as_string will use specified range (standard A1:B2 format)
  • opts.range = range_object will use the specified range (standard format {s:{r:0,c:0},e:{r:1,c:1}})

(default is to use the entire sheet)

I also updated the XLS tests: https://github.com/SheetJS/js-xls/blob/2bd2d1eaf3cbcfe317dd7c9c03ca355fb2c22afd/test.js#L487-L586

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Access a Row in a DataFrame (using Pandas)
How to Access a Row in a DataFrame · First, we check for all rows where the Name column is Benjamin Duran ·...
Read more >
Dealing with Rows and Columns in Pandas DataFrame
In Order to select a column in Pandas DataFrame, we can either access the columns by calling them by their columns name.
Read more >
Accessing pandas dataframe columns, rows, and cells
In this lesson, you will learn how to access rows, columns, cells, and subsets of rows and columns from a pandas dataframe. Let's...
Read more >
Indexing and selecting data — pandas 1.5.2 documentation
You may access an index on a Series or column on a DataFrame directly as an attribute: ... You can also assign a...
Read more >
How to access a group of rows in a Pandas DataFrame?
To access a group of rows in a Pandas DataFrame, we can use the loc() method. For example, if we use df.loc[2:5], then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found