The company uses Mantis to manage bugs, Mantis has a feature that exports bugs to Excel,
But the current version of this mantis, in the export of Excel, "Summary, description, problem repro Step description, additional information, comments" and so on,
When I submit a bug, the carriage return line break is gone, because there is no format, it is inconvenient to read in Excel.
This is the problem that I think we are improving.
When using PHP for Excel, how to write a newline character within an Excel cell to control the format of the cell.
I experimented, \ r \ n When generating Excel, is invalid, will be filtered.
But if you write to <br>, the effect is not to wrap the cells, but to change a new cell.
Google, in order to achieve the purpose of the cell line wrap, you need to insert the following string
' <br style= ' Mso-data-placement:same-cell; '/> '
In addition to the process of my investigation, I found another interesting question.
As mentioned earlier, when using PHP to generate Excel, \ r \ n can not afford any line-wrapping effect, to control the line, you need to use HTML tags.
However, if you put \ r \ n in <pre> </pre> Center,
The shape is as follows, then, at this time, \ r \ n is equivalent to a <br> in Excel, a new cell is made.
Wrote <pre>
... \ r \ n
... \ r \ n
... \ r \ n
</pre>
This behavior is obviously not what we want,
So let's just replace them with the following.
$p _new_lines = Array ("\ r \ n", "\ n", " \ r", "\ r \ n", "<pre>", "</pre>", "<br>", "</br>", "< Br/> "); $p _change_line_in_excel_cell = ' <br style= ' Mso-data-placement:same-cell; '/> '; $p _result = Str_replace ($p _new_lines, $p _change_line_in_excel_cell, $p _input);