Excel 2003数据中的换行符 [英] line break within data for Excel 2003
问题描述
使用PHP从SQL中提取数据,然后在服务器上创建.csv文件,以通过fputcsv进行电子邮件发送/下载。除了尝试在Excel(2003)中的一个字段中获得新行以外,所有的工作都很好。
Using PHP to extract data from SQL and then creating a .csv file on the server for emailing/download by way of fputcsv. All works well other than trying to get a new line within a field in Excel (2003).
当我需要
Product1
Product2
Product3
我试过单引号,双引号,CR,LF,我正在迅速剥夺自己的背后。
I have tried single quotes, double quotes, CRs, LFs and I am rapidly disapearing up my own backside.
所以问题是 - 我需要什么字符进入CSV文件才能实现这一点?
So the question is - what character do I need to get into the CSV file to achieve this?
它必须在Excel中工作
It has to work in Excel
[解决方案] - 问题在于将\r\\\
传递给Excel,通过PHP fputcsv - 我无法以任何方式实现这一点(大量的附加到我的实际单元格数据,如Product1 \\\
)
建议使用$ lfcr = chr(10)。 CHR(13);第一次工作。我想这更多是一个PHP而不是一个Excel问题 - 感谢所有的信息。
[Solution] - the problem lay somewhere in passing the \r\n to Excel through the PHP fputcsv - I was unable to achieve this in any sort of fashion (plenty of appending the desired \r\n to my actual cell data e.g. Product1\r\n) The suggestion to use $lfcr = chr(10) . chr(13); worked first time around. I guess this was more of a PHP rather than an Excel question - thanks to all resonses.
推荐答案
这更像是一个excel而不是一个php问题。你要把它放在csv文件中需要被excel理解,这就是为什么\\\\
将无法工作。
This is more of an excel rather than a php question. What you put into the csv file needs to be understood by excel which is why \r\n will not work.
使用这个
$lfcr = chr(10) . chr(13);
然后将$ code> $ lfcr 附加到每行。
Then append $lfcr
to the end of each line.
这篇关于Excel 2003数据中的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!