我使用mySQL数据库,并且必须创建一些Excel格式的列表(xlsx)。Excel工作表必须格式化。对于csv导出,我使用phpExcel (我知道,它已经过时了,但仍然有效)。
要从我的mySQL数据库创建带格式的Excel工作表,我需要哪些附加组件。我使用php来创建前端。
谢谢,马库斯
发布于 2018-12-07 20:13:37
这只是我使用的函数的副本。它只在设置了特定的$_GET时启动函数。此函数用于创建xlsx文件。如果要将文件导出为文本,只需更改文件扩展名并将文本/xlsm编辑为.csv /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");
}
https://stackoverflow.com/questions/53669293
复制相似问题