百度关键词优化三天上首页!同行都是朋友, 欢迎一起互利共赢。谢绝一切非正规行业服务,感谢以下同行、团队、平台和代理的支持:

百度站长平台、MIP开发小组、SEO焦大老友、SEO每天一贴ZAC大哥、卢松松大哥、海瑶SEO兄弟、附子SEO兄弟、探索者SEO、帮站SEO好友、互点宝、超快排平台

百亿互刷宝、下拉天下、SEO自学网、SEO研究中心、小明SEO、王德春SEO、马海祥博客、踏雪无痕挂机工作室、SEO云优化好友、云客网、杭州思亿欧、网赚吧、北京SEO韩非老弟

需要了解以上同仁的相关信息,我们已经给你做好了搜索框,看右上角绿色那个,输入搜索即刻直达

网站统计: 共有读稿:14367部 / 今日更新:1篇 / 评论:12条 / 会员:48 名 / 阅读:382492
您好,请 【登陆】【注册】
文章页横幅广告
您现在的位置:SEO平台 > PHP网站建设 >

PHPExcel导出2003和2007的excel文档功能示例

2017.02.07

浏览:

【导语】如果您觉得本篇内容还不错,请点击文章下面的赞,然后分享给朋友哦!...

PHPExcel导出2003和2007的excel文档功能示例-破洛洛教学网...请看详情...

seo

seo

本文实例讲述了PHPExcel导出2003和2007的excel文档功能。分享给大家供大家参考,具体如下:

require_once 'common/excel/PHPExcel.php';
require_once 'common/excel/phpExcel/Writer/Excel2007.php';
require_once 'common/excel/phpExcel/Writer/Excel5.php';
include_once 'common/excel/phpExcel/IOFactory.php';
$objExcel = new PHPExcel();
//设置属性 (这段代码无关紧要,其中的内容可以替换为你需要的)
$objExcel->getProperties()->setCreator("andy");
$objExcel->getProperties()->setLastModifiedBy("andy");
$objExcel->getProperties()->setTitle("Office 2003 XLS Test Document");
$objExcel->getProperties()->setSubject("Office 2003 XLS Test Document");
$objExcel->getProperties()->setDescription("Test document for Office 2003 XLS, generated using PHP classes.");
$objExcel->getProperties()->setKeywords("office 2003 openxml php");
$objExcel->getProperties()->setCategory("Test result file");
$objExcel->setActiveSheetIndex(0);
$i=0;
//表头
$k1="编号";
$k2="推广代码";
$k3="访问来源";
$k4="IP";
$k5="访问时间";
$objExcel->getActiveSheet()->setCellValue('a1', "$k1");
$objExcel->getActiveSheet()->setCellValue('b1', "$k2");
$objExcel->getActiveSheet()->setCellValue('c1', "$k3");
$objExcel->getActiveSheet()->setCellValue('d1', "$k4");
$objExcel->getActiveSheet()->setCellValue('e1', "$k5");
//debug($links_list);
foreach($links_list as $k=>$v) {
  $u1=$i+2;
  /*----------写入内容-------------*/
  $objExcel->getActiveSheet()->setCellValue('a'.$u1, $v["id"]);
  $objExcel->getActiveSheet()->setCellValue('b'.$u1, $v["num"]);
  $objExcel->getActiveSheet()->setCellValue('c'.$u1, $v["referer"]);
  $objExcel->getActiveSheet()->setCellValue('d'.$u1, $v["ip"]);
  $objExcel->getActiveSheet()->setCellValue('e'.$u1, $v["dateline"]);
  $i++;
}
// 高置列的宽度
$objExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
$objExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
$objExcel->getActiveSheet()->getColumnDimension('C')->setWidth(70);
$objExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
$objExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
$objExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&BPersonal cash register&RPrinted on &D');
$objExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $objExcel->getProperties()->getTitle() . '&RPage &P of &N');
// 设置页方向和规模
$objExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
$objExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
$objExcel->setActiveSheetIndex(0);
$timestamp = time();
if($ex == '2007') { //导出excel2007文档
  header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  header('Content-Disposition: attachment;filename="links_out'.$timestamp.'.xlsx"');
  header('Cache-Control: max-age=0');
  $objWriter = PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
  $objWriter->save('php://output');
  exit;
} else { //导出excel2003文档
  header('Content-Type: application/vnd.ms-excel');
  header('Content-Disposition: attachment;filename="links_out'.$timestamp.'.xls"');
  header('Cache-Control: max-age=0');
  $objWriter = PHPExcel_IOFactory::createWriter($objExcel, 'Excel5');
  $objWriter->save('php://output');
  exit;
}


0
赞一个
关键词:
☆喜欢这篇文章吗?分享给你的好友吧!点击这里复制网址☆
共有1人阅读,期待你的评论!评论
请先登陆后才能发表评论哦!没账号?赶紧注册一个吧!
最新评论
热门标签
回到顶部