xmind-sdk-js icon indicating copy to clipboard operation
xmind-sdk-js copied to clipboard

How to create a workbook with multiple sheets ?

Open mixam85 opened this issue 2 years ago • 1 comments

Hello, I would like to create a workbook with multiple sheets. To do so I called new Topic with workbook.createSheet multiple time with different name. But when I save to a file using Zipper only the latest sheet is visible in Xmind.

Here is my code:

#!/usr/bin/env node
const { Workbook, Topic, Marker, Zipper } = require('xmind');

const [workbook, marker] = [new Workbook(), new Marker()];
const zipper = new Zipper({path: './', workbook, filename: 'MyFirstMap'});

data = require('./test.json')

function add_data(topic, parent_name, node) {
    console.log(parent_name, node)
    new_node = topic.on(topic.cid(parent_name)).add({"title": node.name}).cid()
    if (node.childs) {
        node.childs.forEach(child => add_data(topic, node.name, child))
    }
}

function add_sheet(element) {
    // console.log(element)
    const topic = new Topic({sheet: workbook.createSheet(element.name, element.name)});
    element.childs.forEach(child => add_data(topic, element.name, child))
}

data.forEach(child => add_sheet(child))

zipper.save().then(status => status && console.log('Saved MyFirstMap.xmind'));

Example of test.json

[
  {
    "name": "All",
    "childs": [
      {
        "name": "N/A",
        "childs": [
          {
            "name": "Test-123",
            "childs": []
          }
        ]
      }
    ]
  },
  {
    "name": "Other",
    "childs": [
      {
        "name": "Plop",
        "childs": [
          {
            "name": "Test-456",
            "childs": []
          }
        ]
      }
    ]
  }
]

mixam85 avatar Sep 20 '22 10:09 mixam85

Hi, I am so sorry for the late replying, and also appreciate your quest.

As you wanted, I've released a new patch version v2.2.26 on npmjs.com. I've added a couple of methods to the class of Workbook and now, You can check at workbook or an example of example.fully.js for usage.

Please, let me know if you have any questions

danielsss avatar Sep 23 '22 06:09 danielsss

Thanks a lot, I will test it !

mixam85 avatar Sep 30 '22 13:09 mixam85