在 mysql 中使用 SELECT INTO OUTFILE 命令保存 XLS 文件

发布于 2024-11-02 17:09:15 字数 306 浏览 0 评论 0原文

我对 XLS 文件使用 SELECT INTO OUTFILE 查询,因为

"SELECT * INTO OUTFILE " . "myfile.xls" . " FIELDS TERMINATED BY '\t'  LINES TERMINATED BY '\n' FROM transactions where ppno like '%$cid%' 

我使用 XLS 文件而不是 CSV。这有什么问题吗。当我尝试在 Microsoft Excel 中打开该 XLS 文件时,它显示“文件格式不同,您确定要打开吗”...请建议我

im using SELECT INTO OUTFILE query with XLS file as

"SELECT * INTO OUTFILE " . "myfile.xls" . " FIELDS TERMINATED BY '\t'  LINES TERMINATED BY '\n' FROM transactions where ppno like '%$cid%' 

Im using XLS file instead of CSV. Is there anything wrong with that. When i try to open that XLS file in Microsoft Excel it says 'The file is in different format, Are you sure you want to open'... Plz suggest me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

阳光下的泡沫是彩色的 2024-11-09 17:09:15

正如 Piskvor 和 Devart 所说,简单地为文件提供 .xls 扩展名实际上并不能使其成为 Excel 文件......生成的文件内容仍然只是一个制表符分隔值文件,正如您的 SQL 语句所表明的那样,

FIELDS TERMINATED BY '\t'  LINES TERMINATED BY '\n' 

如果您想要从 PHP 脚本中创建一个真实 Excel 文件,您还可以(例如)格式化要导出的数据,那么您需要使用一个库,例如我自己的PHPExcel,或 此线程

As Piskvor and Devart have said, simply giving a file an extension of .xls doesn't actually make it an Excel file.... the file content generated is still just a tab-separated value file as your SQL statement makes clear

FIELDS TERMINATED BY '\t'  LINES TERMINATED BY '\n' 

If you want to create a real Excel file from within your PHP script, where you can also (for example) format the data that you're exporting, then you need to use a library such as my own PHPExcel, or one of the others listed in this thread.

离旧人 2024-11-09 17:09:15

是的,这确实有问题。也就是说,您仅更改文件名 - 这不足以自动将您的数据转换为适当的数据格式(换句话说,“任何其他名称的玫瑰都会闻起来很香”)。请注意,Excel 实际上在错误消息中告诉您这一点。

SELECT INTO OUTFILE 不支持 Excel 文档。您需要 a) 导出为 CSV,然后进行转换,或者 b) 获取具有此导出功能的工具(例如 phpMyAdmin 或 Navicat)。

Yes, there is indeed something wrong with that. Namely, you are only changing the filename - that is not sufficient to automagically convert your data to the appropriate data format (in other words, "a rose by any other name would smell as sweet"). Note that Excel actually tells you this, in the error message.

SELECT INTO OUTFILE has no support for Excel documents. You need to a) export into CSV, and convert afterwards, or b) get a tool which has this export capability (e.g. phpMyAdmin or Navicat).

黄昏下泛黄的笔记 2024-11-09 17:09:15

可以设置任何文件扩展名。实际上 xls 是 Excel 尝试读取的二进制 OLE 文件。
SELECT INTO OUTFILE 生成文本文件,尝试存储带有 CSV 或 TXT 扩展名的文件。在这种情况下,Excel 将正确打开文件。

It is possible to set any file extension. Actually xls is a binary OLE file that Excel tries to read.
SELECT INTO OUTFILE generates text file, try to store file with CSV or TXT extension. In this case Excel will open file correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文