跳到主要内容

importFromExcel

Description

将 Excel 文件转换为 JSON

importFromExcel: (config: any) => void

Parameters

  • config - (required) object - 一个具有导入文件配置属性的对象

Example

gantt.importFromExcel({
server:"https://export.dhtmlx.com/gantt",
data: file,
callback: function(project){
console.log(project)
}
});

Details

注释

该方法需要 HTML5 File API 的支持。

注释

该方法在 export 扩展中定义,因此需要激活 export_api 插件。请在 Excel 的导出/导入,导出到 iCal 文章中查看详细信息。

注释

如果你使用的 Gantt 版本低于 8.0,请在页面中包含 https://export.dhtmlx.com/gantt/api.js 以启用在线导出服务,例如:

<script src="codebase/dhtmlxgantt.js"></script>
<script src="https://export.dhtmlx.com/gantt/api.js"></script>

该方法的参数是包含导入文件配置属性的对象:

  • server - 设置请求的 API 端点。可以与导入服务的本地安装一起使用。默认值为 **https://export.dhtmlx.com/gantt**。
  • data - 一个 File 实例,应该包含一个 Excel (xlsx) 文件。
  • callback - 回调函数。
  • sheet - 导入服务应返回的文档的工作表编号。

响应

响应将包含一个 JSON,其中包含对象数组:

[
{ "Name": "Task Name", "Start": "2018-08-11 10:00", "Duration": 8 },
...
]

其中:

  • 第一行的值将用作导入对象的属性名。
  • 每一行被序列化为一个独立的对象。
  • 日期值以 "%Y-%m-%d %H:%i" 格式序列化。
Need help?
Got a question about the documentation? Reach out to our technical support team for help and guidance. For custom component solutions, visit the Services page.