导出xml格式的文件

前端之家收集整理的这篇文章主要介绍了导出xml格式的文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//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 ();
	}

猜你在找的XML相关文章