简体   繁体   English

将选定的mysql数据导出到excel

[英]export selected mysql data to excel

I have a question about exporting selected mysql data to excel. 我有一个关于将选定的mysql数据导出到excel的问题。 I have pulled data from a mysql table and I arranged it as I wanted. 我从mysql表中提取了数据,并按需要进行了排列。

我从mysql表中选择的数据

How can I export data from current page to excel?? 如何将数据从当前页面导出到Excel?

I have tried to use this code, 我尝试使用此代码,

<input type= "button" onclick=location.href="export.php" value="Export"/>

this is for the export button on hrviewdate2.php file and this is export.php file: 这是hrviewdate2.php文件上的导出按钮,这是export.php文件:

<?php

header("Content-type: application/vnd-ms-excel");

header("Content-Disposition: attachment; filename=zakat.xls");

include 'hrviewdate2.php';
?>

but it just exports an html page without data that I needed. 但它只是导出一个html页面而没有我需要的数据。

Your best option is to export your data as a csv file that can be opened by most of the popular spreadsheet application including Google Docs and Excel. 最好的选择是将数据导出为csv文件,大多数流行的电子表格应用程序(包括Google Docs和Excel)都可以打开该文件。

You can see this post Export to CSV via PHP for info on how to do this. 您可以看到此帖子通过PHP导出为CSV,以获取有关如何执行此操作的信息。

The only problem you will run into is the lack of support for non English characters by Excel when data is in CSV format. 您将遇到的唯一问题是,当数据为CSV格式时,Excel不支持非英文字符。 You will need to toy with some encoding settings to get the CSV file to open right in Excel. 您将需要使用一些编码设置来使CSV文件在Excel中打开。

If you do want to generate .xls files, you can look into using this library over at GitHub. 如果您确实想生成.xls文件,则可以在GitHub上研究使用此

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

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