Problem to add italic with setCellValueByColumnAndRow method

Topics: Developer Forum, Project Management Forum, User Forum
Sep 24, 2014 at 9:28 AM
Edited Sep 24, 2014 at 9:34 AM
I everybody!
I'd like to add italic style to a cell filled with setCellValueByColumnAndRow method but what I get is style on cell A1 I suppose because getStyle can't focus on my cell so how can I resolve?
here follow my code:
$styleArray = array('font' => array('bold' => false, 'italic' => true));
//inside a loop to get data for cells:
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0,$z, $c)->getStyle()->applyFromArray($styleArray);
thanks in advance.
ciao
h.
Coordinator
Sep 24, 2014 at 10:21 AM
By default, a call to setCellValueByColumnAndRow() will return a worksheet object. While the worksheet has a getStyle() method, it requires you to pass a cell address as an argument, otherwise it will default to cell A1.

However, you can tell setCellValueByColumnAndRow() to return the cell instead of the worksheet, and the cell's getStyle() method does not require a cell address as an argument, because it already knows what cell it is.

To tell setCellValueByColumnAndRow() to return the cell instead of the worksheet, you need to call it with an additional argument:
$objPHPExcel->getActiveSheet()
    ->setCellValueByColumnAndRow(0, $z, $c, true)
    ->getStyle()
    ->applyFromArray($styleArray);
Sep 24, 2014 at 10:30 AM
Thank you for answer me MarkBaker but in this way I get all cells in italic and not only the single one.

thanks again
ciao
h.
Sep 25, 2014 at 9:20 AM
Any news about my problem?

thanks again.
h.
Dec 26, 2014 at 7:02 AM
hi haltman

i use this for italic in single cells

$bw = new PHPExcel_Style();
    $bw->applyFromArray(
    array(
            'font'    => array('italic' => true)

     ));



    $objPHPExcel->getActiveSheet()->setSharedStyle($bw, 'B');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B' , 'blablablablablabla');

thats work for me.

udin
Dec 26, 2014 at 12:39 PM

Thanks fior hints

Il 26/Dic/2014 09:02 "udin_mentho" <[email removed]> ha scritto:

From: udin_mentho

hi haltman

i use this for italic in single cells

$bw = new PHPExcel_Style();
    $bw->applyFromArray(
    array(
            'font'    => array('italic' => true)

     ));



    $objPHPExcel->getActiveSheet()->setSharedStyle($bw, 'B');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B' , 'blablablablablabla');

thats work for me.

udin

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com