PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
[Solved] Spreadsheet_Excel_Writer - Line break

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> File Formats
View previous topic :: View next topic  
Author Message
alex



Joined: 13 Sep 2006
Posts: 72

PostPosted: Mon Jul 02, 2007 6:43 pm    Post subject: [Solved] Spreadsheet_Excel_Writer - Line break Reply with quote

Hi !
I get data grouped "comma separated" from a mysql db. I need to put it in a cell so explode it then implode with a '\n' (with php functions) so that it put text a new line. Here is this code fetching the db results :

Code:
while($this->fetch()) {
         
         $ex = explode(',', $this->names);
         $names = implode('\n',$ex);
         
         $c_data = array(   '-',
                        $names
                  );
         
         foreach($c_data as $col => $s) {
            $c_max_size[$col] = strlen($c_data[$col]);
            if($p_max_size[$col]<$c_max_size[$col]) {
               $worksheet->setColumn($col,$col,$coeff*$c_max_size[$col]);
               $p_max_size[$col]=$c_max_size[$col];
            }      
            $worksheet->write($row, $col, $c_data[$col]);
         }
         
         $row++;
         
      }


So it does not work ... it just prints '\n' and does not write on a new line.

For example :
name1\nname2\nname4
instead I want :
name1
name2
name4

What is the special char to use to break line ?
Thanks.


Last edited by alex on Tue Jul 03, 2007 12:01 pm; edited 1 time in total
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Mon Jul 02, 2007 6:53 pm    Post subject: Reply with quote

You might want to have a look into the PHP manual about the difference between '\n' and "\n".
Back to top
View user's profile Send private message
alex



Joined: 13 Sep 2006
Posts: 72

PostPosted: Mon Jul 02, 2007 7:14 pm    Post subject: Reply with quote

Hi Mark ! Smile

Yes , you're right ! I did not see I used simple quotes :\

I then used
Code:
implode("\n",$ex);

nstead of
Code:
implode('\n',$ex);


However, although the "\n" disappears in the result, there is no new line Sad :

name1name2name4

Thanks
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Mon Jul 02, 2007 7:44 pm    Post subject: Reply with quote

Take a look at the user notes on the manual then:
http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-worksheet.writestring.php
Back to top
View user's profile Send private message
alex



Joined: 13 Sep 2006
Posts: 72

PostPosted: Tue Jul 03, 2007 12:01 pm    Post subject: Reply with quote

Thanks again Mark ! I did not search in the right place in the doc :\
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> File Formats All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software