Toni
Toni

Reputation: 33

PHPExcel formula border thickness issue

When I try to to set a medium border around a cell, it will not display properly (to be seen in the picture). After editting the cell without changing its value (enter cell editting and pressing enter) it is displaying properly. I'm using Excel 2007.

Screen before updating

<?php
include 'mySQLconnect.php';


/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');

if (PHP_SAPI == 'cli')
    die('This example should only be run from a Web Browser');

/** Include PHPExcel */
require_once dirname(__FILE__) . '/PHPExcel_1.8.0/Classes/PHPExcel.php';

// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

$objPHPExcel->getActiveSheet();
$objPHPExcel->getActiveSheet()->setTitle('Sheet 1');

$objPHPExcel->getActiveSheet()->setCellValue('B2', '1');
$objPHPExcel->getActiveSheet()->setCellValue('B2', '1');
$objPHPExcel->getActiveSheet()->setCellValue('B3', '1');
$objPHPExcel->getActiveSheet()->setCellValue('B4', '1');

$objPHPExcel->getActiveSheet()->setCellValue('B6', '=SUM(B2:B4)');

$objPHPExcel->getActiveSheet()->getStyle('B6')->applyFromArray(
    array('borders' => array(
        'bottom'    => array('style' =>PHPExcel_Style_Border::BORDER_MEDIUM),
        'right'     => array('style' =>PHPExcel_Style_Border::BORDER_MEDIUM),
        'left'      => array('style' =>PHPExcel_Style_Border::BORDER_MEDIUM),
        'top'       => array('style' =>PHPExcel_Style_Border::BORDER_MEDIUM)
    )
)
);

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);

// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="data.xls"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
?>

Any help would be greatly appreciated.

Upvotes: 1

Views: 6059

Answers (2)

Toni
Toni

Reputation: 33

It was a bug in PHPExcel. The problem is fixed with Version 1.8.1

Upvotes: 2

Nue
Nue

Reputation: 181

you can try using allborders instead.

your code will be :

$objPHPExcel->getActiveSheet()->getStyle('B6')->applyFromArray(
    array('borders' => array(
    'allborders'    => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
    )
);

or else, you can change the excel format on the createWriter to Excel2007 .

Upvotes: 2

Related Questions