protobi / js-xlsx

XLSX / XLSM / XLSB (Excel 2007+ Spreadsheet) / ODS parser and writer
http://oss.sheetjs.com/js-xlsx
Other
833 stars 416 forks source link

How to set complex Multistage header? #116

Closed BlackSkyJY closed 6 years ago

BlackSkyJY commented 6 years ago

such as this picture image I try to use ws['!merges'], but this is to difficult to implement it

pietersv commented 6 years ago

@BlackSkyJY

I see the !merges is undocumented. For each merge range you create an entry in the array specifying the upper left ("s") and lower right ("e") of the merged range. See example-style.js

So I think you'd have four entries like so. I haven't executed this so may require fiddling...

[
     { s: { c:0, r:0}, e: {c:1, r:0} },  //cellA
     { s: { c:0, r:2}, e: {c:1, r:4} },  //cellB
     { s: { c:2, r:1}, e: {c:3, r:1} },  //cellBa
     { s: { c:4, r:1}, e: {c:4, r:2} },  //cellBa
]

snippet from example-style.js


workbook = {
  "SheetNames": [
    "Main"
  ],
  "Sheets": {
    "Main": {
      "!merges": [
        {
          "s": {
            "c": 0,
            "r": 0
          },
          "e": {
            "c": 2,
            "r": 0
          }
        }
      ],
      "A1": {
        "v": "This is a submerged cell"
      }
  }
}
BlackSkyJY commented 6 years ago

in fact, If it's a custom header, it's difficult to make merges data formats, The watch head is not fixed