convert-excel-to-json icon indicating copy to clipboard operation
convert-excel-to-json copied to clipboard

Define option to sheets based on sheet index

Open khanisak opened this issue 6 years ago • 5 comments

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.

khanisak avatar Jan 29 '19 04:01 khanisak

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.

DiegoZoracKy avatar Jan 30 '19 12:01 DiegoZoracKy

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.

gerhardx avatar Oct 28 '19 17:10 gerhardx

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.

DiegoZoracKy avatar Oct 29 '19 13:10 DiegoZoracKy

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

y0x avatar Feb 27 '20 13:02 y0x

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

DiegoZoracKy avatar Mar 05 '20 00:03 DiegoZoracKy