When exporting an excel table, it is originally the content of a field, but it is in the second row.

Source: Internet
Author: User
When exporting an excel table, it is originally the content of a field, but it is exported to the second row // start to export
Header ("Content-type: application/vnd. ms-excel ");
Header ("Content-Disposition: attachment?filename=xueyuan_list_data.xls ");

Echo mb_convert_encoding ('note', 'gbk', 'utf-8'). "\ t ";

$ Xuhao = 1;
Foreach ($ arr_xueyuan_list as $ arr)
{
Echo "\ n ";
Echo $ xuhao. "\ t ";
Echo mb_convert_encoding ($ arr ['beizhu'], 'gbk', 'utf-8'). "\ t ";
$ Xuhao = $ xuhao + 1;
}

Because the data beizhu is textarea when it is submitted, the beizhu field contains a line break. During export, once the content contains a line break, the second row is displayed in another row of the excel table, but all the content in the beizhu field is displayed only in the "remarks" field of the excel table, what should I do?


Reply to discussion (solution)

$beizhu = mb_convert_encoding($arr['beizhu'],'GBK','UTF-8');$beizhu = '"' . preg_replace(("/[\r\n]+/", "\n", $beizhu) . '"';echo $beizhu . "\t";


Changing line breaks to line breaks (Linux documents are not required, but considering that the documents may come from Windows or Mac, there is no harm in doing so)
Then packaged in standard csv format (fields are enclosed in double quotation marks)

After testing, you do not have to replace the carriage return and line feed.
You only need to enclose the output string with double quotation marks.

Thank you.

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.