使用 Excel 查看 PHP 创建的 CSV 文件

发布于 2024-10-09 03:19:03 字数 333 浏览 0 评论 0原文

我正在寻找一种在 Excel 中打开使用 PHP 脚本创建的 CSV 文件的方法,以便 Excel 知道如何解析该文件。目前,当我双击使用 PHP 创建的 CSV 文件时,Excel 将打开单列中的内容,因此它不会解析每一行。另外,如果我在 Excel 中执行 CTRL-O 并选择要打开的 CSV 文件,Excel 会启动一个向导,我可以在其中选择解析和编码选项。

是否有任何“标题”或标志字符可以添加到 PHP 中的 CSV 输出中,以便让 Excel 知道如何打开文件?例如,我知道为了让Excel处理UTF8编码,需要将U+FEFF字符作为CSV文件中的第一个字符包含在内,所以也许有类似的东西可以解析?

谢谢。

I am looking for a way to open a CSV file, that was created with a PHP script, in Excel - in such a way that Excel knows how to parse the file. Currently when i double click on a CSV file created with PHP, Excel opens the content in a single column so it does not parse each line. Also, if i do CTRL-O in Excel and select the CSV file to be opened, Excel launches a wizard where i am able to select parsing and encoding option.

Are there any 'headers' or flag characters that i could prepend to the CSV output in PHP to let Excel know how to open a file? I know, for example, that in order for Excel to handle UTF8 encoding, a U+FEFF character needs to be included as the first character in the CSV file, so maybe there is something similar for parsing?

Thanks.

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

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

发布评论

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

评论(1

夜清冷一曲。 2024-10-16 03:19:03

请注意,直接打开 csv 文件时,Excel 中是否会显示 csv 选项对话框,具体取决于您的 xcel 版本。

我测试过的最新版本的 Excel 需要特殊的菜单使用才能获得此对话框。
所以你应该提供 Excels 想要的东西。
他想要的是一个制表符分隔的 csv(不是逗号,有趣的是,当他保存 csv 文件时,他使用逗号,但不在自动导入中),没有 " ,并且在单元格中没有回车符,而不是在 utf8 中。

有人说他需要某种 UTF16,我记不清了,当然是 Mark Ba​​ker 引用的 UTF-32LE BOM,

请不要忘记设置 tes text/csv mime 类型标头。

那么当我时, 看到这个损坏的自动导入 csv 没有新 Excel 的对话框我想知道他们是否不想避免完全使用 csv :-)

Ho,我在过去的某个地方看到有一些神秘的格式化命令可以在纯 HTML 中使用Excel 比 csv 格式更能理解表导出。
你应该搜索一下,也许真的更简单。

Beware that depending on your xcel version you will or will not have the csv options dialog in Excel when opening direclty the csv file.

latest versions of Excel I've tested needs a special menu usage to get this dialog.
So you should provides what Excels wants.
And what he wants is a tab-separated csv (not comas, funny enough when he save a csv file he use comas but not in his auto-import), without " and without carriage returns in cells, and not in utf8.

Some says he need some sort of UTF16, I can't remember exactly, certainly the UTF-32LE BOM cited by Mark Baker. You will certainly have to transcode your chars.

Then do not forget to set tes text/csv mime type header.

When I see this broken auto-import csv without dialog of the new Excel I wonder if they didn't want to avoid complelty csv usage :-)

Ho, and I saw somewhere in past that there some mysterious formating commands you can use in an pure HTML table export that Excel will understand really better than the csv format.
You should search a lttle about it, maybe really simplier.

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