phpExcel使用办法介绍_php技能_脚本之家,phpExcel使

作者:编程

有关phpexcel导出颜色的部分题目,用phpexcel做导出的excel的水彩怎么和网页中的颜色呈现不相通呢?想要知道毕竟是怎么回事?应该怎么来解决呢?PHP代码细节如下: PHP code: 复制代码 代码如下: query("select * from oa_event_sales"); while($a = $db->fetch_array{ $list[] = $a; } $ce = new creatExcelDb(); $re = $ce->_run($list,'served_time','client_status','oid'); $all_nums=0; $num=array(); foreach{ $num[$k]=count; $all_nums =count; } $jq = array(); $title1 = client_status; $title2 = fin_confirm; $title3 = oid; //去除数组中千篇豆蔻梢头律的值 foreach{ if{ foreach($val as $key2 => $val2){ if{ $jq[] = $key2; } } } } $arr_keys=array(); foreach{ foreach{ $arr_keys[]=$k2; } } $c=array_count_values; // === // 创制七个甩卖指标实例 $objExcel = new PHPExcel(); // 创造文件格式写入对象实例, uncomment $objWriter = new PHPExcel_Writer_Excel5; //设置文书档案基性格格/**就如日常景观下用不到**/ $objProps = $objExcel->getProperties(); $objProps->setCreator; $objProps->setLastModifiedBy; $objProps->setTitle; $objProps->setSubject; $objProps->setDescription; $objProps->setKeywords; $objProps->setCategory; //************************************* //设置当前的sheet索引,用于后续的内容操作。 //平时唯有在动用七个sheet的时候才需求出示调用。 //缺省景观下,PHPExcel会自动创设第三个sheet被安装SheetIndex=0 $objExcel->setActiveSheetIndex; $objActSheet = $objExcel->getActiveSheet(); //设置当前运动sheet的名号 $objActSheet->setTitle; //设置宽度,那一个值和EXCEL里的不等,不亮堂是何等单位,略小于EXCEL中的宽度 //$objActSheet->getColumnDimension; //$objActSheet->getRowDimension; //中度 //设置单元格的值 $objActSheet->setCellValue; /* //设置样式 $objStyleA1 = $objActSheet->getStyle; $objStyleA1->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTE兰德Haval); $objFontA1 = $objStyleA1->getFont(); $objFontA1->setName; $objFontA1->setSize; $objFontA1->setBold; //设置列居中对齐 $objActSheet->getStyle->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); */ //============first=================================== $benmu=1; $objActSheet->setCellValue; foreach{ $objActSheet->setCellValue.'1', $v); $benmu =1; } $objActSheet->setCellValue.'1', '总括'); //设置宽度 for($i=0;$igetColumnDimension->setWidth; //宽度 $objActSheet->getStyle."1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objActSheet->getStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //颜色 $objActSheet->getStyle."1")->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID); $objActSheet->getStyle."1")->getFill->setA帕杰罗GB; } //==============content================= $y=2; foreach{ //$k1全勤坐落A2。。。。后边,k1为电话号码、v1为person-》数字 $objActSheet->setCellValue; //颜色 $objActSheet->getStyle->setFillType(PHPExcel_Style_Fill::FILL_SOLID); $objActSheet->getStyle->getStartColor; foreach{ //k2是0,v2是person foreach{ //$k3为person,$v3是要的值 if{ //$objActSheet->setCellValue(get_excel_row; $objActSheet->setCellValueExplicit(get_excel_row.$y,$v1[$k3],PHPExcel_Cell_DataType::TYPE_STRING); } } } $objActSheet->setCellValue(get_excel_row.$y, $num[$k1]); $y =1; } //=================last========== $objActSheet->setCellValue; //颜色 $objActSheet->getStyle->setFillType(PHPExcel_Style_Fill::FILL_SOLID); $objActSheet->getStyle->getStartColor; foreach{ //k为person $objActSheet->setCellValue.$y,$c[$v]); //颜色 $objActSheet->getStyle.$y)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID); $objActSheet->getStyle.$y)->getFill->setARGB; } $objActSheet->setCellValue(get_excel_row.$y,$all_nums); //颜色 $objActSheet->getStyle(get_excel_row->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID); $objActSheet->getStyle(get_excel_row->getFill->setA昂CoraGB; //=============================== //输出内容 $outputFileName =time().".xls"; header; header; header("Cache-Control:must-revalidate, post-check=0, pre-check=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; ?> 上面包车型大巴代码中,define中的颜色在导出的excel没有准确展现出本来应该的水彩?是什么样原因?为啥吗? 发轫定义了一个白色看呈现是怎么,如下:define; 可是结果呈现的是,定义水泥灰在excel中展示为挨近于金红的颜料,反正就不是页面展现的这种颜色,太令人费解了。。。。。 看那句代码:$objActSheet->getStyle->getStartColor; 有一点点感觉恐怕是ARubiconGB原因,故试着把颜色前边加两位00,笔者不知情这么行还是不行,试试效果先,何况格式也会有希望是这么的argb,能够先肃清那几个主题素材,因为a是光滑度,后来试验了才精通,确实是充实了反射率的4位定色。

下载地址: 上边是总结的多少个利用方式include ‘PHPExcel.php'; include ‘PHPExcel/Writer/Excel2005.php'; //可能include ‘PHPExcel/Writer/Excel5.php'; 用于输出.xls的 创设二个excel $objPHPExcel = new PHPExcel(); 保存excel—2007格式 $objWriter = new PHPExcel_Writer_Excel2007; //或者$objWriter = new PHPExcel_Writer_Excel5; 非2007格式 $objWriter->save; 一直出口到浏览器 $objWriter = new PHPExcel_Writer_Excel5; header; header; header("Cache-Control:must-revalidate, post-check=0, pre-check=0″); header("Content-Type:application/force-download"); header("Content-Type:application/vnd.ms-execl"); header("Content-Type:application/octet-stream"); header("Content-Type:application/download");; header('Content-Disposition:attachment;filename="resume.xls"‘); header("Content-Transfer-Encoding:binary"); $objWriter->save; ——————————————————————————————————————– 设置excel的属性: 成立人 $objPHPExcel->getProperties()->setCreator; 最终校勘人 $objPHPExcel->getProperties()->setLastModifiedBy; 标题$objPHPExcel->getProperties()->setTitle("Office 二〇〇五 XLSX Test Document"); 标题 $objPHPExcel->getProperties()->setSubject("Office 二〇〇五 XLSX Test Document"); 描述 $objPHPExcel->getProperties()->setDescription("Test document for Office 二零零六 XLSX, generated using PHP classes."); 关键字 $objPHPExcel->getProperties()->setKeywords("office 2005 openxml php"); 体系 $objPHPExcel->getProperties()->setCategory; ——————————————————————————————————————– 设置当前的sheet $objPHPExcel->setActiveSheetIndex; 设置sheet的name $objPHPExcel->getActiveSheet; 设置单元格的值 $objPHPExcel->getActiveSheet()->setCellValue; $objPHPExcel->getActiveSheet()->setCellValue; $objPHPExcel->getActiveSheet()->setCellValue; $objPHPExcel->getActiveSheet()->setCellValue; $objPHPExcel->getActiveSheet()->setCellValue; 合併单元格 $objPHPExcel->getActiveSheet()->mergeCells; 分离单元格 $objPHPExcel->getActiveSheet()->unmergeCells; 体贴cell $objPHPExcel->getActiveSheet->setSheet; // Needs to be set to true in order to enable any worksheet protection! $objPHPExcel->getActiveSheet()->protectCells; 设置格式 // Set cell number formats echo date . " Set cell number formatsn"; $objPHPExcel->getActiveSheet->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); $objPHPExcel->getActiveSheet()->duplicateStyle( $objPHPExcel->getActiveSheet, ‘E5:E13′ ); 设置宽width // Set column widths $objPHPExcel->getActiveSheet()->getColumnDimension->setAutoSize; $objPHPExcel->getActiveSheet()->getColumnDimension; 设置font $objPHPExcel->getActiveSheet->getFont; $objPHPExcel->getActiveSheet->getFont; $objPHPExcel->getActiveSheet->getFont; $objPHPExcel->getActiveSheet->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE); $objPHPExcel->getActiveSheet->getFont->setARGB(PHPExcel_Style_Color::COLOR_WHITE); $objPHPExcel->getActiveSheet->getFont->setARGB(PHPExcel_Style_Color::COLOR_WHITE); $objPHPExcel->getActiveSheet->getFont; $objPHPExcel->getActiveSheet->getFont; 设置align $objPHPExcel->getActiveSheet->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); $objPHPExcel->getActiveSheet->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); $objPHPExcel->getActiveSheet->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); $objPHPExcel->getActiveSheet->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY); //垂直居中 $objPHPExcel->getActiveSheet->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); 设置column的border $objPHPExcel->getActiveSheet->getBorders->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN); $objPHPExcel->getActiveSheet->getBorders->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN); $objPHPExcel->getActiveSheet->getBorders->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN); $objPHPExcel->getActiveSheet->getBorders->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN); $objPHPExcel->getActiveSheet->getBorders->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN); 设置border的color $objPHPExcel->getActiveSheet->getBorders->getColor()->setA大切诺基GB; $objPHPExcel->getActiveSheet->getBorders->getColor()->setA本田UR-VGB; $objPHPExcel->getActiveSheet->getBorders->getColor()->setA奇骏GB; $objPHPExcel->getActiveSheet->getBorders->getColor()->setA宝马i8GB; $objPHPExcel->getActiveSheet->getBorders->getColor()->setAEnclaveGB; $objPHPExcel->getActiveSheet->getBorders->getColor()->setA科雷傲GB; 设置填充颜色 $objPHPExcel->getActiveSheet->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID); $objPHPExcel->getActiveSheet->getFill->setARGB; $objPHPExcel->getActiveSheet->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID); $objPHPExcel->getActiveSheet->getFill->setARGB; 加图片 $objDrawing = new PHPExcel_Worksheet_Drawing(); $objDrawing->setName; $objDrawing->setDescription; $objDrawing->setPath('./images/officelogo.jpg'); $objDrawing->setHeight; $objDrawing->setWorksheet($objPHPExcel->getActiveSheet; $objDrawing = new PHPExcel_Worksheet_Drawing(); $objDrawing->setName; $objDrawing->setDescription; $objDrawing->setPath; $objDrawing->setCoordinates; $objDrawing->setOffsetX; $objDrawing->setRotation; $objDrawing->getShadow; $objDrawing->getShadow; $objDrawing->setWorksheet($objPHPExcel->getActiveSheet; 在暗中认可sheet后,创造三个worksheet echo date . " Create new Worksheet objectn"; $objPHPExcel->createSheet(); $objWriter = PHPExcel_IOFactory::createWriter; $objWriter-save;

phpExcel操作excel能够事半功倍的踏入图片,帮助jpg gif png格式。

 下载地址: 

上边是总括的多少个利用形式
include ‘PHPExcel.php';
include ‘PHPExcel/Writer/Excel2007.php';
//也许include ‘PHPExcel/Writer/Excel5.php'; 用于输出.xls的
创立一个excel
$objPHPExcel = new PHPExcel();
保存excel—2007格式
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
//或者$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); 非2007格式
$objWriter->save("xxx.xlsx");
直白出口到浏览器
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
header("Pragma: public");
header("Expires: 0″);
header("Cache-Control:must-revalidate, post-check=0, pre-check=0″);
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header('Content-Disposition:attachment;filename="resume.xls"‘);
header("Content-Transfer-Encoding:binary");
$objWriter->save('php://output');
——

对phpexcel类库不熟知的情人,能够翻阅下《phpexcel中文匡帮手册》中的内容,具体实例大家能够phpexcel火速支付指南中的相关例子。 
设置excel的属性:
创建人
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
末段修正人
$objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");
标题
$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
题目
$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
描述
$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
关键字
$objPHPExcel->getProperties()->setKeywords("office 2007 openxml php");
种类
$objPHPExcel->getProperties()->setCategory("Test result file");
编程 ,——————————————————————————————————————–
安装当前的sheet
$objPHPExcel->setActiveSheetIndex(0);
设置sheet的name
$objPHPExcel->getActiveSheet()->setTitle('Simple');
安装单元格的值
$objPHPExcel->getActiveSheet()->setCellValue('A1′, ‘String');
$objPHPExcel->getActiveSheet()->setCellValue('A2′, 12);
$objPHPExcel->getActiveSheet()->setCellValue('A3′, true);
$objPHPExcel->getActiveSheet()->setCellValue('C5′, ‘=SUM(C2:C4)');
$objPHPExcel->getActiveSheet()->setCellValue('B8′, ‘=MIN(B2:C5)');
联合单元格
$objPHPExcel->getActiveSheet()->mergeCells('A18:E22′);
暌违单元格
$objPHPExcel->getActiveSheet()->unmergeCells('A28:B28′);
保护cell
$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true); // Needs to be set to true in order to enable any worksheet protection!
$objPHPExcel->getActiveSheet()->protectCells('A3:E13′, ‘PHPExcel');
安装格式
// Set cell number formats
echo date('H:i:s') . " Set cell number formatsn";
$objPHPExcel->getActiveSheet()->getStyle('E4′)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$objPHPExcel->getActiveSheet()->duplicateStyle( $objPHPExcel->getActiveSheet()->getStyle('E4′), ‘E5:E13′ );
设置宽width
// Set column widths
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12);
设置font
$objPHPExcel->getActiveSheet()->getStyle('B1′)->getFont()->setName('Candara');
$objPHPExcel->getActiveSheet()->getStyle('B1′)->getFont()->setSize(20);
$objPHPExcel->getActiveSheet()->getStyle('B1′)->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('B1′)->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
$objPHPExcel->getActiveSheet()->getStyle('B1′)->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
$objPHPExcel->getActiveSheet()->getStyle('E1′)->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
$objPHPExcel->getActiveSheet()->getStyle('D13′)->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('E13′)->getFont()->setBold(true);
设置align
$objPHPExcel->getActiveSheet()->getStyle('D11′)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle('D12′)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle('D13′)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle('A18′)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
//垂直居中
$objPHPExcel->getActiveSheet()->getStyle('A18′)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
设置column的border
$objPHPExcel->getActiveSheet()->getStyle('A4′)->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('B4′)->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('C4′)->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('D4′)->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('E4′)->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
设置border的color
$objPHPExcel->getActiveSheet()->getStyle('D13′)->getBorders()->getLeft()->getColor()->setARGB('FF993300′);
$objPHPExcel->getActiveSheet()->getStyle('D13′)->getBorders()->getTop()->getColor()->setARGB('FF993300′);
$objPHPExcel->getActiveSheet()->getStyle('D13′)->getBorders()->getBottom()->getColor()->setARGB('FF993300′);
$objPHPExcel->getActiveSheet()->getStyle('E13′)->getBorders()->getTop()->getColor()->setARGB('FF993300′);
$objPHPExcel->getActiveSheet()->getStyle('E13′)->getBorders()->getBottom()->getColor()->setARGB('FF993300′);
$objPHPExcel->getActiveSheet()->getStyle('E13′)->getBorders()->getRight()->getColor()->setARGB('FF993300′);
安装填充颜色
$objPHPExcel->getActiveSheet()->getStyle('A1′)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('A1′)->getFill()->getStartColor()->setARGB('FF808080′);
$objPHPExcel->getActiveSheet()->getStyle('B1′)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('B1′)->getFill()->getStartColor()->setARGB('FF808080′);

>>> 更多php教程内容,请关心本站php编程栏目。
加图片
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$objDrawing->setPath('.officelogo.jpg');
$objDrawing->setHeight(36);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Paid');
$objDrawing->setDescription('Paid');
$objDrawing->setPath('.paid.png');
$objDrawing->setCoordinates('B15′);
$objDrawing->setOffsetX(110);
$objDrawing->setRotation(25);
$objDrawing->getShadow()->setVisible(true);
$objDrawing->getShadow()->setDirection(45);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
在暗许sheet后,创设一个worksheet
echo date('H:i:s') . " Create new Worksheet objectn";
$objPHPExcel->createSheet();
$objWriter = PHPExcel_IOFactory::createWriter($objExcel, 'Excel5');
$objWriter-save('php://output');

本文由www.204.net发布,转载请注明来源

关键词: www.204.net