当我尝试在单元格周围设置中间边框时,它将无法正常显示(在图片中可以看到)。编辑单元格而不更改其值(进入单元格编辑并按Enter键)后,它正确显示。 我正在使用Excel 2007。
<?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;
?>
非常感谢任何帮助。
答案 0 :(得分:2)
这是PHPExcel中的一个错误。 版本1.8.1
修复了该问题答案 1 :(得分:0)
您可以尝试使用allborders
代替。
您的代码将是:
$objPHPExcel->getActiveSheet()->getStyle('B6')->applyFromArray(
array('borders' => array(
'allborders' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
)
);
或者,您可以将createWriter
上的Excel格式更改为Excel2007
。