导出Excel Excel [英] Export CSV for Excel

查看:120
本文介绍了导出Excel Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在PHP中使用 fputcsv($ file,$ data)编写CSV文件。
这一切都有效,但是我不能仅仅在Excel中打开它,而是必须导入它,并指定要使用的编码和分隔符(在向导中)。
我看到从其他网站的出口,只要点击它们正确打开,现在想知道我应该做什么我的文件来实现。



我尝试使用这个库: http://code.google.com/p/ parsecsv-for-php /
但是我甚至不能让它运行,如果它真的可以帮助我,我并不确定...

解决方案

尽管CVS中有C =逗号,但Excel使用您的区域设置本机分隔符。所以假设 fputcsv 总是使用逗号,如果你的语言环境分隔符是分号,它将不起作用。



可能您引用的其他页面从 Accept-Language HTTP标头推断分隔符。



编辑:
当您点击导出到Excel CSV 时,Google Adsense的作用是使用 Tab 作为分隔符。这两种情况都设置了 fputcsv的第三个参数(分隔符覆盖默认的逗号。例如。用于选项卡使用: fputcsv($ handle,$ fields,\t);



绝对比较格式的CSV可用于由 fputcsv 生成的CSV。



考虑在您的问题中包含两个示例。你可能会得到更好的答案。


I'm writing a CSV file in PHP using fputcsv($file, $data). It all works, however I can't just open it in Excel but have to import it and specify the encoding and which delimiter to use (in a wizard). I've seen exports from other websites that open correctly just by clicking on them and now would like to know what I should do to my file to achieve that.

I tried using this library: http://code.google.com/p/parsecsv-for-php/ But I couldn't even get it to run and am not really confident if it would really help me...

解决方案

Despite the "C=comma" in CVS, Excel uses your locale native separator. So supposing fputcsv always uses comma, it won't work, if your locale separator is for example semicolon.

Possibly the other pages you refer to infer the separator from Accept-Language HTTP header.

EDIT: What Google Adsense does, when you click Export to Excel CSV, is that it uses Tab as a separator. And that works.

In both cases set the third parameter (delimiter) of fputcsv to override the default comma. E.g. for tab use: fputcsv($handle, $fields, "\t");

Definitely compare format of the CSV that works for you against the one generated by fputcsv.

Consider including example of both in your question. You might get better answers.

这篇关于导出Excel Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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