Jump to content

Help with line breaks while export text to excel


coupe-r

Recommended Posts

Hi All,

 

I am exporting data to excel, but run into a problem if the text contains a line break.  When it gets to the line break, it cuts off the rest of the text.

 

Here is my printer code:

 

$file = 'Notes_Export';
$csv_output = array();


$tmp = array();
$tmp[] = 'Created On';
$tmp[] = 'Created By';
$tmp[] = 'Note';

$csv_output[] = '"' . implode('","', $tmp) . '"';

$sql  = "SELECT pn.created_on, CONCAT( u.firstname,' ', u.lastname) AS created_by, pn.note FROM prop_notes pn LEFT JOIN users u ON pn.created_by = u.user_id ";
$sql .= "WHERE pn.deleted_by IS NULL AND pn.archive = '0' AND pn.property_id = '".$_GET['pid']."'";
      $result = mysqli_query($connect, $sql);

         while($rowr = mysqli_fetch_row($result))
         {
		$tmp = array();
		for ($j=0; $j<3; $j++)	{$tmp[] = $rowr[$j];}
		$csv_output[] = '"' . implode('","', $tmp) . '"';
         }


$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
// header( "Content-disposition: filename=".$filename.".csv");
header("Content-disposition: attachment; filename=".$filename.".csv");
print implode("\n",$csv_output) . "\n";
exit;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.