如何制作两层标题?

时间:2019-06-19 11:05:16

标签: sheetjs

我有一个简单的Web应用程序,可以使用SheetJS从XML生成Excel文件。

这有效:

代码:

data.push({
  "Car Make": car.make,
  "Car Model": car.model,
  "Engine Type": car.engine.type,
  "Engine HP": car.engine.hp
});

var wb = XSLX.utils.book_new();
filename = "Workbook"
wb.Props = {
  Title: filename,
  Subject: "",
  Author: ""
};

wb.sheetNames.push("Cars and Engines");
wb.Sheets["Cars and Engines"] = XLSX.utils.json_to_sheet(data);

输出:

Car Make | Car Model | Engine Type | Engine HP
---------+-----------+-------------+-----------
Ford     | F150      | V8          | 290
Dodge    | Viper     | V10         | 645

但这不起作用:

代码:

data.push({
  "Car":{
    "Make":car.make,
    "Model":car.model
  },
  "Engine":{
    "Type":engine.type,
    "HP":engine.hp
  }
});

输出:

Car | Engine
----+-------
    |
    |

这就是我想要的:

     Car      |   Engine     <--.
 Make | Model | Type | HP    <---'- Two Headers
------+-------+------+-----
Ford  | F150  | V8   | 290
Dodge | Viper | V10  | 645

是否可以通过SheetJS来做到这一点?

0 个答案:

没有答案