PHPExcel Won't Underline Text

Topics: User Forum
Jul 21, 2012 at 6:54 PM
Edited Jul 21, 2012 at 6:56 PM

Hi I'm trying to underline text when writing to an 'Excel5' type file (.xls) and am having absolutely no luck.


I've tried 


$objPHPExcel -> getActiveSheet() ->getStyle('B3') ->getFont() ->setBold(true);



$styleArray = array( 'font' => array( 'bold' => true, 'underline' => true),);


When I do the same for setBold it works perfectly

Jul 21, 2012 at 10:46 PM

Underlining can be different types, not simply true or false:

const UNDERLINE_NONE             = 'none'; 
const UNDERLINE_DOUBLE           = 'double'; 
const UNDERLINE_DOUBLEACCOUNTING = 'doubleAccounting'; 
const UNDERLINE_SINGLE           = 'single'; 
const UNDERLINE_SINGLEACCOUNTING = 'singleAccounting';

$styleArray = array( 'font' => array( 'bold' => true, 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE),);

Sep 24, 2012 at 7:18 PM

PHPExcel underlining confused me too.

It would be nice if get and set underline, if used as a binary like bold and italic, were short for a single underline.

Sep 25, 2012 at 11:55 AM
Edited Sep 25, 2012 at 11:56 AM

An easy enough change, consider it done: false equates to UNDERLINE_NONE, true to UNDERLINE_SINGLE for setting underline; get will still return the actual UNDERLINE_NONE, UNDERLINE_DOUBLE, etc value