当前位置:  编程技术>php
本页文章导读:
    ▪PHP导出EXCEL的简单范例 使用phpexcel类库导出excel      使用phpexcel 类库(1.7.5版)导出excel。 例子:   代码示例: <?php /* * phpexcel导出excel文件 * edit: www. */ error_reporting(E_ALL); date_default_timezone_set('Europe/London'); require_once 'Classes/PHPExcel.php'; $o.........
    ▪php简单日历的实现代码(可绑定事件)      php实现的简单日历代码。 例子:   代码示例: <?php /** * php简单日历 * edit: www. */ if(empty($year))$year=date("Y"); //初始化年份 if(empty($month))$month=date("n"); //初始化月份 $wd_ar=array("日","一",".........
    ▪phpExcel类的使用方法分享      1,phpexcel的简单示例   代码示例: include ‘PHPExcel.php'; include ‘PHPExcel/Writer/Excel2007.php'; //或者include ‘PHPExcel/Writer/Excel5.php'; 用于输出.xls的 创建一个excel $objPHPExcel = new PHPExcel(); 保存exc.........

[1]PHP导出EXCEL的简单范例 使用phpexcel类库导出excel
    来源: 互联网  发布时间: 2013-12-24

使用phpexcel 类库(1.7.5版)导出excel。
例子:
 

代码示例:

<?php
/*
* phpexcel导出excel文件
* edit: www.
*/
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');
require_once 'Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
//设置属性
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
        ->setLastModifiedBy("Maarten Balliauw")
        ->setTitle("Office 2007 XLSX Test Document")
        ->setSubject("Office 2007 XLSX Test Document")
        ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
        ->setKeywords("office 2007 openxml php")
        ->setCategory("Test result file");

// 添加一些数据
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', iconv('gbk', 'utf-8', '中文Hello'))
            ->setCellValue('B2', 'world!')
            ->setCellValue('C1', 'Hello')
            ->setCellValue('D2', 'world!');
// Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A4', 'Miscellaneous glyphs')
            ->setCellValue('A5', '11111');
// 修改sheet名称
$objPHPExcel->getActiveSheet()->setTitle('Simple');

// 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)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
?>

您可能感兴趣的文章:
PHPExcel常用方法举例
phpExcel类的使用方法分享
phpexcel导出excel的经典实例
PHPExcel读取excel文件的例子
phpexcel类库实例 支持(excel2003 excel2007)
phpexcel导出数据的实例代码
phpexcel导入excel到数据库的代码
phpexcel快速开发指南(不错)
phpExcel中文帮助手册(知识点)
使用PHPExcel判别和格式化Excel中的日期格式的例子
phpexcel导出excel的颜色与网页中颜色不一致的解决方法
CI中使用PHPExcel导出数据到Excel


    
[2]php简单日历的实现代码(可绑定事件)
    来源: 互联网  发布时间: 2013-12-24

php实现的简单日历代码。
例子:
 

代码示例:
<?php
/**
* php简单日历
* edit: www.
*/
if(empty($year))$year=date("Y"); //初始化年份
if(empty($month))$month=date("n"); //初始化月份
$wd_ar=array("日","一","二","三","四","五","六"); //星期数组
$wd=date("w",mktime(0,0,0,$month,1,$year)); //当月第一天是星期几
//年链接
$y_lnk1=$year<=1970?$year=1970:$year-1;
$y_lnk2=$year>=2037?$year=2037:$year+1;
//月链接
$m_lnk1=$month<=1?$month=1:$month-1;
$m_lnk2=$month>=12?$month=12:$month+1;
echo <<< EOT
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#00FF00" width="600" bgcolor="#eeeeee"> <tr align="center" bgcolor="#cccccc">
<td colspan="4" height="35"><a href="/blog_article/$php_self/year/$y_lnk1/amp;month/$month.html"><</a> $year 年 <a href="/blog_article/$php_self/year/$y_lnk2/amp;month/$month.html">></a></td>
<td colspan="3" height="35"><a href="/blog_article/$php_self/year/$year/amp;month/$m_lnk1.html"><</a> $month 月 <a href="/blog_article/$php_self/year/$year/amp;month/$m_lnk2.html">></a></td> </tr> <tr align="center">
EOT;
for($i=0;$i<7;$i++) {
print "<td height=35>$wd_ar[$i]</td> ";
}
print "</tr> ";
$tnum=$wd+date("t",mktime(0,0,0,$month,1,$year));
for($i=0;$i<$tnum;$i++) {
$date=$i+1;
if($i%7==0) print '<tr align="center">';
print '<td height="75">';
if($i>=$wd) print $date-$wd;
print "</td> ";
if($i%7==6) print "</tr> ";
}
if($i%7<6 && $i%7>0) print '<td colspan="".(7-$i%7).""></td> </tr> ';
if($i%7==6) print "<td></td> </tr> ";
print '</table>';
?>

很简单吧,以上就是本节介绍的php日历代码,实现了基本日历的一些功能:年份、月份、日期、星期的显示。


    
[3]phpExcel类的使用方法分享
    来源: 互联网  发布时间: 2013-12-24

1,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");

2,直接输出到浏览器
 

代码示例:

$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');

3,设置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");

4,其它
 

代码示例:
设置当前的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′);
加图片 //www.
$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');

您可能感兴趣的文章:
PHPExcel常用方法举例
PHP导出EXCEL的简单范例 使用phpexcel类库导出excel
phpexcel导出excel的经典实例
PHPExcel读取excel文件的例子
phpexcel类库实例 支持(excel2003 excel2007)
phpexcel导出数据的实例代码
phpexcel导入excel到数据库的代码
phpexcel快速开发指南(不错)
phpExcel中文帮助手册(知识点)
使用PHPExcel判别和格式化Excel中的日期格式的例子
phpexcel导出excel的颜色与网页中颜色不一致的解决方法
CI中使用PHPExcel导出数据到Excel


    
最新技术文章:
▪PHP函数microtime()时间戳的定义与用法
▪PHP单一入口之apache配置内容
▪PHP数组排序方法总结(收藏)
▪php数组排序方法大全(脚本学堂整理奉献)
▪php数组排序的几个函数(附实例)
▪php二维数组排序(实例)
▪php根据键值对二维数组排序的小例子
▪php验证码(附截图)
▪php数组长度的获取方法(三个实例)
▪php获取数组长度的方法举例
▪判断php数组维度(php数组长度)的方法
▪php获取图片的exif信息的示例代码
▪PHP 数组key长度对性能的影响实例分析
▪php函数指定默认值的方法示例
▪php提交表单到当前页面、提交表单后页面重定...
▪php四舍五入的三种实现方法
▪php获得数组长度(元素个数)的方法
▪php日期函数的简单示例代码
▪php数学函数的简单示例代码
▪php字符串函数的简单示例代码
▪php文件下载代码(多浏览器兼容、支持中文文...
▪php实现文件下载、支持中文文件名的示例代码...
▪php文件下载(防止中文文件名乱码)的示例代码
▪解决PHP文件下载时中文文件名乱码的问题
▪php数组去重(一维、二维数组去重)的简单示例
▪php小数点后取两位的三种实现方法
▪php Redis 队列服务的简单示例
▪PHP导出excel时数字变为科学计数的解决方法
▪PHP数组根据值获取Key的简单示例
▪php数组去重的函数代码示例
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

▪PHP函数microtime()时间戳的定义与用法 iis7站长之家