From e2b53042ccc6cabe4a76f9b33b17b251f878d371 Mon Sep 17 00:00:00 2001 From: kongdeqiang <123456> Date: 星期二, 02 一月 2024 17:21:26 +0800 Subject: [PATCH] 修改前端页面 --- src/libs/word.js | 258 +++++++++++++++++++++++++++------------------------ 1 files changed, 135 insertions(+), 123 deletions(-) diff --git a/src/libs/word.js b/src/libs/word.js index 830a592..2eb00c2 100644 --- a/src/libs/word.js +++ b/src/libs/word.js @@ -28,7 +28,13 @@ // 鍒涘缓涓�涓狿izZip瀹炰緥锛屽唴瀹逛负妯℃澘鐨勫唴瀹� let zip = new PizZip(content); // 鍒涘缓骞跺姞杞絛ocx templater瀹炰緥瀵硅薄 - let doc = new docxtemplater().loadZip(zip); + let doc = new docxtemplater().loadZip(zip).setOptions({ + linebreaks:true, + paragraphLoop: true, + nullGetter:function () { + return "" + } + }); // 璁剧疆妯℃澘鍙橀噺鐨勫�� doc.setData(e); @@ -58,145 +64,151 @@ //涓嬭浇word锛屽甫鍥剧墖 export const exportDocWidthImg = (e, path , dname, imgSize) => { - for (let attr in e) { - if (e[attr] == null) { - e[attr] = ""; + + for (let attr in e) { + if (e[attr] == null) { + e[attr] = ""; + } } - } - let docxsrc = path; //妯℃澘鏂囦欢鐨勪綅缃� - let docxname = dname; //瀵煎嚭鏂囦欢鐨勫悕瀛� - // 璇诲彇骞惰幏寰楁ā鏉挎枃浠剁殑浜岃繘鍒跺唴瀹� - JSZipUtils.getBinaryContent(docxsrc, function (error, content) { - // docxsrc鏄ā鏉裤�傛垜浠湪瀵煎嚭鐨勬椂鍊欙紝浼氭牴鎹妯℃澘鏉ュ鍑哄搴旂殑鏁版嵁 - // 鎶涘嚭寮傚父 - if (error) { - throw error; - } + let docxsrc = path; //妯℃澘鏂囦欢鐨勪綅缃� + let docxname = dname; //瀵煎嚭鏂囦欢鐨勫悕瀛� + // 璇诲彇骞惰幏寰楁ā鏉挎枃浠剁殑浜岃繘鍒跺唴瀹� + JSZipUtils.getBinaryContent(docxsrc, function (error, content) { + // docxsrc鏄ā鏉裤�傛垜浠湪瀵煎嚭鐨勬椂鍊欙紝浼氭牴鎹妯℃澘鏉ュ鍑哄搴旂殑鏁版嵁 + // 鎶涘嚭寮傚父 + if (error) { + throw error; + } - // 鍒涘缓涓�涓狿izZip瀹炰緥锛屽唴瀹逛负妯℃澘鐨勫唴瀹� - let zip = new PizZip(content); - // 鍒涘缓骞跺姞杞絛ocx templater瀹炰緥瀵硅薄 - let doc = new docxtemplater().loadZip(zip).setOptions({ - linebreaks:true, - paragraphLoop: true, - nullGetter:function () { - return "" - } - }); + // 鍒涘缓涓�涓狿izZip瀹炰緥锛屽唴瀹逛负妯℃澘鐨勫唴瀹� + let zip = new PizZip(content); + // 鍒涘缓骞跺姞杞絛ocx templater瀹炰緥瀵硅薄 + let doc = new docxtemplater().loadZip(zip).setOptions({ + linebreaks:true, + paragraphLoop: true, + nullGetter:function () { + return "" + } + }); - // // 鍥剧墖澶勭悊 - let opts = {} - opts = { - // 鍥惧儚鏄惁灞呬腑 - centered: false - }; - opts.fileType = "docx"; - opts.getImage = (chartId) =>{ - return base64DataURLToArrayBuffer(chartId); - } + // // 鍥剧墖澶勭悊 + let opts = {} + opts = { + // 鍥惧儚鏄惁灞呬腑 + centered: false + }; + opts.fileType = "docx"; + opts.getImage = (chartId) =>{ + return base64DataURLToArrayBuffer(chartId); + } - opts.getSize = function(img, tagVlaue, tagName){ //鍥剧墖size - if(imgSize.hasOwnProperty(tagName)) { - return imgSize[tagName] - }else { - return [300,300] - } - } - let imageModule = new ImageModule(opts); - doc.attachModule(imageModule); + opts.getSize = function(img, tagVlaue, tagName){ //鍥剧墖size + if(imgSize.hasOwnProperty(tagName)) { + return imgSize[tagName] + }else { + return [300,300] + } + } + let imageModule = new ImageModule(opts); + doc.attachModule(imageModule); - // 璁剧疆妯℃澘鍙橀噺鐨勫�� - doc.setData(e); - console.log(doc,'涓嬭浇---甯﹀浘鐗囩殑---') + // 璁剧疆妯℃澘鍙橀噺鐨勫�� + doc.setData(e); - try { - //鏇挎崲鎵�鏈夋ā鏉垮彉閲� - doc.render(); - } catch (error) { - let e = { - message: error.message, - name: error.name, - stack: error.stack, - properties: error.properties - }; - console.log(JSON.stringify({error: e})); - throw error; - } + try { + //鏇挎崲鎵�鏈夋ā鏉垮彉閲� + doc.render(); + } catch (error) { + let e = { + message: error.message, + name: error.name, + stack: error.stack, + properties: error.properties + }; + console.log(JSON.stringify({error: e})); + throw error; + } - // 鐢熸垚涓�涓唬琛╠ocxtemplater瀵硅薄鐨剒ip鏂囦欢锛堜笉鏄竴涓湡瀹炵殑鏂囦欢锛岃�屾槸鍦ㄥ唴瀛樹腑鐨勮〃绀猴級 - let out = doc.getZip().generate({ - type: "blob", - mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" - }); - // 灏嗙洰鏍囨枃浠跺璞′繚瀛樹负鐩爣绫诲瀷鐨勬枃浠讹紝骞跺懡鍚� - saveAs(out, docxname); - },2000); + // 鐢熸垚涓�涓唬琛╠ocxtemplater瀵硅薄鐨剒ip鏂囦欢锛堜笉鏄竴涓湡瀹炵殑鏂囦欢锛岃�屾槸鍦ㄥ唴瀛樹腑鐨勮〃绀猴級 + let out = doc.getZip().generate({ + type: "blob", + mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" + }); + // 灏嗙洰鏍囨枃浠跺璞′繚瀛樹负鐩爣绫诲瀷鐨勬枃浠讹紝骞跺懡鍚� + saveAs(out, docxname); + },2000); } //涓嬭浇word锛屽甫鍥剧墖 export const exportDocWidthImg2 = (e, path , dname, arry, imgSize) => { - for (let attr in e) { - if (e[attr] == null) { - e[attr] = ""; + for (let attr in e) { + if (e[attr] == null) { + e[attr] = ""; + } } - } - let docxsrc = path; //妯℃澘鏂囦欢鐨勪綅缃� - let docxname = dname; //瀵煎嚭鏂囦欢鐨勫悕瀛� - // 璇诲彇骞惰幏寰楁ā鏉挎枃浠剁殑浜岃繘鍒跺唴瀹� - JSZipUtils.getBinaryContent(docxsrc, function (error, content) { - // docxsrc鏄ā鏉裤�傛垜浠湪瀵煎嚭鐨勬椂鍊欙紝浼氭牴鎹妯℃澘鏉ュ鍑哄搴旂殑鏁版嵁 - // 鎶涘嚭寮傚父 - if (error) { - throw error; - } + let docxsrc = path; //妯℃澘鏂囦欢鐨勪綅缃� + let docxname = dname; //瀵煎嚭鏂囦欢鐨勫悕瀛� + // 璇诲彇骞惰幏寰楁ā鏉挎枃浠剁殑浜岃繘鍒跺唴瀹� + JSZipUtils.getBinaryContent(docxsrc, function (error, content) { + // docxsrc鏄ā鏉裤�傛垜浠湪瀵煎嚭鐨勬椂鍊欙紝浼氭牴鎹妯℃澘鏉ュ鍑哄搴旂殑鏁版嵁 + // 鎶涘嚭寮傚父 + if (error) { + throw error; + } - // 鍒涘缓涓�涓狿izZip瀹炰緥锛屽唴瀹逛负妯℃澘鐨勫唴瀹� - let zip = new PizZip(content); - // 鍒涘缓骞跺姞杞絛ocx templater瀹炰緥瀵硅薄 - let doc = new docxtemplater().loadZip(zip); + // 鍒涘缓涓�涓狿izZip瀹炰緥锛屽唴瀹逛负妯℃澘鐨勫唴瀹� + let zip = new PizZip(content); + // 鍒涘缓骞跺姞杞絛ocx templater瀹炰緥瀵硅薄 + let doc = new docxtemplater().loadZip(zip).setOptions({ + linebreaks:true, + paragraphLoop: true, + nullGetter:function () { + return "" + } + }); - // // 鍥剧墖澶勭悊 - const opts = {} - opts.fileType = "docx"; - opts.getImage = (chartId) =>{ - return base64DataURLToArrayBuffer(chartId); - } + // // 鍥剧墖澶勭悊 + const opts = {} + opts.fileType = "docx"; + opts.getImage = (chartId) =>{ + return base64DataURLToArrayBuffer(chartId); + } - opts.getSize = function(img, tagVlaue, tagName){ //鍥剧墖size - if(imgSize.hasOwnProperty(tagName)) { - return imgSize[tagName] - }else { - return [300,300] - } - } - let imageModule = new ImageModule(opts); - doc.attachModule(imageModule); + opts.getSize = function(img, tagVlaue, tagName){ //鍥剧墖size + if(imgSize.hasOwnProperty(tagName)) { + return imgSize[tagName] + }else { + return [300,300] + } + } + let imageModule = new ImageModule(opts); + doc.attachModule(imageModule); - // 璁剧疆妯℃澘鍙橀噺鐨勫�� - doc.setData(e); + // 璁剧疆妯℃澘鍙橀噺鐨勫�� + doc.setData(e); - try { - //鏇挎崲鎵�鏈夋ā鏉垮彉閲� - doc.render(); - } catch (error) { - let e = { - message: error.message, - name: error.name, - stack: error.stack, - properties: error.properties - }; - console.log(JSON.stringify({error: e})); - throw error; - } + try { + //鏇挎崲鎵�鏈夋ā鏉垮彉閲� + doc.render(); + } catch (error) { + let e = { + message: error.message, + name: error.name, + stack: error.stack, + properties: error.properties + }; + console.log(JSON.stringify({error: e})); + throw error; + } - // 鐢熸垚涓�涓唬琛╠ocxtemplater瀵硅薄鐨剒ip鏂囦欢锛堜笉鏄竴涓湡瀹炵殑鏂囦欢锛岃�屾槸鍦ㄥ唴瀛樹腑鐨勮〃绀猴級 - let out = doc.getZip().generate({ - type: "blob", - mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" - }); - // 灏嗙洰鏍囨枃浠跺璞′繚瀛樹负鐩爣绫诲瀷鐨勬枃浠讹紝骞跺懡鍚� - saveAs(out, docxname); - },2000); + // 鐢熸垚涓�涓唬琛╠ocxtemplater瀵硅薄鐨剒ip鏂囦欢锛堜笉鏄竴涓湡瀹炵殑鏂囦欢锛岃�屾槸鍦ㄥ唴瀛樹腑鐨勮〃绀猴級 + let out = doc.getZip().generate({ + type: "blob", + mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" + }); + // 灏嗙洰鏍囨枃浠跺璞′繚瀛樹负鐩爣绫诲瀷鐨勬枃浠讹紝骞跺懡鍚� + saveAs(out, docxname); + },2000); } //棰勮word锛屼笉甯﹀浘鐗囩殑 @@ -275,7 +287,7 @@ if(imgSize.hasOwnProperty(tagName)) { return imgSize[tagName] }else { - return [300,300] + return [70,40] } } -- Gitblit v1.9.1