浏览代码

导出excel,转义特殊字符

TonyKang 6 年之前
父节点
当前提交
a451a0e149
共有 2 个文件被更改,包括 7 次插入4 次删除
  1. 3 0
      modules/reports/util/rpt_excel_util.js
  2. 4 4
      test/unit/reports/test_rpt_test_template.js

+ 3 - 0
modules/reports/util/rpt_excel_util.js

@@ -278,9 +278,12 @@ function writeSharedString(sharedStrList){
     if (sharedStrList && sharedStrList.length > 0) {
         rst.push(dftHeadXml + '\r\n');
         rst.push('<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="' + sharedStrList.length + '" uniqueCount="' + sharedStrList.length + '">');
+        let regExp = new RegExp("<", "gm");
         for (let i = 0; i < sharedStrList.length; i++) {
             //rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
             if (typeof sharedStrList[i] === 'string') {
+                //转换特殊字符,如 < , 则需要转义一下
+                sharedStrList[i] = sharedStrList[i].replace(regExp, "&lt;");
                 if (sharedStrList[i].indexOf('|') >= 0) {
                     //rst.push('<si><t>' + sharedStrList[i].split('|').join('\r\n') + '</t></si>');
                     rst.push('<si><t>' + sharedStrList[i].split('|').join('\n') + '</t></si>');

+ 4 - 4
test/unit/reports/test_rpt_test_template.js

@@ -43,7 +43,7 @@ let userId_Leng = "5acac1e885bf55000bd055ba"; //小冷User Id2
 // demoPrjId = 720; //QA: DW3
 //demoPrjId = 1626; //QA:
 // demoPrjId = 2260; //QA:
-demoPrjId = 3604; //QA:
+demoPrjId = 3602; //QA:
 //*/
 let userId_Dft = userId_Leng;
 // let userId_Dft = "5a025c4c15074d134c2b9689";
@@ -89,9 +89,9 @@ test('测试 - 测试模板啦: ', function (t) {
                     let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
                     if (pageRst) {
                         // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult_测试模板.jsp");
-                        // rpt_xl_util.exportExcel(pageRst, pagesize, "local_test_rpt_excel", true, null, null, function(uuidName){
-                        //     console.log("excel uuid: " + uuidName);
-                        // });
+                        rpt_xl_util.exportExcel(pageRst, pagesize, "local_test_rpt_excel", true, null, null, function(uuidName){
+                            console.log("excel uuid: " + uuidName);
+                        });
                         // rpt_pdf_util.export_pdf_file(pageRst, pagesize, 'local_test_rpt_pdf', function(uuidName){
                         //     console.log("pdf uuid: " + uuidName);
                         // });