A solution to the problem of in cell line wrapping when PHP generates excel

  • 2020-03-31 21:05:48
  • OfStack

"Name:{$Name}\nAddress:{$adress}\nCity:{$city}\nCountry:{$country}\n..."
Since "\n" is not the purpose of line breaking, change it to "\r\n".
Modify = "submit =" test
The result is still no line break!!
Is it operating system compatibility?
PHP runtime constant PHP_EOL instead of "\r\n"
Modify = "submit =" test
The result is still no line break!!
What's going on? It's impossible and it doesn't solve the OS compatibility problem.
See exactly how this XLS file is generated in PHP.
Look at the code to generate excel, Oh My Lady gaga, the original format is HTML, but the file suffix is written XLS, since the format of HTML, so should < Br / > I think I can do a line break.
Continue to
Modify = "submit =" test
The result is that you can wrap. Congratulations. The problem was finally solved.
Tell the boss to solve the problem, now in the heart is very happy.

After a quarter of an hour, the boss came running over and said, "the problem of the line feed effect is solved, but you see, the data is not easy to copy."
.
Omit N sentences.
Copy a cell's data and paste it into word. Oh My Lady gaga, why border??
What's the problem? Using \n, \r\n can not play a line - break correlation, use < Br / > The effect is there, but there is a new problem... What to do?
There is no way out, use BAIDU Google.
Finally, the answer to the question was found.
In < Style> < / styel> Tag with CSS style br {mso-data-placement:same-cell; }
The problem was solved perfectly.
The text reads:
 
 will HTML File extension to XLS After the use Excel Open it. Every one of them <br /> Will cause the text to go into another cell <br /> To wrap a line in a cell CSS Add this sentence:  
br {mso-data-placement:same-cell;} 

Excel Will the <br /> It says enter.  


Thanks to kakashi for sharing his knowledge. Otherwise, I do not know when I have to toss around to solve!!

Related articles: