setTextRotation - does not rotate text

Topics: Developer Forum, Project Management Forum, User Forum
Feb 6, 2008 at 11:16 PM
Using release 1.5.5, I cannot rotate text.

example:
$objPHPExcel->getActiveSheet()->getStyle('B7')->getAlignment()->setTextRotation(90);

Does not produce rotated text. I didn'd find this as a known issue. Any insight?

Feb 7, 2008 at 9:01 AM
Edited Feb 7, 2008 at 9:01 AM


rtide wrote:
Using release 1.5.5, I cannot rotate text.

example:
$objPHPExcel->getActiveSheet()->getStyle('B7')->getAlignment()->setTextRotation(90);

Does not produce rotated text. I didn'd find this as a known issue. Any insight?





I have found a code solution to my problem. I'm using the Excel Writer 5 for this project. I traced the output to \PHPExcel\Writer\Excel5\Format.php. The rotation angle was not being set in the getXF() method.

In the IF statement that detects what the BIFF version is, the last case where BIFF version==0x0600 is where the rotation variable was hardcoded to 0x00.

I added this segment of code around line 430 in that file and removed the $rotation=0x00; line. I'm not saying this is perfect nor 100% accurate, but it now rotates my text as I need it to.

switch($this->_rotation){
case 3:
$rotation=0xFFFFFFFFFFFFFFA6;
break;

case 2:
$rotation=0x5A;
break;

case 0:
$rotation=0x00;
break;

default:
$rotation=0x00;
break;
}



Coordinator
Feb 7, 2008 at 9:08 AM
This should be working, are you using Excel2007 writer or Excel5 writer?
Excel5 writer may not support this.
Feb 7, 2008 at 11:59 AM


maartenba wrote:
This should be working, are you using Excel2007 writer or Excel5 writer?
Excel5 writer may not support this.



I'm using the Excel5 writer. Each BIFF format seems to support the text rotation within the IF statement I noted in my posting above. However BIFF version 0x0600 had the rotation hardcoded.

What I posted above resolved my issues.
Sep 4, 2008 at 4:35 AM
I needed a varriation on the above solution to make mine work for all cases, 90, -90, and -1 (stacked):

            switch($this->_rotation){
   case 3:
   $rotation=0x5A;
   break;

   case 2:
   $rotation=0xB4;
   break;

   case 1:
   $rotation=0xFF;
   break;

   case 0:
   $rotation=0x00;
   break;

   default:
   $rotation=0x00;
    break;
    }

Developer
Sep 6, 2008 at 5:29 AM
This has been copied to a work item:
http://www.codeplex.com/PHPExcel/WorkItem/View.aspx?WorkItemId=7531
Developer
Sep 6, 2008 at 5:57 AM
Issue is now fixed. Arbitrary integer rotation angles −90, ... +90 are allowed plus the value −165 for stacked text. From now on please always use the special rotation angle −165 to indicate stacked text.

Examples of what you can do (Works together with both Excel5 writer and Excel2007 writer):

// text rotated 90 degrees clock-wise
$getStyle('A1')->getAlignment()->setTextRotation(-90);

// text rotated 51 degrees counter-clockwise
$getStyle('A1')->getAlignment()->setTextRotation(51);

// to get stacked text (always use -165)
$getStyle('A1')->getAlignment()->setTextRotation(-165);

Feb 11, 2009 at 2:02 PM
Make sure you are NOT using

setVersion 

I took the following line out of my code and  setTextRotation worked immediately.

$workbook->setVersion(8);
Developer
Feb 11, 2009 at 2:07 PM
Uhh.. That is not so good. That line is supposed to stay there. BIFF5 format only supports rotations in steps of 90 degrees. There must be some other reason why it is was not working. Do you have some sample code showing what is not working?