Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
785 views
in Technique[技术] by (71.8m points)

php - line break within data for 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).

I get Product1Product2Product3 in the cell when I need

Product1
Product2
Product3

I have tried single quotes, double quotes, CRs, LFs and I am rapidly disapearing up my own backside.

So the question is - what character do I need to get into the CSV file to achieve this?

It has to work in Excel

[Solution] - the problem lay somewhere in passing the to Excel through the PHP fputcsv - I was unable to achieve this in any sort of fashion (plenty of appending the desired to my actual cell data e.g. Product1 ) 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 will not work.

Use this

$lfcr = chr(10) . chr(13);

Then append $lfcr to the end of each line.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...