Projects in iOS display XLS and xlsx easily, using the following code can be, but Android is more troublesome, in order to unify processing, select Excel save CSV to parse the display table.
Https://developer.apple.com/library/ios/qa/qa1630/_index.html func loaddocument (documentname:string, Webview:uiwebview) {let path:string = Nsbundle.mainbundle (). Pathforresource (DocumentName, Oftype:nil)!; Let Url:nsurl = Nsurl (fileurlwithpath:path) let request:nsurlrequest = Nsurlrequest (url:url) Webview.loadrequest (Request) }
Using D3.js to parse the server's CSV file, but D3 parse out is the Key-value array, because the content is changed, so I directly use the return value, and then I parse
function response (Request) { return request.responsetext;//dsv.parse (Request.responsetext);}
One problem is that if you don't handle it, the CSV file that is turned out is the ANSI encoded JS direct fetch is garbled, so use D3 when you need to set the following:
function Callpase () { var csv = D3.DSV (",", "text/csv;charset=gb2312"); CSV ("Http://7xnhdv.com1.z0.glb.clouddn.com/test.csv", function (error,csvdata) { gentable (csvdata); });
use GetTable method parsing to generate tables after getting data
function gentable (param) { var isarray=param instanceof Array; var html = ""; var data=null; if (IsArray) {//array directly with Data=param; } Else{//csv strings are converted to arrays data=new Array (); var lines=param.split (' \ r \ n '); for (Var i=0;i<lines.length;i++) { var cells=lines[i].split (', '); Data.push (cells); } } var Table = document.getElementById ("TableId"); for (Var i=0;i<data.length;i++) { var NewRow = Table.insertrow (); Add row var cells=data[i]; for (Var j=0;j<cells.length;j++) { var newcell= newrow.insertcell (); newcell.innerhtml = Cells[j]; NewCell.style.height = "20px";}} }
The effect is as follows:
Full HTML code:
<! DOCTYPE html>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
WebView Show CSV