1、mammo(word.docx)
var url = url; var xhr = new XMLHttpRequest (); xhr. open("get ", url,true); x = "blob"; //添加请求头 //获取cookie里的 token x (" access-token", getCookie('access-t oken')); xhr. onload = function ( { if atus == 200){ var blob = ; //流读取 readFileInputEventAsArrayBuffer (blob); $('#wordJS').show(); } }; x(); function displayResult (result) { //读取后的blob 转换赋值为html let html = result. value ; let newHTML = (/ /g, ' ') .replace('<h1>', '<h1>') .replace( /<table>/g,'<table>') .replace(/<tr>/g, '<tr>') .replace( /<td>/g, '<td>') .replace(/<p>/g, '<p>'); document.getElementById("wordoutput " ) .innerHTML = newHTML; } function readFileInputEventAsArrayBuffer (excelBlob) { var reader = new FileReader(: reader. onload = function (loadEvent) { var arrayBuffer = loadEvent. target. result; try{ //进行读取 mamoth. convertToHtml({ arrayBuffer: arrayBuffer } ).then (displayResult).done(); }catch(err) { con('格式错误!'); } reader. readAsArr ayBuffer (excelB1ob) ; }
2、xl(excel.xlsx)
//url文件地址 var url = url; var xhr = new XMLHttpRequest(); x("get", url, true); x = "blob"; //添加请求头 x("access-token", getCookie('access-token')); x = function () { if atus == 200) { var blob = ; readFileInputEventAsArrayBuffer(blob); } }; x(); function readFileInputEventAsArrayBuffer(file){ const reader = new FileReader(); reader.readAsBinaryString(file); reader.onload = (e) => { const data = e.; const zzexcel = window.XLSX.read(data, { type: 'binary'}); const result = []; for (let i = 0; i < zzexcel.S; i++) { const newData = window.XLSX.u[zzexcel.SheetNames[i]]); re(...newData) } //将数据存起来,将excel读取为数组 dataExcel = result; } }
3、(embed)
!function(root, factory) { "function" == typeof define && de ? define([], factory) : "object" == typeof module && module.exports ? module.exports = factory() : root.PDFObject = factory() }(this, function() { "use strict"; if ("undefined" == typeof window || void 0 === window.navigator || void 0 === window.naviga || void 0 === window.naviga) return !1; let nav = window.navigator , ua = window.naviga , isIE = "ActiveXObject"in window , isModernBrowser = void 0 !== window.Promise , supportsPdfMimeType = void 0 !== nav.mimeTypes["application/pdf"] , isMobileDevice = void 0 !== nav.platform && "MacIntel" === nav.platform && void 0 !== nav.maxTouchPoints && nav.maxTouchPoints > 1 || /Mobi|Tablet|Android|iPad|iPhone/.test(ua) , isSafariDesktop = !isMobileDevice && void 0 !== nav.vendor && /Apple/.te) && /Safari/.test(ua) , isFirefoxWithPDFJS = !!(!isMobileDevice && /irefox/.test(ua) && ua.split("rv:").length > 1) && parseIn("rv:")[1].split(".")[0], 10) > 18 , createAXO = function(type) { var ax; try { ax = new ActiveXObject(type) } catch (e) { ax = null } return ax } , supportsPDFs = !isMobileDevice && (isModernBrowser || isFirefoxWithPDFJS || supportsPdfMimeType || isIE && !(!createAXO("AcroPDF.PDF") && !createAXO("PDF.PdfCtrl"))) , embedError = function(msg, suppressConsole) { return suppressConsole || con("[PDFObject] " + msg), !1 } , emptyNodeContents = function(node) { for (; node.firstChild; ) node.removeChild) } , generatePDFJSMarkup = function(targetNode, url, pdfOpenFragment, PDFJS_URL, id, title, omitInlineStyles) { emptyNodeContents(targetNode); let fullURL = PDFJS_URL + "?file=" + encodeURIComponent(url) + pdfOpenFragment , div = document.createElement("div") , iframe = document.createElement("iframe"); return i = fullURL, i = "pdfobject", i = "application/pdf", i = "0", i = "fullscreen", i = title, id && = id), omitInlineStyles || = "position: absolute; top: 0; right: 0; bottom: 0; left: 0;", i = "border: none; width: 100%; height: 100%;", = "relative", = "auto"), div.appendChild(iframe), (div), ("pdfobject-container"), ("iframe")[0] } , embed = function(url, targetSelector, options) { let selector = targetSelector || !1 , opt = options || {} , id = "string" == typeof o ? o : "" , page = o || !1 , pdfOpenParams = o || {} , fallbackLink = o || !0 , width = o || "100%" , height = o || "100%" , title = o || "Embedded PDF" , assumptionMode = "boolean" != typeof o || o , forcePDFJS = "boolean" == typeof o && o , supportRedirect = "boolean" == typeof o && o , omitInlineStyles = "boolean" == typeof o && o , suppressConsole = "boolean" == typeof o && o , forceIframe = "boolean" == typeof o && o , PDFJS_URL = o || !1 , targetNode = function(targetSelector) { let targetNode = document.body; return "string" == typeof targetSelector ? targetNode = document.querySelector(targetSelector) : void 0 !== window.jQuery && targetSelector instanceof jQuery && ? targetNode = (0) : void 0 !== && 1 === && (targetNode = targetSelector), targetNode }(selector) , fallbackHTML = "" , pdfOpenFragment = ""; if ("string" != typeof url) return embedError("URL is not valid", suppressConsole); if (!targetNode) return embedError("Target element cannot be determined", suppressConsole); if (page && = page), pdfOpenFragment = function(pdfParams) { let prop, string = ""; if (pdfParams) { for (prop in pdfParams) (prop) && (string += encodeURIComponent(prop) + "=" + encodeURIComponent(pdfParams[prop]) + "&"); string && (string = (string = "#" + string).slice(0, - 1)) } return string }(pdfOpenParams), forcePDFJS && PDFJS_URL) return generatePDFJSMarkup(targetNode, url, pdfOpenFragment, PDFJS_URL, id, title, omitInlineStyles); if (supportsPDFs || assumptionMode && !isMobileDevice) { return function(embedType, targetNode, targetSelector, url, pdfOpenFragment, width, height, id, title, omitInlineStyles) { emptyNodeContents(targetNode); let embed = document.createElement(embedType); if = url + pdfOpenFragment, embed.className = "pdfobject", embed.type = "application/pdf", embed.title = title, id && = id), "iframe" === embedType && = "fullscreen"), !omitInlineStyles) { let style = "embed" === embedType ? "overflow: auto;" : "border: none;"; targetSelector && targetSelector !== document.body ? style += "width: " + width + "; height: " + height + ";" : style += "position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%;", embed. = style } return ("pdfobject-container"), (embed), (embedType)[0] }(forceIframe || supportRedirect || isSafariDesktop ? "iframe" : "embed", targetNode, targetSelector, url, pdfOpenFragment, width, height, id, title, omitInlineStyles) } return PDFJS_URL ? generatePDFJSMarkup(targetNode, url, pdfOpenFragment, PDFJS_URL, id, title, omitInlineStyles) : (fallbackLink && (fallbackHTML = "string" == typeof fallbackLink ? fallbackLink : "<p>This browser does not support inline PDFs. Please download the PDF to view it: <a href='[url]'>Download PDF</a></p>", = (/\[url\]/g, url)), embedError("This browser does not support embedded PDFs", suppressConsole)) }; return { embed: function(a, b, c) { return embed(a, b, c) }, pdfobjectversion: "2.2.7", supportsPDFs: supportsPDFs } } //url为文件路径,id为dom PDFObject.embed(url, id);