<?php
/**
*導出到CSV文件
*/
function export_csv($data = '', $filename = '') {
$filename = empty ( $filename ) ? date ( 'YmdHis' ) . ".csv" : $filename . ".csv";
header ( "Content-type:text/csv" );
header ( "Content-Disposition:attachment;filename=" . $filename );
header ( 'Cache-Control:must-revalidate,post-check=0,pre-check=0' );
header ( 'Expires:0' );
header ( 'Pragma:public' );
echo array_to_string ( $data );
}
/**
*導出數據轉換
*/
function array_to_string($result) {
$data = '';
foreach ( $result as $v ) {
$line = '';
foreach ( $v as $vo ) {
$line .= i ( $vo ) . ',';
}
$line = rtrim ( $line, ',' );
$data .= $line . "\n";
}
return $data;
}
/**
* *編碼轉換
* @param <type> $strInput
* @return <type>
*/
function i($strInput) {
if (is_string ( $strInput )) {
// if(strstr($strInput, '"'))
$strInput = str_replace ( ',', ',', $strInput );
// else
// $strInput = '"'.$strInput.'"';
}
return iconv ( 'utf-8', 'gbk//IGNORE', $strInput ); // 頁面編碼為utf-8時使用,否則導出的中文為亂碼
}
/*
* 導出數據
*/
public function outExcel($dataArr, $fileName = '', $sheet = false) {
require_once VENDOR_PATH . 'download-xlsx.php';
export_csv ( $dataArr, $fileName, $sheet );
unset ( $sheet );
unset ( $dataArr );
}
?>
*