phpexcel經常使用操做

$objPHPExcel = new PHPExcel();
//設置列寬
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth('11');


//設置默認對齊方式
$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

//設置默認行高
$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(25);


//設置第一行高
$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(80);

//合併單元格
$objPHPExcel->getActiveSheet()->mergeCells('A1:G1');

//設置字體
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(22);    
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑體');

//設置自動換行
$objPHPExcel->getActiveSheet()->getStyle('E10')->getAlignment()->setWrapText(true);

//設置水平居中
$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

//水平居左
$objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
//水平居右
$objPHPExcel->getActiveSheet()->getStyle('C2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

//設置邊框
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getTop()->getColor()->setARGB('FF000000');
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getLeft()->getColor()->setARGB('FF000000');
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getBottom()->getColor()->setARGB('FF000000');
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getRight()->getColor()->setARGB('FF000000');    


$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1','')
            ->setCellValue('A2','編號:' . $BNum)
            ->setCellValue('B3',$Cz)
            ->setCellValue('G19',number_format($Czcb, 2, '.', ''))
            ->setCellValue('C20',round($Cxl,2).'%')
            ->setCellValue('E22',"鑑定評估師(簽章)". $Jdpgs ."\n複覈人(簽章)\n"."評估日期:".date("Y年m月d日",strtotime($Jdpgs_de)) );

// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('二手車鑑定評估報告單');

// 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)

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('../excel/'. $Pg_Excel .'');



若是想生成多個sheet

$objPHPExcel1 = $objPHPExcel->createSheet(1);

$objPHPExcel1->setTitle('表2');

$objPHPExcel1->setCellValue('A1','');


//第二張表的操做都不須要用getActiveSheet()方法了
$objPHPExcel1->getRowDimension(1)->setRowHeight(80);web

相關文章
相關標籤/搜索