0

I'm trying to get the data from Object using object.variable format not object.property format which is right and default one. I'm doing Excel export and import. I need to do styling the first row(header) and it increments like A1, B1, C1, D1 ... and so on as you know.

so I've made this function.

function export() {

let ws = XLSX.utils.json_to_sheet(data) // object: {A1: {v: 'please'}, B1: {v: 'help'} ... }

for(let i=65; i<this.data.length + 65; i++) {
let alphabets = String.fromCharCode(i)
let cells = alphabets+1

this.style(ws.cells) //doesn't work

   }
...
}

I'm guessing getting data by using this weird object.variable format wouldn't work at all, but I really need to do this.... otherwise I have to code everything one by one.. and all styles in 23 pages are different so it will be such pain in the ass for me....

please help!

Chawchawchaw
  • 203
  • 1
  • 4
  • 13
  • It would be `this.style(ws[cells]);`. But I don't understand what function `this.style` is supposed to do. – Adder May 18 '20 at 09:14
  • @Adder it's for styling function that I didn't add. I'm using xlsx, xlsx-style for styling only so separated both library to read more clearly. it's style(cell) { const cellStyle={fill: {fgColor: { rgb: 'fff2cdd7'}}} – Chawchawchaw May 18 '20 at 23:57
  • @CBroe Yes it does! Thanks you so much :) – Chawchawchaw May 19 '20 at 00:00

1 Answers1

3

In your case cells is one of 'A1', 'B1', 'C1' etc.

What you can do with JavaScript Objects is

object['property']

so please try

this.style(ws[cells])
Nico Gräf
  • 236
  • 1
  • 8