Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* added worksheet title when processing multi tab sheet #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function cellIsValid(cell) {
}

// google spreadsheet cells into json
exports.cellsToJson = function(allCells, options) {
exports.cellsToJson = function(allCells, options , title) {

// setting up some options, such as defining if the data is horizontal or vertical
options = options || {}
Expand Down Expand Up @@ -314,8 +314,9 @@ exports.cellsToJson = function(allCells, options) {

}
})

return finalList
var sheetFinal = {}
sheetFinal[title] = finalList
return sheetFinal
}

exports.getWorksheets = function(options) {
Expand Down Expand Up @@ -349,7 +350,7 @@ exports.spreadsheetToJson = function(options) {

var allWorksheets = !!options.allWorksheets
var expectMultipleWorksheets = allWorksheets || Array.isArray(options.worksheet)

var worksheetTitles = []
return exports.getWorksheets(options)
.then(function(worksheets) {

Expand All @@ -372,13 +373,14 @@ exports.spreadsheetToJson = function(options) {
})
.then(function(worksheets) {
return Promise.all(worksheets.map(function(worksheet) {
worksheetTitles.push(worksheet.title)
return worksheet.getCellsAsync()
}))
})
.then(function(results) {

var finalList = results.map(function(allCells) {
return exports.cellsToJson(allCells, options)
var finalList = results.map(function(allCells , index) {
return exports.cellsToJson(allCells, options , worksheetTitles[index])
})

return expectMultipleWorksheets ? finalList : finalList[0]
Expand Down