资源介绍
1.获取PHPExcel
2.添加如下方法:
function Excel_Export($filename,$data,$sheet){
error_reporting(E_ALL);
ini_set('display_errors','On');
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../Classes/');
/** PHPExcel */
include 'api/excel/PHPExcel.php';
/** PHPExcel_Writer_Excel2007 */
include 'api/excel/PHPExcel/Writer/Excel2007.php';
// Create new PHPExcel object
//echo date('H:i:s') . "Create new PHPExcel object\n";
$objPHPExcel = new PHPExcel();
// Set properties
//echo date('H:i:s') . "Set properties\n";
$objPHPExcel->getProperties()->setCreator("E421083458");
$objPHPExcel->getProperties()->setLastModifiedBy("E421083458");
$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");
// Add some data
//echo date('H:i:s') . "Add some data\n";
$objPHPExcel->setActiveSheetIndex(0);
$charlist = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
//print_r($data);
foreach($data as $key=>$value){
$j=0;
if($key==0){
foreach($value as $k=>$v){
if($j<25){
$objPHPExcel->getActiveSheet()->setCellValue($charlist[$j].($key+1), mb_convert_encoding($k, "UTF-8", "GBK"));
$j++;
}
}
$j=0;
}
foreach($value as $k=>$v){
if($j<25){
//echo $charlist[$j].($key+1)."
"; //echo $v."
"; $objPHPExcel->getActiveSheet()->setCellValue($charlist[$j].($key+2), mb_convert_encoding($v, "UTF-8", "GBK")); $j++; } } } // Rename sheet //echo date('H:i:s') . "Rename sheet\n"; $objPHPExcel->getActiveSheet()->setTitle(mb_convert_encoding($sheet, "UTF-8", "GBK")); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Save Excel 2007 file echo date('H:i:s') . "Write to Excel2007 format\n"; echo $filename; print_r($objPHPExcel); $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); $objWriter->save($filename); // Echo done echo date('H:i:s') . "Done writing file.\r\n"; } 3.调用生成excel: if($table=='destoon_member'){ $itemids = is_array($userid) ? implode(',', $userid) : $userid; $sgender = array('性别', '先生' , '女士'); $sprofile = array('资料', '已完善' , '未完善'); $semail = array('邮件', '已认证' , '未认证'); $smobile = array('手机', '已认证' , '未认证'); $struename = array('实名', '已认证' , '未认证'); $sbank = array('银行', '已认证' , '未认证'); $scompany = array('公司', '已认证' , '未认证'); $strade = array($DT['trade_nm'], '已认证' , '未认证'); $result = $db->query("SELECT * FROM destoon_member,destoon_company WHERE destoon_member.userid = destoon_company.userid AND destoon_member.userid IN ($itemids) ORDER BY destoon_member.userid desc"); $rs = $db->query("SELECT * FROM destoon_member_group"); while($r = $db->fetch_array($rs)) { $grouplist[] = $r; } while($r = $db->fetch_array($result)) { $s['用户名'] = $r['username']; $s['公司'] = $r['company']; $s['资金'] = $r['money']; $s['积分'] = $r['credit']; $s['短信'] = $r['sms']; $s['性别'] = $sgender[$r['gender']]; $s['会员组'] = $grouplist[$r['groupid']]['groupname']; if($r['regtime']!="0"){ $s['注册时间'] = timetodate($r['regtime'], 5); } else{ $s['注册时间'] = ""; } if($r['logintime']!="0"){ $s['最后登录'] = timetodate($r['logintime'], 5); } else{ $s['最后登录'] = ""; } $s['登录次数'] = $r['logintimes']; switch ($r['groupid']){ case 4: $s['状态'] = '待审核'; break; case 6: $s['状态'] = '初审通过'; break; case 8: $s['状态'] = '已经通过审核'; break; default: $s['状态'] = '未知状态'; } $lists[] = $s; } //print_r($lists); $filename = $D.'export_mall.xlsx'; Excel_Export($filename,$lists,"mall_count"); }
"; //echo $v."
"; $objPHPExcel->getActiveSheet()->setCellValue($charlist[$j].($key+2), mb_convert_encoding($v, "UTF-8", "GBK")); $j++; } } } // Rename sheet //echo date('H:i:s') . "Rename sheet\n"; $objPHPExcel->getActiveSheet()->setTitle(mb_convert_encoding($sheet, "UTF-8", "GBK")); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Save Excel 2007 file echo date('H:i:s') . "Write to Excel2007 format\n"; echo $filename; print_r($objPHPExcel); $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); $objWriter->save($filename); // Echo done echo date('H:i:s') . "Done writing file.\r\n"; } 3.调用生成excel: if($table=='destoon_member'){ $itemids = is_array($userid) ? implode(',', $userid) : $userid; $sgender = array('性别', '先生' , '女士'); $sprofile = array('资料', '已完善' , '未完善'); $semail = array('邮件', '已认证' , '未认证'); $smobile = array('手机', '已认证' , '未认证'); $struename = array('实名', '已认证' , '未认证'); $sbank = array('银行', '已认证' , '未认证'); $scompany = array('公司', '已认证' , '未认证'); $strade = array($DT['trade_nm'], '已认证' , '未认证'); $result = $db->query("SELECT * FROM destoon_member,destoon_company WHERE destoon_member.userid = destoon_company.userid AND destoon_member.userid IN ($itemids) ORDER BY destoon_member.userid desc"); $rs = $db->query("SELECT * FROM destoon_member_group"); while($r = $db->fetch_array($rs)) { $grouplist[] = $r; } while($r = $db->fetch_array($result)) { $s['用户名'] = $r['username']; $s['公司'] = $r['company']; $s['资金'] = $r['money']; $s['积分'] = $r['credit']; $s['短信'] = $r['sms']; $s['性别'] = $sgender[$r['gender']]; $s['会员组'] = $grouplist[$r['groupid']]['groupname']; if($r['regtime']!="0"){ $s['注册时间'] = timetodate($r['regtime'], 5); } else{ $s['注册时间'] = ""; } if($r['logintime']!="0"){ $s['最后登录'] = timetodate($r['logintime'], 5); } else{ $s['最后登录'] = ""; } $s['登录次数'] = $r['logintimes']; switch ($r['groupid']){ case 4: $s['状态'] = '待审核'; break; case 6: $s['状态'] = '初审通过'; break; case 8: $s['状态'] = '已经通过审核'; break; default: $s['状态'] = '未知状态'; } $lists[] = $s; } //print_r($lists); $filename = $D.'export_mall.xlsx'; Excel_Export($filename,$lists,"mall_count"); }
- 上一篇: cef_binary32位
- 下一篇: cef浏览器内核使用