/** * * @param unknown $objPHPExcel * @param unknown $cols */ private static function printHeaders($objPHPExcel, $cols) { $count = 1; $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 2, "Data"); foreach ($cols as $col) { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($count++, 2, sprintf("%7s", $col)); } }
/** * * @param unknown $objPHPExcel */ static function newSheet($objPHPExcel, $index = -1) { if ($index < 0) { $index = $objPHPExcel->getSheetCount(); } $objPHPExcel->createSheet($index); $objPHPExcel->setActiveSheetIndex($index); $sheet = $objPHPExcel->getActiveSheet(); return $sheet; }
/** * 设置单元格对齐 * @param unknown $objPHPExcel * @param unknown $CellString * @param string $isRight 是否居右对其 */ private function setCENTER($objPHPExcel, $CellString, $isRight = flase, $isSetBorder = false) { $cellStyle = $objPHPExcel->getActiveSheet()->getStyle($CellString); $cellAlignment = $cellStyle->getAlignment(); $cellAlignment->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); if ($isRight) { $cellAlignment->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); } else { $cellAlignment->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); } if ($isSetBorder) { $cellStyle->getBorders()->getTop()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN); $cellStyle->getBorders()->getLeft()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN); $cellStyle->getBorders()->getRight()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN); $cellStyle->getBorders()->getBottom()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN); } }