DiegoZoracKy / convert-excel-to-json

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

could I use the row[0]/header as prop name of object value? #14

Closed thearabbit closed 6 years ago

thearabbit commented 6 years ago

image


[
  {id: , name: , gender: , dob: , time:, amount: ...},
  {id: , name: , gender: , dob: , time:, amount: ...},
  {id: , name: , gender: , dob: , time:, amount: ...},
]
thearabbit commented 6 years ago

I can't use column to key mapping, bc sometime use changed order column.

thearabbit commented 6 years ago

Now work fine

columnToKey: {
          '*': '{{columnHeader}}',
        },

I solved by all column, but I wold like to do any columns

DiegoZoracKy commented 6 years ago

Great! So, is everything ok now? Can we close this issue?

ukankal commented 6 years ago

How do we cleanse header values(like replace space, dots etc in header cells with _'s ) and still do columnToKeycolumnToKey: { '*': '{{columnHeader}}', }

DiegoZoracKy commented 6 years ago

Did you find error while running the module because those characters were written on the header, or do you just want to "clean" the keys found on the result object?

ukankal commented 6 years ago

I am looking to clean the keys present on the resultant object

something like below.

columnToKey: { "*": "{{columnHeader}}".replace(/[\W]/g, "") }

Could u tell how to do it properly? Thanks for your time :)

DiegoZoracKy commented 6 years ago

This module doesn't provide something on this sense. This should be a rule of your application's domain. What you can do is to clean it yourself by looping through all the keys with Object.keys().

On Wed, Aug 29, 2018, 7:24 PM Uday notifications@github.com wrote:

I am looking to clean the keys present on the resultant object

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/DiegoZoracKy/convert-excel-to-json/issues/14#issuecomment-417126747, or mute the thread https://github.com/notifications/unsubscribe-auth/AB_oP1OaYU7k7EA6E_sWvLH65t_U6RAPks5uVxSygaJpZM4WFG4M .

thearabbit commented 6 years ago

Thanks for your reply. How to solve?

DiegoZoracKy commented 6 years ago

Hi @thearabbit, how to solve what?

thearabbit commented 6 years ago

Now I use

columnToKey: {
        A: 'id',
        B: 'firstName'
    }

But don't good for me, when user change order of column name

DiegoZoracKy commented 6 years ago

By using:

columnToKey: {
"*": "{{columnHeader}}"
}

You could get all the keys, following what is written on the header, regardless of their order.

Search for "columnHeader" on the docs to see more about it.

thearabbit commented 6 years ago

I would like specific like this

columnToKey: {
   "ID Column": "id",
   "First Name": "firstName",
   "Other Column": "other"
}
DiegoZoracKy commented 6 years ago

Take a look at the section: "Mapping columns to keys :: Special Variables Cell Variables"

It says:

"A value from a specific cell can be defined as a key name (e.g. { A: '{{A1}}' })..."

This one and the {{columnHeader}} are closest solutions to what you want to achieve.

DiegoZoracKy commented 6 years ago

Any news around here? Could you managed to handle your case with this last suggestion?

thearabbit commented 6 years ago

Thanks, Now I understand about this usage. 👍