1
當我嘗試在單元格周圍設置中等邊框時,它將無法正確顯示(可在圖片中看到)。在編輯單元格而不更改其值(輸入單元格編輯並按下Enter鍵)後,它正常顯示。 我使用Excel 2007中PHPExcel公式邊框厚度問題
<?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;
?>
任何幫助將不勝感激。
我試過allboarders,但rersult仍然是一樣的。底部邊界比其他邊界更薄。當我在單元格B6中寫入文本而不是公式時,所有邊界都從頭開始正確顯示。這似乎是與PHPExcel或Excel 2007的問題。 – Toni
我需要它爲另一個項目。上面的代碼只是爲了向社區描述問題。我已經在這裏上傳了測試文件:[link](http://tv-laufach.de/ExcelExportTest.php)。可能每個人都打開它並在此處報告他的結果。我知道這不是一個大問題,但每次手動編輯單元格都很麻煩,而且Excel顯示屏沒有任何好的照片。 – Toni
您是否嘗試將'createWriter'上的excel格式更改爲'Excel2007'? – Nue