-
- require_once './PHPExcel.php';
- require_once './Excel5.php';
- require_once './ get_excel_row.php';
- require "../include/base.php";
- require "../include/function/006/creatExcelDb.php";
- define("COLOR1","# 96B7F6");
- //查 处理 数据------------
- $q = $db->query ("oa_event_sales에서 * 선택");
- while($a = $db->fetch_array($q)){
- $list[] = $a;
- }
- $ce = new creatExcelDb();
- $re = $ce->_run($list,'served_time','client_status','oid');
- $all_nums=0;
- $num=array( );
- foreach($re as $k=>$v){
- $num[$k]=count($re[$k]);
- $all_nums =count($re[ $k]);
- }
- $jq = array();
- $title1 = client_status;
- $title2 = fin_confirm;
- $title3 = oid;
- //去除数组中상동형值
- foreach($re as $key => $val){
- if(true){
- foreach($val as $key2 => $val2){
- if (!in_array($key2,$jq)){
- $jq[] = $key2;
- }
- }
- }
- }
- $arr_keys=array();
- foreach($re as $k=>$v){
- foreach($v as $k2=>$v2){
- $arr_keys[]=$k2;
- }
- }
- $c=array_count_values($arr_keys);
- // ===---------------
- // 创建一个处理对象实例
- $objExcel = new PHPExcel();
- // 创建文件格式写入对象实例, 주석 해제
- $objWriter = new PHPExcel_Writer_ Excel5($objExcel);
- //设置文档基本属性/**일반적으로 사용되지 않는 것 같습니다 **/
- $objProps = $objExcel->getProperties();
- $objProps->setCreator("杨本木");
- $objProps- >setLastModifiedBy("杨本木");
- $objProps->setTitle("杨本木");
- $objProps->setSubject("杨本木");
- $objProps->setDescription("杨本木");
- $objProps->setKeywords("杨本木");
- $objProps->setCategory("杨本木");
- //***************************************
- //나중 사용을 위해 현재 시트 인덱스 설정 콘텐츠 운영.
- //일반적으로 여러 시트를 사용할 때만 표시 호출이 필요합니다.
- //기본적으로 PHPExcel은 SheetIndex=0
- $objExcel->setActiveSheetIndex(0);
- $objActSheet = $objExcel->getActiveSheet() ;
- 을 사용하여 자동으로 첫 번째 시트를 생성합니다. //현재 활성 시트의 이름을 설정
- $objActSheet->setTitle('현재 시트 이름');
- //폭을 설정합니다. 이 값은 EXCEL의 값과 다릅니다. 단위는 EXCEL
- //$objActSheet->getColumnDimension('A')->setWidth(20);
- //$objActSheet->getRowDimension(1)-의 너비보다 약간 작습니다. >setRowHeight(30) ); //높이
- //셀 값 설정
- $objActSheet->setCellValue('A1', '전체 제목 표시');
- /*
- //스타일 설정
- $objStyleA1 = $objActSheet->getStyle('A1');
- $objStyleA1->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $ objFontA1 = $objStyleA1->getFont ();
- $objFontA1->setName('宋体');
- $objFontA1->setSize(18);
- $objFontA1->setBold(true );
- //열 중심 정렬 설정
- $objActSheet->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- */
- / /---------------첫 번째---------
- $benmu=1;
- $ objActSheet->setCellValue('A1', '行标签列标签');
- foreach($jq as $k=>$v){
- $objActSheet->setCellValue(get_excel_row($benmu) .'1', $v);
- $benmu =1;
- }
- $objActSheet->setCellValue(get_excel_row($benmu).'1', '总计');
- / /设置宽道
- for($i=0;$i<$benmu 1;$i ){
- $objActSheet->getColumnDimension(get_excel_row($i))->setWidth(20);
- //도
- $objActSheet->getStyle(get_excel_row($i)."1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objActSheet->getStyle (get_excel_row($i))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //颜color
- $objActSheet->getStyle(get_excel_row($i)."1") ->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
- $objActSheet->getStyle(get_excel_row($i)."1")->getFill()->getStartColor()- >setARGB(COLOR1);
- }
- //---------------내용---------
- $y=2;
- foreach($re as $k1=>$v1){ //$k1전체 부분 放재A2。。。后면,k1为电话号码、v1为person-》数字
- $objActSheet->setCellValue('A'.$y, $k1);
- //颜color
- $objActSheet->getStyle( 'A'.$y)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
- $objActSheet->getStyle('A'.$y)->getFill()-> getStartColor()->setARGB(COLOR1);
- foreach($jq as $k2=>$v2){ //k2是0,v2是person
- foreach($v1 as $k3=> $v3){ //$k3为person,$v3是要的值
- if($k3==$v2){
- //$objActSheet->setCellValue(get_excel_row("1" $k2) .$y,$v1[$k3]);
- $objActSheet->setCellValueExplicit(get_excel_row("1" $k2).$y,$v1[$k3],PHPExcel_Cell_DataType::TYPE_STRING);
- }
- }
- }
- $objActSheet->setCellValue(get_excel_row("1" count($jq)).$y, $num[$k1]);
- $y =1;
- }
- //----마지막----------------
- $objActSheet-> ;setCellValue("A".$y,"总计");
- //색
- $objActSheet->getStyle("A".$y)->getFill()->setFillType(PHPExcel_Style_Fill ::FILL_SOLID);
- $objActSheet->getStyle("A".$y)->getFill()->getStartColor()->setARGB(COLOR1);
- foreach($jq as $k=>$v){ //k为person
- $objActSheet->setCellValue(get_excel_row("1" $k).$y,$c[$v]);
- //颜color
- $objActSheet->getStyle(get_excel_row("1" $k).$y)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
- $objActSheet->getStyle(get_excel_row ("1" $k).$y)->getFill()->getStartColor()->setARGB(COLOR1);
- }
- $objActSheet->setCellValue(get_excel_row("1") count($jq)).$y,$all_nums);
- //颜color
- $objActSheet->getStyle(get_excel_row("1" count($jq)).$y)->getFill( )->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
- $objActSheet->getStyle(get_excel_row("1" count($jq)).$y)->getFill()->getStartColor()- >setARGB(COLOR1);
- //----------------------
- //출입内容
- $outputFileName =time().".xls";
- header("Pragma: public");
- header("Expires: 0");
- header("캐시 -Control:재검증 필수, 사후 확인=0, 사전 확인=0");
- header("Content-Type:application/force-download");
- header("Content-Type:application /octet-stream");
- header("Content-Type:application/download");
- header('Content-Disposition:attachment;filename='.$outputFileName.'');
- header ("Content-Transfer-Encoding:binary");
- $objWriter->save('php://output');
- ?>
-
复제代码
以上的代码는 중앙의 颜color를 정의하여 excel没有正确显示 Get本来应该的颜color를 정의합니다.
开始定义了一个红color看显示是什么,如下:define(“COLOR1″,”#FF0000″);
但是结果显示的是,정의는 excel中显示为类似于紫color的颜color,反是就不是页面显示的那种颜color입니다.
기술: $objActSheet->getStyle('A'.$y)->getFill()->getStartColor()->setARGB(COLOR1);
考虑可能是ARGB의 원본, 试着把颜color前side加两位00,格式可能是这样的argb(128,255,0,0),可以先排除这个问题,因为a是透명도,试验后才知道,确实是增加了透명도는 4位정색입니다.
|