PHP generate excel and control line breaks in Excel cells The company uses Mantis to manage bugs. Mantis has a function to export bugs to Excel, However, in the current mantis version, when exporting an excel file, "Abstract, description, problem reproduction step description, additional information, comment", and so on, When submitting a bug, the carriage return and line breaks were lost. because there was no format, it was inconvenient to read in excel, This is the problem, When using php to make an excel file, how can I write a line break in an excel cell to control the format of the cell. I tried it. \ r \ n is invalid when generating an excel file and will be filtered and tuned. However The effect is not a line break in the cell, but a new cell. Google, to achieve the goal of wrapping in cells, you need to insert the following string' ' In addition, I found another interesting problem during my investigation. As mentioned above, when using php to generate an excel file, \ r \ n does not have any line breaks. to control line breaks, you need to use html tags. However, if \ r \ n is mixed in Middle,As shown below, \ r \ n at this time is equivalent to In the excel file, a new cell is created. .......... \ R \ n .......... \ r \ n .......... \ r \ n </pre>This behavior is clearly not what we want, So we should replace them all like below. $ p_new_lines = array ("\ r \ n", "\ n", "\ r", "\ r \ n "," "," "," "," "," "); $ P_change_line_in_excel_cell =' '; $ P_result = str_replace ($ p_new_lines, $ p_change_line_in_excel_cell, $ p_input );>>> Articles you may be interested in: php removes the string line break instance parsing php compresses html (clear line breaks, clear tabs, remove comment tags) php form conversion textarea linefeed method php regular filter html tags, spaces, line breaks and other code examples php remove linefeed method summary php compress html webpage code (clear spaces, line breaks, tabs, annotation mark, etc) provides several php methods to replace line breaks. |