Text wrapping in cells when PHP generates an Excel file

Source: Internet
Author: User

The customer asked a question today that the cell line of the exported Excel file does not have a line break.

The source code is opened, and the line feed method used in the string is "Name: {$ name} \ naddress: {$ adress} \ ncity: {$ city} \ ncountry: {$ country} \ n ......"

Since "\ n" cannot start with a line break, change it to "\ r \ n.

Modify = submit = test

There is still no line feed !!!!

Is it a problem with operating system compatibility ??

Directly use the PHP runtime constant php_eol to replace "\ r \ n"

Modify = submit = test

There is still no line feed !!!!

What is the situation? This cannot solve the problem of OS compatibility.

Let's see how the xls file is generated using PHP.

After reading the generated Excel fileCode, Oh my Lady Gaga, originally in HTML format, but the file suffix is written as XLS. Since the HTML format is used, it should be <br/>.

Continue

Modify = submit = test

The result is a line break. Congratulations. The problem is finally solved.

Tell the boss to solve the problem. At this time, I am very happy.

 

After a quarter of a year, the boss ran and said, "The problem with the line feed effect is solved, but you can see that the data cannot be copied ."

....

N sentences are omitted.

Copy the data of a cell and paste it into word. Oh my Lady Gaga, why is there border ????

What is the problem ?? Use \ n, \ r \ n to indicate that the newline cannot be used. Use <br/> to display the effect, but a new problem occurs... How is it good?

No. use Baidu Google.

Finally Huang Tian don't have heart, in http://nece001.blog.163.com/blog/static/85633602008979136966/ found the answer to the question.

Append the CSS style BR {MSO-data-placement: Same-cell;} to the <style> </styel> label ;}

Finally, the problem is solved perfectly.

 

Thank you for"The true face of Kakashi"This dear friend shared his knowledge. Otherwise, I don't know when to fix it !!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.