Php generate excel and control line breaks in Excel cells

Source: Internet
Author: User
Tags php form
Php generate excel and control line breaks in Excel cells
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.

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.