如何在不使用任何 excel 库 PHP 的情况下创建 xlsx 文件 [英] How to create xlsx file without using any excel library PHP

查看:40
本文介绍了如何在不使用任何 excel 库 PHP 的情况下创建 xlsx 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我现在正在使用的.

This is right now I am using.

$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 variable contains the header row of excel to be generated and looks like this

$header="Business_Name\tBusiness_Type\tType";

\t

$data 包含要在标题列下生成的行.它们也由 \t 分隔,一行以 \n 结束.

and $data contains rows to be generated under header columns. They are also separated by \t and a row is terminated by \n.

当前安装文件已下载,但未使用 ms excel 打开并显示此消息.

With the current setup file is downloaded but it is not opening with ms excel and showing this message.

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.

应该向服务器发送什么标头?或者我如何生成该文件?

What header should be sent to server? or how do I generate that file?

推荐答案

你所拥有的实际上是一个 CSV 文件.根据您的操作系统、浏览器和 Excel 版本,浏览器会允许或不允许您使用 Excel 软件打开扩展程序 CSV、XLS XLSX.

What you have is actually a CSV file. Depending on your OS, your browser and your Excel version, then the browser will differently let you or not let your open the extensions CSV, XLS XLSX with the Excel software.

如果您确实希望使用 Excel 打开数据,则可以使用 打开TBS.使用当前处于 Release Candidate 中的 1.6.0(或更高版本)版本,因为它为 Excel 文件提供了主要功能.

If you do want to have your data opened with Excel, then you can merge the data with an Excel template using OpenTBS. Use version 1.6.0 (or greater) which is currently in Release Candidate because it brings major facilities for Excel files.

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

In your title there is "no excel library PHP". I don't know why you have this specification but OpenTBS is not exactly an Excel library. It's a PHP tool for merging OpenOffice and Ms Office documents using templates.

这篇关于如何在不使用任何 excel 库 PHP 的情况下创建 xlsx 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆