PHP匯出EXCEL亂碼

2021-10-24 23:03:21 字數 2011 閱讀 6614

/**

* 生成excel**

* @param array $data 需要匯出的資料

* @param array tit

le帶出

資料的標

題∗@p

aram

strf

ilen

ame導

出exc

el檔案

名稱∗/

func

tion

expo

rtex

cel(

title 帶出資料的標題 * @param str filename 匯出excel檔名稱 */ function exportexcel(

title帶

出資料的

標題∗@

para

mstr

file

name

匯出ex

cel文

件名稱∗

/fun

ctio

nexp

orte

xcel

(data=array(),tit

le=a

rray

()

,title=array(),

title=

arra

y(),il

enam

e.".

xls"

);he

ader

("pr

agma

:no−

cach

e");

head

er("

expi

res:

0");

//匯出

xls開

始if(

!emp

ty

(filename.".xls"); header("pragma: no-cache"); header("expires: 0"); //匯出xls 開始 if (!empty(

filena

me."

.xls

");h

eade

r("p

ragm

a:no

−cac

he")

;hea

der(

"exp

ires

:0")

;//導

出xls

開始if

(!em

pty(

title))

$title= implode("\t", $title);

echo "$title\n";

}if (!empty($data))

$data[$key]=implode("\t", $data[$key]);

}echo implode("\n",$data);

}}在使用上述方法匯出excel的時候,有時候發現出現亂碼(機率很小),對編碼和特殊字元已處理 還是出現亂碼,後換成匯出**的樣式解決了亂碼問題

/*** 生成excel**

* @param array $data 需要匯出的資料

* @param array $title 帶出資料的標題

* @param str filename 匯出excel檔名稱

*/function exporttableexcel($data=array(),$title=array(),$filename='report')

$strtable .= '';

//匯入資料

$strtable .= '';

foreach ($data as $key => $val)

$strtable .= '';

}$strtable .='';

header('expires:0');//瀏覽器不會響應快取

header('pragma:public');//public指示響應可被任何快取區快取。

echo ''.$strtable.'';

exit();

PHP匯出excel亂碼

php匯出excel檔案時有兩個主要的過程 1 定義檔名 2 填充excel資料 這兩個過程中可能會出現一些php匯出excel亂碼問題,下面我來說一下解決辦法 解決檔名的php匯出excel亂碼 亂碼原因 客戶使用的中文版windows系統平台,而windows平台的檔名編碼為gb2312 gbk...

vue 匯出excel 亂碼

經過小女子的不懈努力,終於解決了。responsetype blob 2.呼叫介面 看後台返回的是二進位製流還是blob物件 轉化成 blob物件 2 那就方便了直接使用 let url window.url.createobjecturl res.data console.log blob var...

PHP資料匯出Excel

需要將php資料匯出exel 中,可以用phpexcel,但是也有更快的方法,但是會出現些小問題 比如 處理excel匯出 param datas array 設定 資料 param titlename string 設定head param title string 設定表頭 function e...