Hello,

i'm exporting mysql data to excel with php-excel library (http://code.google.com/p/php-excel/).

I don't know how to print new line in excel... i try "\n", "CHAR(10),"NEWLINE" without success. I have all exported data in one line, but i want to have each row in new line.

Here you can look at my code:
http://pastebin.com/vXF1CnRS

Thanks in advice!

From what I read from the documentation, it looks like you have to add the rows in the sheet one at a time. Hence, from your code:

$xls = new Excel_XML('UTF-8', false, 'My Test Sheet');

$xls->addArray($data);
$xls->generateXML('my-test');

You could, as a SIMPLISTIC example:

$xls = new Excel_XML('UTF-8', false, 'My Test Sheet');
$myheaders = array('Data1','Data2','Data3');
$xls->addArray ( $myheaders );

// then sql call here
while($row = mysql_fetch_array($result, MYSQL_BOTH)) {
   $thisrow[0] = $row['dbvalue1'];
   $thisrow[1] = $row['dbvalue2'];
   $thisrow[2] = $row['dbvalue3'];
   $xls->addArray ( $thisrow );
}
$xls->generateXML('my-test');

This is just what makes sense to me after reading the docs. Basically, every time a new $xls->addArray is invoked, it is like a new line of data in the spreadsheet. Not tested, as I do not have the libraries installed. Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.