导出到excel文件,单元格行中,ALT + ENTER

我需要在一个单元格使用PHP xls导出行换行,我已经尝试\ r或\ n他们把文本到下一个单元格的字符,而不是把文本放在同一个单元格换行符。

例:

hello world

我需要一行和下一个世界像你在同一个细胞。

这是肮脏的代码..但工作..希望这可以帮助你。

我提到这些

http://www.bennadel.com/blog/1095-maintaining-line-breaks-in-an-html-excel-file.htm

在PHP中将MySQL数据导出到Excel

 <?php /*******EDIT LINES 3-8*******/ $DB_Server = "localhost"; //MySQL Server $DB_Username = "root"; //MySQL Username $DB_Password = ""; //MySQL Password $DB_DBName = "survey"; //MySQL Database Name $DB_TBLName = "results"; //MySQL Table Name $filename = "survey results"; //File Name /*******YOU DO NOT NEED TO EDIT ANYTHING BELOW THIS LINE*******/ //create MySQL connection $sql = "Select username, email, q1, q2, q3, createdat from $DB_TBLName"; $Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno()); //select database $Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno()); //execute query $result = @mysql_query($sql,$Connect) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno()); $file_ending = "xls"; //header info for browser header("Content-Type: application/xls"); header("Content-Disposition: attachment; filename=$filename.xls"); header("Pragma: no-cache"); header("Expires: 0"); /*******Start of Formatting for Excel*******/ //define separator (defines columns in excel & tabs in word) $sep = "\t"; //tabbed character //start of printing column names as names of MySQL fields echo <<<EOF <!--- Store Excel-HTML output. ---> <cfsavecontent variable="strData"> <table border=".5pt"> <thead> <tr> EOF; for ($i = 0; $i < mysql_num_fields($result); $i++) { echo "<th>" . mysql_field_name($result,$i) . "</th>"; } echo <<<EOF </thead> <tbody> EOF; //end of printing column names //start while loop to get data while($row = mysql_fetch_row($result)) { echo "<tr valign=\"top\">"; for($j=0; $j<mysql_num_fields($result);$j++) { echo "<td>"; if(!isset($row[$j])) echo preg_replace("/\r\n|\n\r|\n|\r/", "<br style=\"mso-data-placement:same-cell;\" />", "NULL".$sep); elseif ($row[$j] != "") echo preg_replace("/\r\n|\n\r|\n|\r/", "<br style=\"mso-data-placement:same-cell;\" />", "$row[$j]".$sep); else echo preg_replace("/\r\n|\n\r|\n|\r/", "<br style=\"mso-data-placement:same-cell;\" />", "".$sep); echo "</td>"; } echo "</tr>"; } echo <<<EOF </tbody> </table> </cfsavecontent> <!--- Set header for file attachment. ---> <cfheader name="content-disposition" value="attachment; filename=data.xls" /> <!--- Stream the content. ---> <cfcontent type="application/excel" variable="#ToBinary( ToBase64( strData ) )#" /> EOF; ?>