简体   繁体   中英

export selected mysql data to excel

I have a question about exporting selected mysql data to excel. I have pulled data from a mysql table and I arranged it as I wanted.

我从mysql表中选择的数据

How can I export data from current page to 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:

<?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.

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.

You can see this post Export to CSV via PHP for info on how to do this.

The only problem you will run into is the lack of support for non English characters by Excel when data is in CSV format. You will need to toy with some encoding settings to get the CSV file to open right in Excel.

If you do want to generate .xls files, you can look into using this library over at GitHub.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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