`
ljqian
  • 浏览: 6790 次
  • 性别: Icon_minigender_1
  • 来自: 常熟
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
导出word格式 php, word, 导出
/**
 * 文件导出为word格式
 * @param string $filname             //输出的文件名
 * @param string $type                //编码类型
 * @param string $array              //excel的标题
 * @param string $data               //需要的数据data
 * eg.exportExcel(test, 'utf-8', array('测试','OK'),array(array('ceshishuju1','OK1'),array('ceshi2','OK2'),array('ceshi3',''),array('','OK4')));
 */
function exportWord($filename, $type = 'utf-8', $array, $data){
	header( "Pragma: public" );  
	header( "Expires: 0" ); // set expiration time  
	header( "Cache-Component: must-revalidate, post-check=0, pre-check=0" );  
	header( "Content-type:application/msword");  
	$filename=rawurldecode($filename);
	$filename=iconv("UTF-8","gb2312//IGNORE",$filename);
	header( 'Content-Disposition: attachment; filename="'.$filename.'"' );
	header( 'Content-Transfer-Encoding: binary' );
	echo '<html xmlns:v="urn:schemas-microsoft-com:vml"
			xmlns:o="urn:schemas-microsoft-com:office:office"
			xmlns:w="urn:schemas-microsoft-com:office:word">';
	echo "<META HTTP-EQUIV='Content-Type' CONTENT='text/html;charset=$type'>";
	echo '<table border="1" cellspacing="1" cellpadding="1"><tr align="center">';
	foreach ($array as $val) {
		echo "<td width='100'>$val</td>";
    }
    echo '</tr>';
    foreach ($data as $val) {
    	if(is_array($val)){
    		echo '<tr align="center">';
    	    foreach ($val as $v) {
    	    	echo '<td width="120" height="30">' . $v . '</td>';
            }
            echo '</td>';
		}else {
			echo '<tr align="center">';
			echo '<td width="120" height="30">' . $val . '</td>';
			echo '</td>';
		}
	}
	echo $html;
	echo '</html>';
	exit;
}
Global site tag (gtag.js) - Google Analytics