When you export an Excel table, it is originally a field, and when you export it comes to the second line

Source: Internet
Author: User
Start Export
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:attachment;filename=xueyuan_list_data.xls");

Echo mb_convert_encoding (' remarks ', ' 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;
}

Since the data Beizhu at the time of submission is textarea, so beizhu this field will contain a newline character, when exported, once the content has a newline, then the second line will be displayed to the Excel table in another row, But what I want is beizhu. All the content in this field is only displayed in the "Remarks" box in 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 ";


The return line break will be replaced with newline characters (Linux documents are not required, but considering that the document may come from Windows or MAC, doing it is no harm)
Then wrap it up in a standard CSV format (fields are enclosed in double quotes)

Tested without replacing the carriage return line
Just wrap the output string in double quotes.

Yes, 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.