名站网址导航为大家免费提供关于网站编程方面的知识。
比较全面的PhP数组的使用方法小结-PhPphp技巧
- 本篇文章的具体介绍如下请大家仔细看
下载地址:http://www.codeplex.com/PhPExcel
下面是总结的几个使用方法
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');
――――――――――――――――――――――――――――――――――――――�C
设置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");
――――――――――――――――――――――――――――――――――――――�C
设置当前的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′);
加图片
$objDrawing = new PhPExcel_Worksheet_Drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$objDrawing->setPath('./images/officelogo.jpg');
$objDrawing->setheight(36);
$objDrawing->setWorksheet($objPhPExcel->getActiveSheet());
$objDrawing = new PhPExcel_Worksheet_Drawing();
$objDrawing->setName('Paid');
$objDrawing->setDescription('Paid');
$objDrawing->setPath('./images/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');
关于网站编程方面的知识就说道这里了,希望能够对大家有作用。,