美文网首页
前端导出文件换行

前端导出文件换行

作者: 卟噜卟噜叭 | 来源:发表于2020-07-09 18:39 被阅读0次
    if (Yonlink.Export == true) {
                        $("#exportPoint").show();
                        $("#exportPoint").unbind().click(function () {
                            var _txt = "";
                            var pointIndex = [];
                            if (queryResult) {
                                for (var n = 0; n < queryResult.length; n++) {
                                    pointStr = queryResult[n].geometry.rings[0];
                                    pointIndex[n] = pointStr.length;
                                    var indexNum = 0;
                                    for (let k = 0; k < pointIndex.length - 1; k++) {
                                        indexNum += pointIndex[k];
                                    }
                                    for (var m = 0; m < pointStr.length; m++) {
                                        var xStr = pointStr[m][0].toFixed(4);
                                        var yStr = pointStr[m][1].toFixed(4);
                                        if (n > 1) {
                                            _txt += indexNum + m + 1 + "," + "0," + yStr + "," + xStr + ",0";
                                            _txt += "<br>";
                                        } else if (n == 1) {
                                            _txt += pointIndex[0] + m + 1 + "," + "0," + yStr + "," + xStr + ",0";
                                            _txt += "<br>";
                                        } else {
                                            _txt += m + 1 + "," + "0," + yStr + "," + xStr + ",0";
                                            _txt += "<br>";
                                        }
                                    }
                                }
                                var isIE = !!window.ActiveXObject || "ActiveXObject" in window;
                                if (isIE) {
                                    var strHTML = _txt
                                    var winSave = window.open();
                                    winSave.document.open("text", "utf-8");
                                    winSave.document.write(strHTML);
                                    winSave.document.execCommand("SaveAs", true, "coordinate.txt");
                                    winSave.close();
                                } else {
                                    var elHtml = _txt;
                                    var mimeType = 'text/plain';
                                    $('#createInvote').attr('href', 'data:' + mimeType + ';charset=utf-8,' + encodeURIComponent(elHtml));
                                    document.getElementById('createInvote').click();
                                }
                            }
                        })
                    }
    

    相关文章

      网友评论

          本文标题:前端导出文件换行

          本文链接:https://www.haomeiwen.com/subject/fxnscktx.html