简体   繁体   English

如何将行数据从highchart导出到excel文件而不是csv?

[英]How can i export row data from highchart to excel file and not csv?

我有使用php和MySQL从highcharts生成的图表,我想将数据导出到excel(xls)文件中找到了很多解决方案,但它们全部都将数据导出到csv文件中的任何解决方案?

then you can use PHPExcel . 然后可以使用PHPExcel It is an easy utility for exporting your data to excel 这是用于将数据导出到excel的简单实用程序

you can't :P 你不能:P

javascript doesn't know anything about excel a closed source desktop application however it does know csv which is basically a string but im not sure if you can trigger a download with javascript what you need in this case is a server-side language like php javascript对excel封闭式桌面应用程序一无所知,但是它确实知道csv,它基本上是一个字符串,但是我不确定是否可以使用javascript触发下载,在这种情况下,您需要的是服务器端语言(如php)

so what i would do is - a high level list - 所以我要做的是-高级别列表-

  1. identify the row i want to export by attaching an event handler 通过附加事件处理程序来标识我要导出的行
  2. make an ajax call to the 'backend' sending the id of the model and possibly the db table name or any other parameters that will help you get the model 对“后端”进行ajax调用,以发送模型的ID以及可能的数据库表名称或任何其他可帮助您获取模型的参数
  3. handle that ajax call with php 用php处理那个ajax调用

    3.1 make a database call requesting the whole model of that id 3.1进行数据库调用以请求该ID的整个模型

    3.2 use some third-party library that creates excel files 3.2使用一些创建Excel文件的第三方库

    3.3 trigger a download prompt 3.3触发下载提示

alternative step 2. 替代步骤2。

if you already have the model in json or as a javascript object you can serialize it and make an ajax call to the 'backend' and send it instead that would save you the db call and then you would unserialize in php and continue with step 3.2 如果您已经在json中或作为javascript对象拥有模型,则可以对其进行序列化,并向“后端”进行ajax调用并将其发送,这将节省您的db调用,然后您将在php中反序列化并继续执行步骤3.2

it would really helpful if you could post link from the highcharts website with the type of the chart you are using eg is it a pie chart or a bar chart etc 如果您可以从highcharts网站上发布使用的图表类型的链接,这将非常有帮助,例如饼图或条形图等

maybe you can trigger a download with javascript after all but only on html5 compatible browsers Create a file in memory for user to download, not through server 也许您毕竟可以使用javascript触发下载,但只能在html5兼容的浏览器上触发在内存中创建文件供用户下载,而不是通过服务器下载

您可以尝试使用用户插件之一将数据导出到Excel: http : //forum.highcharts.com/highcharts-usage/highchart-export-in-excel-t7816/page15.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM