【发布时间】:2019-05-09 04:56:42
【问题描述】:
我使用一个 mySQL 数据库并且必须创建一些 Excel 格式 (xlsx) 的列表。 Excel 工作表必须格式化。对于 csv 导出,我使用 phpExcel(我知道,它已经过时但仍在工作)。
我需要从我的 mySQL 数据库创建格式化的 Excel 工作表。我使用 php 创建前端。
谢谢, 马库斯
【问题讨论】:
标签: php mysql excel format export
我使用一个 mySQL 数据库并且必须创建一些 Excel 格式 (xlsx) 的列表。 Excel 工作表必须格式化。对于 csv 导出,我使用 phpExcel(我知道,它已经过时但仍在工作)。
我需要从我的 mySQL 数据库创建格式化的 Excel 工作表。我使用 php 创建前端。
谢谢, 马库斯
【问题讨论】:
标签: php mysql excel format export
这只是我使用的功能的副本。它只是在设置特定的 $_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");
}
【讨论】: