php - 如何从 mySQL 数据库创建格式化的 Excel 列表?

标签 php mysql excel format export

我使用 mySQL 数据库,并且必须创建一些 Excel 格式 (xlsx) 的列表。 Excel 工作表必须格式化。对于 csv 导出,我使用 phpExcel(我知道,它已经过时,但仍然有效)。

我需要哪个插件才能从 mySQL 数据库创建格式化的 Excel 工作表。我使用 php 创建前端。

谢谢, 马库斯

最佳答案

这只是我使用的函数的副本。它只是在特定的 $_GET 发生时启动该函数。该函数创建一个 xlsx 文件。如果您想将文件导出为 .csv,只需更改文件扩展名并将 text/xlsm 编辑为 text/csv

   $gg = $db->prepare("SELECT * FROM beta_mails ORDER BY created DESC");


    $gg->execute();
            $ggg = $gg->get_result();
            $gg->store_result();

            while ($row = $ggg->fetch_assoc()) {
            $data[] = $row;
        }

        function getprelaunchCSV(){
            global $data;

        header('Content-Type: text/xlsx; charset=utf-8');
        header('Content-Disposition: attachment; filename=data.xlsx');
        // create a file pointer connected to the output stream
        $output = fopen('php://output', 'w');
        // output the column headings
        fputcsv($output, array('ID', 'EMAIL', 'OPRETTET'));
        foreach ($data as $rowCSV){
            fputcsv($output, [$rowCSV["id"], decrypt($rowCSV["email"]), $rowCSV["created"]]);
        }
        fclose($output);
        die();
    }

    if (isset($_GET["getlist"]) && $_GET["getlist"] == "1") {
        echo getprelaunchcsv();
        header("Location:admin?success=1");
    }

关于php - 如何从 mySQL 数据库创建格式化的 Excel 列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53669293/

相关文章:

vba - 如何通过vba中的计数器变量选择工作表?

php - Symfony - Doctrine - 选择用户查询(但可以是匿名用户)

PHP/MySQL 特定的列数

php - 错误 : Unterminated quoted string during PHP exec

mysql - 特定情况下SQL表的命名约定

mysql - 优化分组依据和日期功能

php - mysql:未知选项 '--includedir/etc/mysql/mariadb.conf.d/'

php - TCPDF 问题 - 双重编码

excel - 当我打开多个文件时,如何在 Workbook_Open 事件中关闭 Excel 文件?

excel - 在查找函数后创建循环以复制/粘贴 vba 循环