js 實現純前端將資料匯出excel

2021-09-08 14:11:00 字數 1079 閱讀 7806

通過將json遍歷進行字串拼接,將字串輸出到csv檔案,輸出的檔案不會再是html型別的檔案而是真正的csv檔案,**如下

<

html

>

<

head

>

<

p style

="font-size: 20px;color: red;"

>使用a標籤方式將json匯出csv檔案

p>

<

button

onclick

='tabletoexcel()'

>匯出

button

>

head

>

<

body

>

<

script

>

function

tabletoexcel(),,,

,]

//列標題,逗號隔開,每乙個逗號就是隔開乙個單元格

let str

=`姓名,**,郵箱\n`;

//增加\t為了不讓**顯示科學計數法或者其他格式

for(let i =0

; i

<

jsondata.length ; i

++),`;

}str+='

\n'; }

//encodeuricomponent解決中文亂碼

let uri ='

data:text/csv;charset=utf-8,\ufeff'+

encodeuricomponent(str);

//通過建立a標籤實現

varlink

=document.createelement("a

");link.href

=uri;

="json資料表.csv";

link.click();

document.body.removechild(link);

}script

>

body

>

html

>

js 實現純前端將資料匯出excel兩種方式

部落格參考 primary plain click ex 匯出 el button ex 通過post方式匯出檔案 param key 請求定義靜態位址 param data 請求引數 return 返回promise物件 letpostfileexport key,data,params,base...

C 將DateTable表資料匯出到Excel中

在visual c 中呼叫excel 並不像讀取excel 中的資料那麼容易了,因為在visual c 中呼叫excel 要使用到excel的com元件。以vs2005為例,首先新增引用 在com選項中,新增microsfot excel 11.0 objet library。然後在程式中引入命名空...

用Python將mysql資料匯出成json

1 相關說明 此指令碼可以將mysql的資料匯出成json格式,匯出的內容可以進行select查詢確定。資料傳入引數有 dbconfigname,selectsql,jsonpath,filename。依賴的庫有 mysqldb json,尤其mysqldb需要事先安裝好。2 python指令碼及測...