Problem creating a diagonal line in a cell

Topics: Developer Forum, User Forum
Jan 31, 2012 at 4:18 PM

I was trying to create a diagonal line in a cell but nothing appears in the exported excel spreadsheet.

I have no problem with setting up other borders like allborders, top, right, except diagonal.

Here is the code i wrote:

// Set Diagonal Line
$sheet->getStyle('AC19')->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_UP);
$sheet->getStyle('AC19')->getBorders()->getDiagonal(PHPExcel_Style_Borders::DIAGONAL_BOTH);

// alternative method
$styleArray = array(
        'borders' => array(
             'diagonal' => array(
                 'style' => PHPExcel_Style_Borders::DIAGONAL_BOTH,
                 'color' => array('argb' => 'FF000000'),
             ),
         ),
 );
$sheet->getStyle('AC19')->applyFromArray($styleArray);

Could someone help ? Thanks

Coordinator
Feb 1, 2012 at 9:11 PM

Which writer are you using?

Feb 2, 2012 at 8:06 AM
// Output the generated excel file so that the user can save or open the file
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename\"MPSFormAReport.xls");
header("Cache-Control: max-age=0");

$objWriter = PHPExcel_IOFactory::createWriter($phpExcel,"Excel5");
$objWriter->save("php://output");
Sep 27, 2012 at 3:51 AM

hello leatheric:

I have the same question with you that i want to create a diagonal border from left top to right bottom, and you can try this before create a border:

$sheet-> getActiveSheet() -> getStyle(''AC19') -> getBorders() -> setDiagonalDirection( PHPExcel_Style_Borders::DIAGONAL_BOTH );

because the default diagonal border style is DIAGONAL_NONE means no border if you not set, so you must do this before use.