导出xml格式的文件
发布时间:2020-12-16 05:18:20 所属栏目:百科 来源:网络整理
导读://ExportExcelLib.php ?php/** * Simple excel generating from PHP5 * * @package Utilities * @license http://www.opensource.org/licenses/mit-license.php * @author Oliver Schwarz oliver.schwarz@gmail.com * @version 1.0 *//** * Generating excel
//ExportExcelLib.php <?php /** * Simple excel generating from PHP5 * * @package Utilities * @license http://www.opensource.org/licenses/mit-license.php * @author Oliver Schwarz <oliver.schwarz@gmail.com> * @version 1.0 */ /** * Generating excel documents on-the-fly from PHP5 * * Uses the excel XML-specification to generate a native * XML document,readable/processable by excel. * * @package Utilities * @subpackage Excel * @author Oliver Schwarz <oliver.schwarz@vaicon.de> * @version 1.1 * * @todo Issue #4: Internet Explorer 7 does not work well with the given header * @todo Add option to give out first line as header (bold text) * @todo Add option to give out last line as footer (bold text) * @todo Add option to write to file */ class ExportExcelLib { public function addArray($info) { $i = 0; $newInfo = array (); foreach ( $info as $key => $value ) { $j = 0; foreach ( $value as $key2 => $value2 ) { $newInfo [$i] [$j] = $value2; $j ++; } $i ++; } return $newInfo; } public function generateXML($name,$info) { error_reporting ( E_ALL ); date_default_timezone_set ( 'Europe/London' ); /** PHPExcel */ require_once 'PHPExcel.php'; // Create new PHPExcel object $objPHPExcel = new PHPExcel (); // Set properties $objProps = $objPHPExcel->getProperties (); $objProps->setCreator ( "Maarten Balliauw" ); $objProps->setLastModifiedBy ( "Maarten Balliauw" ); $objProps->setTitle ( "Office 2003 XLS Test Document" ); $objProps->setSubject ( "Office 2003 XLS Test Document" ); $objProps->setDescription ( "Test document for Office 2003 XLS,generated using PHP classes." ); $objProps->setKeywords ( "office 2003 openxml php" ); $objProps->setCategory ( "Test result file" ); $zi = 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' ); // Add some data foreach ( $info as $key => $value ) { foreach ( $value as $key2 => $value2 ) { $objPHPExcel->setActiveSheetIndex ( 0 )->setCellValue ( $zi [$key2] . ($key+1),$value2 ); } } // Rename 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 (Excel2007) header ( 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ); $name=iconv("utf-8","gb2312",$name); header ( 'Content-Disposition: attachment;filename="'.$name.'.xls"' ); header ( 'Cache-Control: max-age=0' ); $objWriter = PHPExcel_IOFactory::createWriter ( $objPHPExcel,'Excel5' ); $objWriter->save ( 'php://output' ); exit (); } } ?> /** * 英文过期域名导出成excel文件 * @param unknown_type $data */ public function expiredEnDomainExport($data) { $fileName = '过期域名导出列表_' . date ( "YmdHis" ) . rand ( 100,999 ); $info[0]=array ('域名','域名长度','系统分组','原注册日期','后缀','删除日期','是否推荐'); foreach ( $data as $v ) { $temp = array(); $temp[] = $v['DomainName']; $temp[] = $v['DomainLength']; $temp[] = $v['SystemGroup']; $temp[] = $v['LastRegDate']; $temp[] = $v['DomainTLD']; $temp[] = $v['DelDate']; $temp[] = $v['isRecommend']; $info[] = $temp; } require SYSTEM_LIB_PATH . 'lib/extra/excel/ExportExcelLib.php'; $xls = new ExportExcelLib (); $newInfo=$xls->addArray ( $info ); $xls->generateXML ( $fileName,$newInfo ); exit (); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |