Automatic newlines in long text

Topics: User Forum
Jul 26, 2008 at 4:16 PM
Edited Jul 26, 2008 at 4:17 PM

I'm inserting text into Excel cells and I'm having trouble with getting it to appear correctly in the generated Excel file. The problem is that it continues to run beyond the scope of the cell so that it appears to the user as if it has been sliced in the middle. Of course, if you expand the cell this data appears. However, this issue is not solved when printing the file, which my application will automatically do directly after the Excel file has been generated. One solution is to use the capability of PHPExcel to automatically set the column width, but then another problem arises. The sheet becomes to wide to print without scaling the sheet down too much to be readable by people.

So what I'm looking for is a possibility to make long text expand below the initial text.

Instead of: Hello World!
It will apperas as if it is:

The row height will indeed increase, but that is not an issue. The important thing is that the width remain the same. I tried inserting newlines (\n) between the words (if that would have worked I could have designed a PHP function to set these newlines in the correct places to create the effect I'm searching for). But it didn't work. So my question is if there is a builtin method someplace within the PHPExcel classes that I can make use for? Or if someone can help me understand how I can create working newlines within Excel. Because \n doesn't seem to work.

Thanks in advance.
Jul 27, 2008 at 3:38 AM
Sounds like you want to wrap text?

Done in MS Office Excel 2007 using Home > Alignment > Wrap Text.

Corresponding method in PHPExcel, example:

$ws = $objPHPExcel->getActiveSheet();