js json轉excel
本人在網上查詢前臺json轉excel。結果大多都是json轉scv。(不知道google結果怎麼樣)
結果試了下匯出之後用excel開啟中文還是亂碼。
最後還是參考tableExport.jquery.plugin外掛完成。
減少別人走得彎路
上程式碼
<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#wwo').click(function(){ var data = {"title":[{"value":"集團", "type":"ROW_HEADER_HEADER", "datatype":"string"}, {"value":"日期", "type":"ROW_HEADER_HEADER", "datatype":"string"}],"data":[[{"value":"好好", "type":"ROW_HEADER"}, {"value":"2015-08-24", "type":"ROW_HEADER"}]]}; if(data == '') return; JSONToExcelConvertor(data.data, "Report", data.title); }); }); function JSONToExcelConvertor(JSONData, FileName, ShowLabel) { //先轉化json var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData; var excel = '<table>'; //設定表頭 var row = "<tr>"; for (var i = 0, l = ShowLabel.length; i < l; i++) { row += "<td>" + ShowLabel[i].value + '</td>'; } //換行 excel += row + "</tr>"; //設定資料 for (var i = 0; i < arrData.length; i++) { var row = "<tr>"; for (var index in arrData[i]) { var value = arrData[i][index].value === "." ? "" : arrData[i][index].value; row += '<td>' + value + '</td>'; } excel += row + "</tr>"; } excel += "</table>"; var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>"; excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">'; excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel'; excelFile += '; charset=UTF-8">'; excelFile += "<head>"; excelFile += "<!--[if gte mso 9]>"; excelFile += "<xml>"; excelFile += "<x:ExcelWorkbook>"; excelFile += "<x:ExcelWorksheets>"; excelFile += "<x:ExcelWorksheet>"; excelFile += "<x:Name>"; excelFile += "{worksheet}"; excelFile += "</x:Name>"; excelFile += "<x:WorksheetOptions>"; excelFile += "<x:DisplayGridlines/>"; excelFile += "</x:WorksheetOptions>"; excelFile += "</x:ExcelWorksheet>"; excelFile += "</x:ExcelWorksheets>"; excelFile += "</x:ExcelWorkbook>"; excelFile += "</xml>"; excelFile += "<![endif]-->"; excelFile += "</head>"; excelFile += "<body>"; excelFile += excel; excelFile += "</body>"; excelFile += "</html>"; var uri = 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile); var link = document.createElement("a"); link.href = uri; link.style = "visibility:hidden"; link.download = FileName + ".xls"; document.body.appendChild(link); link.click(); document.body.removeChild(link); } </script> </head> <body> <input type="button" id="wwo" value="匯出" /> </body> </html>
附件是tableExport程式碼
http://download.csdn.net/detail/a410147597/9052583
相關推薦
js json轉excel
本人在網上查詢前臺json轉excel。結果大多都是json轉scv。(不知道google結果怎麼樣) 結果試了下匯出之後用excel開啟中文還是亂碼。 最後還是參考tableExport.jquery.plugin外掛完成。 減少別人走得彎路 上程式碼 <html
問題集錄--jquery將json轉excel保持
ros ring com display idl != html nco move 代碼如下: <html> <head> <meta http-equiv="content-type" content="text/html;
JSON轉EXCEL Python
reload add str turn lis tde def div bsp 具體參數根據實際情況調整 1 # -*- coding: utf-8 -* 2 import json 3 import xlwt 4 import os 5 import sys
JSON轉Excel
one excel export download obj -o 下載 ade eth 1.引入js (dist目錄下JsonExportExcel.min.js) <script src="https://cuikangjie.github.io/JsonExpo
TXT轉json,轉Excel
轉Excel using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; using UnityEngine; using Ex
【web前端】js json轉陣列,陣列轉json,字串轉數字
,學習記錄 //陣列轉json串 var arr = [1,2,3, { a : 1 } ]; JSON.stringify( arr ); //json字串轉陣列 var jsonStr =
js json轉string string轉json
<script type="text/javascript" src="./json2.js"></script> <script type="text/javascript"n> //把json 字串轉換成物件 var string
JSON轉EXCEL程式碼( java)
依賴 <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId>
淺析ajax請求json數據並用js解析 [轉]
set gif .ajax -1 pen 技術分享 hide asc spa <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-
js 數組轉json,json轉數組
數組 stringify json字符串 style js 數組 arr pan code spa //數組轉json串 var arr = [1,2,3, { a : 1 } ]; JSON.stringify( arr ); //json字符串轉數組 var jso
JSON轉JS對象,JS對象轉JSON
ger get nvi 調用 方法 add 實體 per 轉字符串 一、從服務端發來的json字符串,怎麽才能作為JavaScript對象(JSON對象)在web端調用呢?1、如果使用jQuery,就很方便了,可以在ajax一系列函數中,把參數Datatype傳json即可
js 數組、對象轉json 以及json轉 數組、對象
bar con bject arr clas js對象 技術 info http 1、JS對象轉JSON 方式:JSON.stringify(obj) var json = {"name":"iphone","price":666}; //創建對象; var json
Json文件轉Excel
src sin 項目 table files 讀取 write lis exp 先創建一個web項目,在根目錄放置需要轉換的json文件,直接讀取靜態Json文件加載數據進行轉換,代碼如下: string Json = string.Empty;
利用js-xlsx.js外掛實現Excel檔案匯入並解析Excel資料成json資料格式
<!--本文轉載於網路,有太多一樣的文章,不知道原作者是哪位了,就不註明出處了。這裡記載下來,用於自己的學習借鑑--><!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8">
js json字串轉物件
1.JSON.parse() 在網上找json字串轉物件的方法 主要是:JSON.parse(str) 但我發現這個方法有很大的侷限性 var jsonStr = '{"key":"value"}'; var jsonStr1 = '
JS Array轉JSON
如果是這樣: var params = new Array(); params["item1"] = $("#val1").val(); var paramsJson = JSO
js Json value 值 轉 大小寫
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/java
Java POI JSON陣列轉EXCEL
JSON陣列轉EXCEL,自定義動態生成表頭 public static void createExcel(String[] heads,JSONArray jsonArray ,String uplo
js 陣列轉json,json轉陣列
//陣列轉json串 var arr = [1,2,3, { a : 1 } ]; JSON.stringify( arr ); //json字串轉陣列 var jsonStr = '[1,2,3,{
Json格式轉 Excel檔案的Java原始碼
由於工作中與我們對接的部門不懂技術需要我們將Json格式的資料轉換成Excel文件提供給她們進行資料分析,其實使用到的技術並不複雜就是Apache poi的一個簡單應用,之所以我要分享出來是因為這個工具類比較實用,有相同需求的小夥伴可以直接引入此類配置Json檔案所在的路徑和