DiegoZoracKy / convert-excel-to-json

Convert Excel to JSON, mapping sheet columns to object keys.
MIT License
289 stars 92 forks source link

Define option to sheets based on sheet index #25

Open khanisak opened 5 years ago

khanisak commented 5 years ago

Can we give an option for sheet based on index not name? So I want to give an option to second sheet or third sheet whatever the sheet name is.

DiegoZoracKy commented 5 years ago

This is a good idea. I have to check on the xlsx (the module being used under the hood to get the data from a spreadsheet) to see if it has an option for that. Currently it returns me all the sheets as an object literal where the keys are the names of the sheets.

gerhardx commented 5 years ago

For anyone interest in doing something index sheet based. An easy implementation would be:

jsonObj: result from excel converter i: variable to access sheet page

  1. Keymap sheets names with var index = Object.keys(jsonObj)
  2. Access the sheet with your data object like: jsonObj[index[i]]

@DiegoZoracKy If you think this would be a good option, I can help to create a pull request.

DiegoZoracKy commented 5 years ago

Hi @gerhardx, this is a good idea, however the property order of a Object Literal is not guaranteed. So your code access by index the result of Object.keys which cannot be guaranteed to be the exactly order of the sheets on source file.

y0x commented 4 years ago

@DiegoZoracKy I think this would be a quite useful feature. Will you implement it?

DiegoZoracKy commented 4 years ago

Hi @y0x, yes it would be possible to be implemented, however, unfortunately I don't have time to code that at the moment. If you, @gerhardx or someone else would be interested in to work on it I can provide you further guidance on this task. We would need to have a new config option named sheetsIndex, and then use it at this flow of the code:

https://github.com/DiegoZoracKy/convert-excel-to-json/blob/a716b606426e7a67317b3ef5f92e1ddf4eb2f686/lib/convert-excel-to-json.js#L138