본문 바로가기

Javascript

javascript xlsx ecxel 모든 cell에 style 적용

주석을 봐주세요...


 for (const i in ws) { // 모든 cell을 돌겠다
   if (typeof (ws[i]) !== 'object') continue; // object가 아니면 style 적용 안됨
      ws[i].s = { // 모든 cell 에 style을 적용
        alignment: {
          horizontal: 'center',
        },
        border: {
          right: {
            style: 'thin',
            color: '000000',
          },
          left: {
            style: 'thin',
            color: '000000',
          },
          top: {
            style: 'thin',
            color: '000000',
          },
          bottom: {
            style: 'thin',
            color: '000000',
          },
        },
    }

여기서 i는 number가 아니라 string이다. 왜냐면 cell의 이름을 나타내기 때문이다. ex) A1, A2, B13