PHPExcel公式边框粗细问题
PHPExcel formula border thickness issue
当我尝试在单元格周围设置中边框时,它无法正常显示(如图所示)。在不更改其值的情况下编辑单元格(输入单元格编辑并按回车键)后,它可以正常显示。
我正在使用 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;
?>
如有任何帮助,我们将不胜感激。
您可以尝试使用 allborders
。
您的代码将是:
$objPHPExcel->getActiveSheet()->getStyle('B6')->applyFromArray(
array('borders' => array(
'allborders' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
)
);
否则,您可以将 createWriter
上的 excel 格式更改为 Excel2007
。
这是 PHPExcel 中的错误。
问题已在版本 1.8.1
中修复
当我尝试在单元格周围设置中边框时,它无法正常显示(如图所示)。在不更改其值的情况下编辑单元格(输入单元格编辑并按回车键)后,它可以正常显示。 我正在使用 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;
?>
如有任何帮助,我们将不胜感激。
您可以尝试使用 allborders
。
您的代码将是:
$objPHPExcel->getActiveSheet()->getStyle('B6')->applyFromArray(
array('borders' => array(
'allborders' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
)
);
否则,您可以将 createWriter
上的 excel 格式更改为 Excel2007
。
这是 PHPExcel 中的错误。 问题已在版本 1.8.1
中修复