【问题标题】:How to create formated Excel lists from mySQL database?如何从 mySQL 数据库创建格式化的 Excel 列表?
【发布时间】:2019-05-09 04:56:42
【问题描述】:

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

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

谢谢, 马库斯

【问题讨论】:

    标签: php mysql excel format export


    【解决方案1】:

    这只是我使用的功能的副本。它只是在设置特定的 $_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");
        }
    

    【讨论】:

    • 但它是 csv 而不是 xlsx。而且我没有看到任何格式信息。
    • 我对其进行了编辑,因此它现在创建了一个 xlsm 而不是 csv
    • @Markus 只是想让你知道 php 是后端 - html、css、js 是前端
    • 我知道php是后端。最后 php 为前端创建 html :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多