gpt4 book ai didi

php - 如何在不使用任何Excel库PHP的情况下创建xlsx文件

转载 作者:可可西里 更新时间:2023-11-01 12:26:44 25 4
gpt4 key购买 nike

这是我现在正在使用的。

$mimeType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
header('Content-Description: File Transfer');
header('Content-Type: ' . $mimeType);
header('Content-Disposition: attachment; filename='.basename($type.'.xlsx'));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
print "$header\n$data";
exit;
$header变量包含要生成的excel的标题行,看起来像这样
$header= "Business_Name\tBusiness_Type\tType";
\t分隔

$data包含要在标题列下生成的行。它们也由 \t分隔,并且行由 \n终止。

当前的安装文件已下载,但无法在ms excel中打开并显示此消息。

Excel cannot open the file "file name" because the file format or file extension is not valid. Verify that the file format has not been corrupted and that the file extension matches the format of the file.



什么头应该发送到服务器?或如何生成该文件?

最佳答案

您所拥有的实际上是一个CSV文件。根据您的操作系统,浏览器和Excel版本的不同,浏览器将以不同的方式允许您或不允许您使用Excel软件打开扩展名CSV,XLS XLSX。

如果您确实想使用Excel打开数据,则可以使用OpenTBS将数据与Excel模板合并。使用当前候选版本中的1.6.0(或更高版本)版本,因为它带来了Excel文件的主要功能。

您的标题中有“没有excel库PHP”。我不知道您为什么有此规范,但是OpenTBS并不完全是Excel库。这是一个PHP工具,用于使用模板合并OpenOffice和Ms Office文档。

关于php - 如何在不使用任何Excel库PHP的情况下创建xlsx文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6055430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com