<?php
require_once 'PHPExcel.php';
require_once 'config.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");
$aRows[] = array("No.","Dealer Name","Mobile No.","Phone No.","Address","Credit Limit","Pending Amount","Status","Total Amount","Order No.","Estimate Arrival","Docket No.");
$aRows[] = array("","","","","","","","","","","","");
$qry = "SELECT * FROM register ";
$qry=mysqli_query($conn , $qry);
while($d= mysqli_fetch_array($qry)){
$aRows[]=array("","","","Item Details","","","");
$aRows[]=array("","","","","","","","","","","","");
$aRows[]=array("","ID","First Name","Last Name","Email");
$aRows[]=array("",$d[0],$d[1],$d[2],$d[3]);
}
$objPHPExcel->setActiveSheetIndex(0)->fromArray($aRows);
$B1Style = array(
'borders' => array(
'allborders' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN
)
)
);
$objPHPExcel->getActiveSheet()->fromArray($aRows[4])->getStyle('B:E')->applyFromArray($B1Style);
$objPHPExcel->getActiveSheet()->getStyle('A3')->getAlignment()->setWrapText(true);
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');
// 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="01simple.xlsx"');
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
function cellColor($cells,$color){
global $objPHPExcel;
$objPHPExcel->getActiveSheet()->getStyle($cells)->getFill()->applyFromArray(array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'startcolor' => array(
'rgb' => $color
)
));
}
/*cellColor('A1:G1', 'F28A8C');
cellColor('B6:E6', 'F28A8C');
cellColor('B8:E8', 'F28A8C');*/
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
ob_end_clean();
$objWriter->save('php://output');
exit;
?>
我有一个数组$ aRows,因为我想在项目详细信息行上创建一个边框,因为项目详细信息重复,我不知道什么是单元格名称所以我怎么能在getstyle()而不是单元格名称中添加行