Generate an Excel file in PHP and generate a line break in an Excel cell.

Source: Internet
Author: User
PHP generates an Excel file and controls the linefeed in the Excel cell. Mantis has a function to export the bug to Excel. However, in the current Mantis version, when exporting the excel file, "Abstract, description, problem reproduction step description: PHP generates an Excel file to control the line break in an Excel cell

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
To create a new cell in the excel file.

Write

..........\r\n
..........\r\n
..........\r\n
?

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);
?

?

?

?

Related Article

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.