Home >Backend Development >PHP Tutorial >Solution to the problem of line breaks in cells when Microsoft Office Excel PHP generates Excel

Solution to the problem of line breaks in cells when Microsoft Office Excel PHP generates Excel

WBOY
WBOYOriginal
2016-07-29 08:43:401345browse

Open the source code and open it. The method of using line breaks in the string is "Name:{$name}nAddress:{$adress}nCity:{$city}nCountry:{$country}n..."
Since "n" cannot achieve the purpose of line break, change it to "rn" and see.
Modify=》Submit=》Test
The result is still no line break! ! ! !
Is it an operating system compatibility issue? ?
Use the php runtime constant PHP_EOL directly instead of "rn"
Modify =》 Submit =》Test
The result is still no line break! ! ! !
What’s going on? There's no way this won't solve OS compatibility issues with newlines.
Let’s see how this xls file is generated using php.
Looking at the code to generate excel, Oh My Lady gaga, it turns out to be in html format, but the file suffix is ​​written as xls. Since it is in html format, then "br />" should be able to have a line break effect.
Continue
Modify =》 Submit =》Test
The result is that the line can be changed. What a joy. The problem is finally solved.
I told the boss that the problem was solved, and I felt very happy at this time.
After a quarter of an hour, the boss ran over and said: "The problem with the line break effect has been solved, but look, the data is difficult to copy."
. . . .
Omit communication N sentences.
Copy the data in a cell and paste it into word. Oh My Lady gaga, why is there a border? ? ? ?
What exactly is the problem? ? Using n and rn does not have the effect of line breaks, and using
has the effect, but new problems arise. . . What to do?
No choice, use BAIDU google.
Finally, Huang Tian paid off and found the answer to the question.
Append CSS style br {mso-data-placement:same-cell;} in the