rpt_jsexcel.js 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852
  1. /**
  2. * Created by Tony on 2022/2/21.
  3. * 导出excel从后端移到前端处理
  4. */
  5. // const JV = require('../rpt_component/jpc_value_define'); // JV对象默认已有
  6. // const JSZip = require('jszip'); // 已引用
  7. // const strUtil = require('../public/stringUtil'); // stringUtil对象也有
  8. // STAGE_AUDIT, STAGE_LIST 已存在
  9. const DPI = 96;
  10. const dftHeadXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
  11. const STD_COMP_STAMP_SIZE_WIDTH = Math.round(5 * 96 / 2.54); // 公章标准尺寸(宽4.2厘米)转成像素
  12. const STD_COMP_STAMP_SIZE_HEIGHT = STD_COMP_STAMP_SIZE_WIDTH; // 公章标准尺寸(高4.2厘米)转成像素
  13. function writeContentTypes(sheets, isSinglePage, hasSignature) {
  14. const rst = [];
  15. rst.push(dftHeadXml + '\r\n');
  16. rst.push('<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">');
  17. rst.push('<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>');
  18. rst.push('<Default Extension="xml" ContentType="application/xml"/>');
  19. if (hasSignature) {
  20. rst.push('<Default Extension="png" ContentType="image/png"/>');
  21. }
  22. rst.push('<Override PartName="/xl/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>');
  23. rst.push('<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>');
  24. rst.push('<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>');
  25. rst.push('<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>');
  26. rst.push('<Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>');
  27. if (isSinglePage) {
  28. rst.push('<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>');
  29. if (hasSignature) {
  30. rst.push('<Override PartName="/xl/drawings/drawing1.xml" ContentType="application/vnd.openxmlformats-officedocument.drawing+xml"/>');
  31. }
  32. } else {
  33. for (let i = 0; i < sheets.length; i++) {
  34. rst.push('<Override PartName="/xl/worksheets/sheet' + (i + 1) + '.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>');
  35. if (hasSignature) {
  36. rst.push('<Override PartName="/xl/drawings/drawing' + (i + 1) + '.xml" ContentType="application/vnd.openxmlformats-officedocument.drawing+xml"/>');
  37. }
  38. }
  39. }
  40. rst.push('<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>');
  41. rst.push('</Types>');
  42. return rst;
  43. }
  44. function writeRootRels() {
  45. const rst = [];
  46. rst.push(dftHeadXml + '\r\n');
  47. rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
  48. rst.push('<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>');
  49. rst.push('<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>');
  50. rst.push('<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>');
  51. rst.push('</Relationships>');
  52. return rst;
  53. }
  54. function writeApp(sheets, isSinglePage) {
  55. const rst = [];
  56. rst.push(dftHeadXml + '\r\n');
  57. rst.push('<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">');
  58. rst.push('<Application>Microsoft Excel</Application>');
  59. rst.push('<DocSecurity>0</DocSecurity>');
  60. rst.push('<ScaleCrop>false</ScaleCrop>');
  61. rst.push('<HeadingPairs>');
  62. rst.push('<vt:vector size="2" baseType="variant">');
  63. rst.push('<vt:variant><vt:lpstr>工作表</vt:lpstr></vt:variant>');
  64. if (isSinglePage) rst.push('<vt:variant><vt:i4>1</vt:i4></vt:variant>');
  65. else rst.push('<vt:variant><vt:i4>' + sheets.length + '</vt:i4></vt:variant>');
  66. rst.push('</vt:vector>');
  67. rst.push('</HeadingPairs>');
  68. rst.push('<TitlesOfParts>');
  69. if (isSinglePage) {
  70. rst.push('<vt:vector size="1" baseType="lpstr">');
  71. rst.push('<vt:lpstr>' + sheets[0].sheetName + '</vt:lpstr>');
  72. } else {
  73. rst.push('<vt:vector size="' + sheets.length + '" baseType="lpstr">');
  74. for (let i = 0; i < sheets.length; i++) {
  75. rst.push('<vt:lpstr>' + sheets[i].sheetName + '</vt:lpstr>');
  76. }
  77. }
  78. rst.push('</vt:vector>');
  79. rst.push('</TitlesOfParts>');
  80. rst.push('<Company>SmartCost</Company>');
  81. rst.push('<LinksUpToDate>false</LinksUpToDate>');
  82. rst.push('<SharedDoc>false</SharedDoc>');
  83. rst.push('<HyperlinksChanged>false</HyperlinksChanged>');
  84. rst.push('<AppVersion>12.0000</AppVersion>');
  85. rst.push('</Properties>');
  86. return rst;
  87. }
  88. function writeCore() {
  89. const rst = [];
  90. const p_fillZero = function(val) {
  91. let rst = val;
  92. if (val < 10) {
  93. rst = '0' + val;
  94. }
  95. return rst;
  96. };
  97. rst.push(dftHeadXml + '\r\n');
  98. rst.push('<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">');
  99. rst.push('<dc:creator>SmartCost</dc:creator>');
  100. rst.push('<cp:lastModifiedBy>SmartCost</cp:lastModifiedBy>');
  101. const dt = new Date();
  102. dt.setDate(dt.getDate() - 8 / 24); // it's GMT time, so please add the server offset time ( -8 hours )
  103. const dtStr = dt.getFullYear() + '-' + p_fillZero(dt.getMonth() + 1) + '-' + p_fillZero(dt.getDate()) + 'T' +
  104. p_fillZero(dt.getHours()) + ':' + p_fillZero(dt.getMinutes()) + ':' + p_fillZero(dt.getSeconds()) + 'Z';
  105. rst.push('<dcterms:created xsi:type="dcterms:W3CDTF">' + dtStr + '</dcterms:created>');
  106. rst.push('<dcterms:modified xsi:type="dcterms:W3CDTF">' + dtStr + '</dcterms:modified>');
  107. rst.push('</cp:coreProperties>');
  108. return rst;
  109. }
  110. function writeXlWorkBook(sheets, isSinglePage) {
  111. const rst = [];
  112. rst.push(dftHeadXml + '\r\n');
  113. rst.push('<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">');
  114. rst.push('<fileVersion appName="xl" lastEdited="4" lowestEdited="4" rupBuild="4505"/>');
  115. rst.push('<workbookPr defaultThemeVersion="124226"/>');
  116. rst.push('<bookViews><workbookView xWindow="360" yWindow="345" windowWidth="14655" windowHeight="4305"/></bookViews>');
  117. rst.push('<sheets>');
  118. if (isSinglePage) {
  119. rst.push('<sheet name="' + sheets[0].sheetName + '" sheetId="1" r:id="rId1"/>');
  120. } else {
  121. for (let i = 0; i < sheets.length; i++) {
  122. rst.push('<sheet name="' + sheets[i].sheetName + '" sheetId="' + (i + 1) + '" r:id="rId' + (i + 1) + '"/>');
  123. }
  124. }
  125. rst.push('</sheets>');
  126. rst.push('<calcPr calcId="124519"/>');
  127. rst.push('</workbook>');
  128. return rst;
  129. }
  130. function writeXlRels(sheets, isSinglePage) {
  131. const rst = [];
  132. let idx = 1;
  133. rst.push(dftHeadXml + '\r\n');
  134. rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
  135. if (isSinglePage) {
  136. rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>');
  137. idx++;
  138. } else {
  139. for (let i = 0; i < sheets.length; i++) {
  140. rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet' + (i + 1) + '.xml"/>');
  141. idx++;
  142. }
  143. }
  144. rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>');
  145. idx++;
  146. rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>');
  147. idx++;
  148. rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/>');
  149. rst.push('</Relationships>');
  150. return rst;
  151. }
  152. function writeTheme() {
  153. // const rst = fs.readFileSync(__dirname + '/excel_base_files/theme1.xml', 'utf8', 'r');
  154. const rst = [`<?xml version="1.0"encoding="UTF-8"standalone="yes"?><a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"name="Office 主题"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText"lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window"lastClr="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="1F497D"/></a:dk2><a:lt2><a:srgbClr val="EEECE1"/></a:lt2><a:accent1><a:srgbClr val="4F81BD"/></a:accent1><a:accent2><a:srgbClr val="C0504D"/></a:accent2><a:accent3><a:srgbClr val="9BBB59"/></a:accent3><a:accent4><a:srgbClr val="8064A2"/></a:accent4><a:accent5><a:srgbClr val="4BACC6"/></a:accent5><a:accent6><a:srgbClr val="F79646"/></a:accent6><a:hlink><a:srgbClr val="0000FF"/></a:hlink><a:folHlink><a:srgbClr val="800080"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Cambria"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan"typeface="MS Pゴシック"/><a:font script="Hang"typeface="맑은 고딕"/><a:font script="Hans"typeface="宋体"/><a:font script="Hant"typeface="新細明體"/><a:font script="Arab"typeface="Times New Roman"/><a:font script="Hebr"typeface="Times New Roman"/><a:font script="Thai"typeface="Tahoma"/><a:font script="Ethi"typeface="Nyala"/><a:font script="Beng"typeface="Vrinda"/><a:font script="Gujr"typeface="Shruti"/><a:font script="Khmr"typeface="MoolBoran"/><a:font script="Knda"typeface="Tunga"/><a:font script="Guru"typeface="Raavi"/><a:font script="Cans"typeface="Euphemia"/><a:font script="Cher"typeface="Plantagenet Cherokee"/><a:font script="Yiii"typeface="Microsoft Yi Baiti"/><a:font script="Tibt"typeface="Microsoft Himalaya"/><a:font script="Thaa"typeface="MV Boli"/><a:font script="Deva"typeface="Mangal"/><a:font script="Telu"typeface="Gautami"/><a:font script="Taml"typeface="Latha"/><a:font script="Syrc"typeface="Estrangelo Edessa"/><a:font script="Orya"typeface="Kalinga"/><a:font script="Mlym"typeface="Kartika"/><a:font script="Laoo"typeface="DokChampa"/><a:font script="Sinh"typeface="Iskoola Pota"/><a:font script="Mong"typeface="Mongolian Baiti"/><a:font script="Viet"typeface="Times New Roman"/><a:font script="Uigh"typeface="Microsoft Uighur"/></a:majorFont><a:minorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan"typeface="MS Pゴシック"/><a:font script="Hang"typeface="맑은 고딕"/><a:font script="Hans"typeface="宋体"/><a:font script="Hant"typeface="新細明體"/><a:font script="Arab"typeface="Arial"/><a:font script="Hebr"typeface="Arial"/><a:font script="Thai"typeface="Tahoma"/><a:font script="Ethi"typeface="Nyala"/><a:font script="Beng"typeface="Vrinda"/><a:font script="Gujr"typeface="Shruti"/><a:font script="Khmr"typeface="DaunPenh"/><a:font script="Knda"typeface="Tunga"/><a:font script="Guru"typeface="Raavi"/><a:font script="Cans"typeface="Euphemia"/><a:font script="Cher"typeface="Plantagenet Cherokee"/><a:font script="Yiii"typeface="Microsoft Yi Baiti"/><a:font script="Tibt"typeface="Microsoft Himalaya"/><a:font script="Thaa"typeface="MV Boli"/><a:font script="Deva"typeface="Mangal"/><a:font script="Telu"typeface="Gautami"/><a:font script="Taml"typeface="Latha"/><a:font script="Syrc"typeface="Estrangelo Edessa"/><a:font script="Orya"typeface="Kalinga"/><a:font script="Mlym"typeface="Kartika"/><a:font script="Laoo"typeface="DokChampa"/><a:font script="Sinh"typeface="Iskoola Pota"/><a:font script="Mong"typeface="Mongolian Baiti"/><a:font script="Viet"typeface="Arial"/><a:font script="Uigh"typeface="Microsoft Uighur"/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="35000"><a:schemeClr val="phClr"><a:tint val="37000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="15000"/><a:satMod val="350000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000"scaled="1"/></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:shade val="51000"/><a:satMod val="130000"/></a:schemeClr></a:gs><a:gs pos="80000"><a:schemeClr val="phClr"><a:shade val="93000"/><a:satMod val="130000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="94000"/><a:satMod val="135000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000"scaled="0"/></a:gradFill></a:fillStyleLst><a:lnStyleLst><a:ln w="9525"cap="flat"cmpd="sng"algn="ctr"><a:solidFill><a:schemeClr val="phClr"><a:shade val="95000"/><a:satMod val="105000"/></a:schemeClr></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="25400"cap="flat"cmpd="sng"algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="38100"cap="flat"cmpd="sng"algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000"dist="20000"dir="5400000"rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="38000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000"dist="23000"dir="5400000"rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000"dist="23000"dir="5400000"rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst><a:scene3d><a:camera prst="orthographicFront"><a:rot lat="0"lon="0"rev="0"/></a:camera><a:lightRig rig="threePt"dir="t"><a:rot lat="0"lon="0"rev="1200000"/></a:lightRig></a:scene3d><a:sp3d><a:bevelT w="63500"h="25400"/></a:sp3d></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"/><a:satMod val="350000"/></a:schemeClr></a:gs><a:gs pos="40000"><a:schemeClr val="phClr"><a:tint val="45000"/><a:shade val="99000"/><a:satMod val="350000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="20000"/><a:satMod val="255000"/></a:schemeClr></a:gs></a:gsLst><a:path path="circle"><a:fillToRect l="50000"t="-80000"r="50000"b="180000"/></a:path></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="30000"/><a:satMod val="200000"/></a:schemeClr></a:gs></a:gsLst><a:path path="circle"><a:fillToRect l="50000"t="50000"r="50000"b="50000"/></a:path></a:gradFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements><a:objectDefaults/><a:extraClrSchemeLst/></a:theme>`];
  155. // 前端没有这个文件,需要想想怎么给(说白了,也就是一个一个xml文件而已)
  156. return rst;
  157. }
  158. function writeStyles(stylesObj, hasSignature) {
  159. const rst = [];
  160. rst.push(dftHeadXml + '\r\n');
  161. rst.push('<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">');
  162. // 1. push fonts
  163. rst.push('<fonts count="' + stylesObj.fonts.length + '">');
  164. for (let i = 0; i < stylesObj.fonts.length; i++) {
  165. const font = stylesObj.fonts[i];
  166. rst.push('<font>');
  167. if (stringUtil.convertStrToBoolean(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]])) {
  168. rst.push('<b/>');
  169. }
  170. if (stringUtil.convertStrToBoolean(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]])) {
  171. rst.push('<i/>');
  172. }
  173. if (stringUtil.convertStrToBoolean(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]])) {
  174. rst.push('<u/>');
  175. }
  176. rst.push('<sz val="' + font.size + '"/>');
  177. rst.push('<color indexed="' + font.colorIdx + '"/>');
  178. rst.push('<name val="' + font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]] + '"/>');
  179. rst.push('<charset val="' + font.charset + '"/>');
  180. rst.push('</font>');
  181. }
  182. rst.push('</fonts>');
  183. // 2. push default fills
  184. rst.push('<fills count="2"><fill><patternFill patternType="none" /></fill><fill><patternFill patternType="gray125" /></fill></fills>');
  185. // 3. push borders
  186. rst.push('<borders count="' + stylesObj.borders.length + '">');
  187. const private_setBorder = function(border, borderDirection) {
  188. if (parseInt(border[borderDirection][JV.PROP_LINE_WEIGHT]) === 0) {
  189. rst.push('<' + borderDirection.toLowerCase() + '/>');
  190. } else {
  191. let bW = 'thin';
  192. if (parseInt(border[borderDirection][JV.PROP_LINE_WEIGHT]) === 2) bW = 'medium';
  193. if (parseInt(border[borderDirection][JV.PROP_LINE_WEIGHT]) > 2) bW = 'thick';
  194. rst.push('<' + borderDirection.toLowerCase() + ' style="' + bW + '"><color indexed="64"/></' + borderDirection.toLowerCase() + '>');
  195. }
  196. };
  197. for (let i = 0; i < stylesObj.borders.length; i++) {
  198. const border = stylesObj.borders[i];
  199. rst.push('<border>');
  200. private_setBorder(border, JV.PROP_LEFT);
  201. private_setBorder(border, JV.PROP_RIGHT);
  202. private_setBorder(border, JV.PROP_TOP);
  203. private_setBorder(border, JV.PROP_BOTTOM);
  204. rst.push('<diagonal />');
  205. rst.push('</border>');
  206. }
  207. rst.push('</borders>');
  208. // 4. push cellStyleXfs
  209. rst.push('<cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"><alignment vertical="center"/></xf></cellStyleXfs>');
  210. // 5. push cellXfs
  211. rst.push('<cellXfs count="' + stylesObj.cellXfs.length + '">');
  212. for (let i = 0; i < stylesObj.cellXfs.length; i++) {
  213. const excelStyle = stylesObj.cellXfs[i];
  214. rst.push('<xf numFmtId="0" fontId="' + excelStyle.fontId + '" fillId="0" borderId="' + excelStyle.borderId + '" xfId="0">');
  215. // pageData[JV.NODE_FONT_COLLECTION] excelStyle.fontId
  216. let alignStr = '<alignment';
  217. let textRotation = 0;
  218. let newHorizontal = excelStyle[JV.CONTROL_PROPS[2]];
  219. let newVertical = excelStyle[JV.CONTROL_PROPS[3]];
  220. if (excelStyle[JV.CONTROL_PROPS[5]] && !stringUtil.convertStrToBoolean(excelStyle[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_CLOSE_OUTPUT]])) {
  221. newVertical = excelStyle[JV.CONTROL_PROPS[5]];
  222. }
  223. if (parseInt(excelStyle.fontAngle) !== 0) {
  224. let tmpH = newHorizontal;
  225. let tmpV = newVertical;
  226. if (excelStyle.fontAngle > 0) {
  227. textRotation = 180;
  228. if (newHorizontal === 'left') {
  229. tmpV = 'top';
  230. } else if (newHorizontal === 'right') {
  231. tmpV = 'bottom';
  232. } else {
  233. tmpV = 'center';
  234. }
  235. if (newVertical === 'top') {
  236. tmpH = 'right';
  237. } else if (newVertical === 'bottom') {
  238. tmpH = 'left';
  239. } else if (newVertical === 'justify') {
  240. tmpH = 'justify';
  241. } else {
  242. tmpH = 'center';
  243. }
  244. } else {
  245. textRotation = 90;
  246. if (newHorizontal === 'left') {
  247. tmpV = 'bottom';
  248. } else if (newHorizontal === 'right') {
  249. tmpV = 'top';
  250. } else {
  251. tmpV = 'center';
  252. }
  253. if (newVertical === 'top') {
  254. tmpH = 'left';
  255. } else if (newVertical === 'bottom') {
  256. tmpH = 'right';
  257. } else {
  258. tmpH = 'center';
  259. }
  260. }
  261. newHorizontal = tmpH;
  262. newVertical = tmpV;
  263. }
  264. alignStr += ' horizontal="' + newHorizontal + '" vertical="' + newVertical + '"';
  265. if (stringUtil.convertStrToBoolean(excelStyle[JV.CONTROL_PROPS[0]])) {
  266. alignStr += ' shrinkToFit="1"';
  267. }
  268. if (stringUtil.convertStrToBoolean(excelStyle[JV.CONTROL_PROPS[4]]) && !stringUtil.convertStrToBoolean(excelStyle[JV.CONTROL_PROPS[6]])) {
  269. alignStr += ' wrapText="1"';
  270. }
  271. if (textRotation !== 0) {
  272. alignStr += ' textRotation="' + textRotation + '"';
  273. }
  274. alignStr += '/>';
  275. rst.push(alignStr);
  276. rst.push('</xf>');
  277. }
  278. rst.push('</cellXfs>');
  279. // 6. others (xfl style / dxfs / tableStyles)
  280. rst.push('<cellStyles count="1"><cellStyle name="常规" xfId="0" builtinId="0"/></cellStyles>');
  281. rst.push('<dxfs count="0"/>');
  282. rst.push('<tableStyles count="0" defaultTableStyle="TableStyleMedium9" defaultPivotStyle="PivotStyleLight16"/>');
  283. if (hasSignature) {
  284. rst.push('<extLst>');
  285. rst.push('<ext uri="{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main">');
  286. rst.push('<x14:slicerStyles defaultSlicerStyle="SlicerStyleLight1"/>');
  287. rst.push('</ext>');
  288. rst.push('<ext uri="{9260A510-F301-46a8-8635-F512D64BE5F5}" xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main">');
  289. rst.push('<x15:timelineStyles defaultTimelineStyle="TimeSlicerStyleLight1"/>');
  290. rst.push('</ext>');
  291. rst.push('</extLst>');
  292. }
  293. rst.push('</styleSheet>');
  294. return rst;
  295. }
  296. function writeSharedString(sharedStrList) {
  297. const rst = [];
  298. const pri_func_write = function(cellVal) {
  299. if (cellVal !== null) {
  300. if ((typeof cellVal === 'string') && cellVal.indexOf(' ') === 0) {
  301. rst.push('<si><t xml:space="preserve">' + cellVal + '</t></si>');
  302. } else {
  303. rst.push('<si><t>' + cellVal + '</t></si>');
  304. }
  305. }
  306. };
  307. if (sharedStrList && sharedStrList.length > 0) {
  308. rst.push(dftHeadXml + '\r\n');
  309. rst.push('<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="' + sharedStrList.length + '" uniqueCount="' + sharedStrList.length + '">');
  310. const regExp = new RegExp('<', 'gm');
  311. for (let i = 0; i < sharedStrList.length; i++) {
  312. if (typeof sharedStrList[i] === 'string') {
  313. // 转换特殊字符,如 < , 则需要转义一下
  314. sharedStrList[i] = sharedStrList[i].replace(regExp, '&lt;');
  315. if (sharedStrList[i].indexOf('|') >= 0) {
  316. // rst.push('<si><t>' + sharedStrList[i].split('|').join('\r\n') + '</t></si>');
  317. // rst.push('<si><t>' + sharedStrList[i].split('|').join('\n') + '</t></si>');
  318. pri_func_write(sharedStrList[i].split('|').join('\n'));
  319. } else {
  320. // rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
  321. pri_func_write(sharedStrList[i]);
  322. }
  323. // rst.push('<si><t>' + sharedStrList[i].replace('|','\r\n') + '</t></si>');
  324. } else {
  325. // rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
  326. pri_func_write(sharedStrList[i]);
  327. }
  328. }
  329. rst.push('</sst>');
  330. }
  331. return rst;
  332. }
  333. function _setupPgBrks(pageData) {
  334. pageData.pageBreaks = [];
  335. let pgBrkIdx = 0;
  336. const pgBrk = [];
  337. function _insertMaxBottom(pCells, targetBottomArr, chkTop) {
  338. if (pCells) {
  339. for (const cell of pCells) {
  340. let cb = parseFloat(cell[JV.PROP_AREA][JV.PROP_BOTTOM]);
  341. if (targetBottomArr.indexOf(cb) < 0) {
  342. targetBottomArr.push(cb);
  343. }
  344. if (chkTop || pCells.isStamp) {
  345. cb = parseFloat(cell[JV.PROP_AREA][JV.PROP_TOP]);
  346. if (targetBottomArr.indexOf(cb) < 0) {
  347. targetBottomArr.push(cb);
  348. }
  349. }
  350. }
  351. }
  352. }
  353. // for (const page of pageData.items) {
  354. // for (let i = 0; i < pageData.items.length - 1; i++) {
  355. for (let i = 0; i < pageData.items.length; i++) {
  356. const page = pageData.items[i];
  357. const maxBottomArr = [];
  358. _insertMaxBottom(page[JV.PROP_CELLS], maxBottomArr);
  359. _insertMaxBottom(page[JV.PROP_INTERACT_CELLS], maxBottomArr);
  360. _insertMaxBottom(page[JV.PROP_SIGNATURE_CELLS], maxBottomArr, true);
  361. _insertMaxBottom(page[JV.PROP_SIGNATURE_DATE_CELLS], maxBottomArr);
  362. _insertMaxBottom(page[JV.PROP_SIGNATURE_AUDIT_CELLS], maxBottomArr);
  363. _insertMaxBottom(page[JV.PROP_WATERMARK_CELLS], maxBottomArr, true);
  364. pgBrkIdx += maxBottomArr.length;
  365. pgBrk.push(pgBrkIdx);
  366. }
  367. pageData.pageBreaks.push(pgBrk);
  368. }
  369. function writeSheets(pageData, paperSize, sharedStrList, stylesObj, isSinglePage, custSheetMergeBands, hasSignature, signSheetIdxArr) {
  370. const rst = [];
  371. const private_pushDftFont = function() {
  372. const font = {};
  373. if (!(stylesObj.fonts)) {
  374. stylesObj.fonts = [];
  375. }
  376. font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]] = '宋体'; // font name
  377. font.size = 12;
  378. font.charset = 134;
  379. font.colorIdx = '8';
  380. stylesObj.fonts.push(font);
  381. };
  382. const private_buildFirstDftStyle = function() {
  383. stylesObj.cellXfs = [];
  384. stylesObj.borders = [];
  385. const fontId = 0;
  386. const borderId = 0;
  387. const border = {};
  388. border[JV.PROP_LEFT] = {};
  389. border[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT] = 0;
  390. border[JV.PROP_RIGHT] = {};
  391. border[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT] = 0;
  392. border[JV.PROP_TOP] = {};
  393. border[JV.PROP_TOP][JV.PROP_LINE_WEIGHT] = 0;
  394. border[JV.PROP_BOTTOM] = {};
  395. border[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT] = 0;
  396. stylesObj.borders.push(border);
  397. const cellControl = pageData[JV.NODE_CONTROL_COLLECTION].Default;
  398. const sheetControl = {};
  399. sheetControl.fontId = fontId;
  400. sheetControl.borderId = borderId;
  401. sheetControl.fontAngle = 0;
  402. for (let i = 0; i < JV.CONTROL_PROPS.length; i++) {
  403. sheetControl[JV.CONTROL_PROPS[i]] = cellControl[JV.CONTROL_PROPS[i]];
  404. }
  405. stylesObj.cellXfs.push(sheetControl);
  406. };
  407. private_pushDftFont();
  408. private_buildFirstDftStyle();
  409. let sheetIdx = 0;
  410. if (isSinglePage) {
  411. rst.push(writeSheet(pageData, null, paperSize, sharedStrList, stylesObj, null, hasSignature, sheetIdx, signSheetIdxArr, true, -1));
  412. } else {
  413. for (let i = 0; i < pageData.items.length; i++) {
  414. let appointedMergeBand = null;
  415. if (custSheetMergeBands && custSheetMergeBands.length > i) {
  416. appointedMergeBand = custSheetMergeBands[i];
  417. }
  418. rst.push(writeSheet(pageData, pageData.items[i], paperSize, sharedStrList, stylesObj, appointedMergeBand, hasSignature, sheetIdx, signSheetIdxArr, i === 0, i));
  419. sheetIdx++;
  420. }
  421. }
  422. return rst;
  423. }
  424. function getProperSignatureArea(cell, control) {
  425. // 约定默认长宽比例是2:1,图片分辨率是600*300
  426. const rst = [0, 0, 0, 0]; // left, top, right, bottom
  427. if (cell && cell[JV.PROP_AREA]) {
  428. if (cell.hasOwnProperty('isOrgShow') && cell.isOrgShow) {
  429. // 例外的约定,按原始类型处理
  430. rst[JV.IDX_LEFT] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  431. rst[JV.IDX_TOP] = cell[JV.PROP_AREA][JV.PROP_TOP];
  432. rst[JV.IDX_RIGHT] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  433. rst[JV.IDX_BOTTOM] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  434. } else {
  435. let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
  436. height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP];
  437. if (width > height * 2) {
  438. width = height * 2;
  439. } else {
  440. height = width / 2;
  441. }
  442. switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  443. case 'left':
  444. rst[0] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  445. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  446. rst[2] = rst[0] + width;
  447. rst[3] = rst[1] + height;
  448. break;
  449. case 'right':
  450. rst[2] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  451. rst[3] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  452. rst[0] = rst[2] - width;
  453. rst[1] = rst[3] - height;
  454. break;
  455. default:
  456. // center
  457. rst[0] = (cell[JV.PROP_AREA][JV.PROP_LEFT] + cell[JV.PROP_AREA][JV.PROP_RIGHT] - width) / 2;
  458. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  459. rst[2] = rst[0] + width;
  460. rst[3] = rst[1] + height;
  461. break;
  462. }
  463. }
  464. }
  465. // rst[0] = rst[0] + JpcCanvasOutput.offsetX;
  466. // rst[2] = rst[2] + JpcCanvasOutput.offsetX;
  467. // rst[1] = rst[1] + JpcCanvasOutput.offsetY;
  468. // rst[3] = rst[3] + JpcCanvasOutput.offsetY;
  469. return rst;
  470. }
  471. function preAnalyzePos(pageData, sheetData, xPos, yPos, yMultiPos) {
  472. let cell;
  473. let pos;
  474. const private_array_sort = function(i1, i2) {
  475. return (i1 - i2);
  476. };
  477. const private_set_cell_pos = function(theCell, theXPos, theYPos) {
  478. pos = theCell[JV.PROP_AREA][JV.PROP_LEFT];
  479. if (theXPos.indexOf(pos) < 0) theXPos.push(pos);
  480. pos = theCell[JV.PROP_AREA][JV.PROP_RIGHT];
  481. if (theXPos.indexOf(pos) < 0) theXPos.push(pos);
  482. pos = theCell[JV.PROP_AREA][JV.PROP_TOP];
  483. if (theYPos.indexOf(pos) < 0) theYPos.push(pos);
  484. pos = theCell[JV.PROP_AREA][JV.PROP_BOTTOM];
  485. if (theYPos.indexOf(pos) < 0) theYPos.push(pos);
  486. };
  487. const private_set_cell_pos2 = function(area, theXPos, theYPos) {
  488. pos = area[0];
  489. if (theXPos.indexOf(pos) < 0) theXPos.push(pos);
  490. pos = area[2];
  491. if (theXPos.indexOf(pos) < 0) theXPos.push(pos);
  492. pos = area[1];
  493. if (theYPos.indexOf(pos) < 0) theYPos.push(pos);
  494. pos = area[3];
  495. if (theYPos.indexOf(pos) < 0) theYPos.push(pos);
  496. };
  497. const self_analyze_sheet_pos = function(theShtData, theXPos, theYPos) {
  498. for (let i = 0; i < theShtData[JV.PROP_CELLS].length; i++) {
  499. cell = theShtData[JV.PROP_CELLS][i];
  500. private_set_cell_pos(cell, theXPos, theYPos);
  501. }
  502. for (let i = 0; i < theShtData[JV.PROP_INTERACT_CELLS].length; i++) {
  503. cell = theShtData[JV.PROP_INTERACT_CELLS][i];
  504. private_set_cell_pos(cell, theXPos, theYPos);
  505. }
  506. for (let i = 0; i < theShtData[JV.PROP_SIGNATURE_CELLS].length; i++) {
  507. cell = theShtData[JV.PROP_SIGNATURE_CELLS][i];
  508. private_set_cell_pos(cell, theXPos, theYPos);
  509. let cellControl;
  510. if (typeof cell[JV.PROP_CONTROL] === 'string') {
  511. cellControl = pageData[JV.NODE_CONTROL_COLLECTION][cell[JV.PROP_CONTROL]];
  512. } else {
  513. cellControl = cell[JV.PROP_CONTROL];
  514. }
  515. const area = getProperSignatureArea(cell, cellControl);
  516. if (cell.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) >= 0) {
  517. area[JV.IDX_LEFT] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  518. area[JV.IDX_TOP] = cell[JV.PROP_AREA][JV.PROP_TOP];
  519. area[JV.IDX_RIGHT] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  520. area[JV.IDX_BOTTOM] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  521. }
  522. private_set_cell_pos2(area, theXPos, theYPos);
  523. }
  524. for (let i = 0; i < theShtData[JV.PROP_SIGNATURE_DATE_CELLS].length; i++) {
  525. cell = theShtData[JV.PROP_SIGNATURE_DATE_CELLS][i];
  526. private_set_cell_pos(cell, theXPos, theYPos);
  527. }
  528. for (let i = 0; i < theShtData[JV.PROP_SIGNATURE_AUDIT_CELLS].length; i++) {
  529. cell = theShtData[JV.PROP_SIGNATURE_AUDIT_CELLS][i];
  530. private_set_cell_pos(cell, theXPos, theYPos);
  531. }
  532. for (let i = 0; i < theShtData[JV.PROP_WATERMARK_CELLS].length; i++) {
  533. cell = theShtData[JV.PROP_WATERMARK_CELLS][i];
  534. // private_set_cell_pos(cell, theXPos, theYPos);
  535. let cellControl;
  536. if (typeof cell[JV.PROP_CONTROL] === 'string') {
  537. cellControl = pageData[JV.NODE_CONTROL_COLLECTION][cell[JV.PROP_CONTROL]];
  538. } else {
  539. cellControl = cell[JV.PROP_CONTROL];
  540. }
  541. const area = getProperSignatureArea(cell, cellControl);
  542. if (cell.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) >= 0) {
  543. area[JV.IDX_LEFT] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  544. area[JV.IDX_TOP] = cell[JV.PROP_AREA][JV.PROP_TOP];
  545. area[JV.IDX_RIGHT] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  546. area[JV.IDX_BOTTOM] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  547. }
  548. private_set_cell_pos2(area, theXPos, theYPos);
  549. }
  550. };
  551. xPos.push(0);
  552. if (sheetData) {
  553. // current sheet data
  554. // console.log('preAnalyzePos not single');
  555. yPos.push(0);
  556. self_analyze_sheet_pos(sheetData, xPos, yPos);
  557. xPos.sort(private_array_sort);
  558. yPos.sort(private_array_sort);
  559. } else {
  560. // total data in one sheet
  561. const marginBottomPos = Math.round((pageData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE][1] - parseFloat(pageData[JV.NODE_PAGE_INFO][JV.NODE_MARGINS][JV.PROP_BOTTOM]) / 2.54) * DPI);
  562. // console.log('preAnalyzePos isSingle start');
  563. for (const shtItemData of pageData.items) {
  564. const tmpPos = [];
  565. tmpPos.push(0);
  566. self_analyze_sheet_pos(shtItemData, xPos, tmpPos);
  567. tmpPos.sort(private_array_sort);
  568. if (marginBottomPos - tmpPos[tmpPos.length - 1] > 10) {
  569. // 此逻辑是为了防止打印跨页(假设有些报表模板高度设置离底部margin还好远,导出excel后预览时会发现跨页现象(即下一页的某几行数据会挪到前一页来预览))
  570. tmpPos.push(marginBottomPos - 10);
  571. }
  572. // console.log('preAnalyzePos push to yMultiPos');
  573. yMultiPos.push(tmpPos);
  574. }
  575. xPos.sort(private_array_sort);
  576. yPos.splice(0, yPos.length);
  577. for (const p of yMultiPos[0]) {
  578. yPos.push(p);
  579. }
  580. }
  581. }
  582. function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, appointedMergeBand, hasSignature, sheetIdx, signSheetIdxArr, isFirstSheet, pgBrkIdx) {
  583. const rst = [];
  584. const xPos = [];
  585. const yPos = [];
  586. const yMultiPos = [];
  587. let currentMergeBorder = null;
  588. const headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  589. let currentPageMergePos = null; // 在 JV.PAGING_OPTION_INFINITY 场合应用
  590. const private_getCellIdxStr = function(idx) {
  591. let rst = 'A';
  592. if (idx < 26) {
  593. rst = headerStr[idx];
  594. } else if (idx < 26 * 26 + 26) {
  595. const ti = Math.floor(idx / 26);
  596. const tj = idx % 26;
  597. rst = headerStr[ti - 1] + headerStr[tj];
  598. } else if (idx < 26 * 26 * 26 + 26) {
  599. const ti = Math.floor(idx / (26 * 26));
  600. const tj = Math.floor((idx - ti * 26 * 26) / 26);
  601. const tk = idx % 26;
  602. rst = headerStr[ti - 1] + headerStr[tj - 1] + headerStr[tk];
  603. }
  604. return rst;
  605. };
  606. const private_getSharedStrIdx = function(val) {
  607. let strVal = val;
  608. if (val === null || val === undefined || (typeof val === 'number' && isNaN(val))) {
  609. strVal = '';
  610. }
  611. let rst = sharedStrList.indexOf(strVal);
  612. if (rst < 0) {
  613. sharedStrList.push(strVal);
  614. rst = sharedStrList.length - 1;
  615. }
  616. return rst;
  617. };
  618. const private_getFontId = function(cell) {
  619. let rst = 0;
  620. let hasFont = false;
  621. if (!(stylesObj.fonts)) {
  622. stylesObj.fonts = [];
  623. // for (let i = 0; i < sheetData.font_collection)
  624. }
  625. let sheetFont = null;
  626. if (typeof cell[JV.PROP_FONT] === 'string') {
  627. sheetFont = pageData[JV.NODE_FONT_COLLECTION][cell[JV.PROP_FONT]];
  628. } else {
  629. sheetFont = cell[JV.PROP_FONT];
  630. }
  631. for (let i = 0; i < stylesObj.fonts.length; i++) {
  632. const font = stylesObj.fonts[i];
  633. if (sheetFont) {
  634. if (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]] === sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]] && font.size === Math.floor(sheetFont[JV.FONT_PROPS[1]] * 3 / 4)
  635. && font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] === sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] && font[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]] === sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]]
  636. && font[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]] === sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]]) {
  637. hasFont = true;
  638. rst = i;
  639. break;
  640. }
  641. } else {
  642. break;
  643. }
  644. }
  645. if (!hasFont) {
  646. const font = {};
  647. font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]] = sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]]; // font name
  648. // font.size = Math.round(sheetFont[JV.FONT_PROPS[1]] * 3 / 4);
  649. font.size = Math.floor(sheetFont[JV.FONT_PROPS[1]] * 3 / 4);
  650. font.charset = 134;
  651. font.colorIdx = '8';
  652. font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] = sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]]; // font bold
  653. font[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]] = sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]]; // font italic
  654. font[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]] = sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]]; // font underline
  655. stylesObj.fonts.push(font);
  656. rst = stylesObj.fonts.length - 1;
  657. }
  658. return rst;
  659. };
  660. const private_chkAndGetMergeLine = function(cell, sheetBorder, borderStr, needFurtherChk) {
  661. let rst = 0;
  662. const mergeBorder = currentMergeBorder;
  663. let mergeBand = pageData[JV.BAND_PROP_MERGE_BAND];
  664. if (appointedMergeBand !== null) {
  665. mergeBand = appointedMergeBand;
  666. }
  667. if (sheetBorder[borderStr] && sheetBorder[borderStr][JV.PROP_LINE_WEIGHT] !== undefined) {
  668. rst = sheetBorder[borderStr][JV.PROP_LINE_WEIGHT];
  669. }
  670. if (currentPageMergePos) {
  671. const side = currentPageMergePos[borderStr];
  672. if (side.indexOf(cell[JV.PROP_AREA][borderStr]) >= 0) {
  673. if (needFurtherChk) {
  674. const topSide = currentPageMergePos[JV.PROP_TOP];
  675. const bottomSide = currentPageMergePos[JV.PROP_BOTTOM];
  676. for (let i = 0; i < topSide.length; i++) {
  677. if (cell[JV.PROP_AREA][JV.PROP_TOP] >= topSide[i]) {
  678. if (cell[JV.PROP_AREA][JV.PROP_BOTTOM] <= bottomSide[i]) {
  679. const destStyle = pageData[JV.NODE_STYLE_COLLECTION][mergeBand[JV.PROP_STYLE][JV.PROP_ID]];
  680. rst = destStyle[borderStr][JV.PROP_LINE_WEIGHT];
  681. break;
  682. }
  683. } else {
  684. break;
  685. }
  686. }
  687. } else {
  688. const destStyle = pageData[JV.NODE_STYLE_COLLECTION][mergeBand[JV.PROP_STYLE][JV.PROP_ID]];
  689. rst = destStyle[borderStr][JV.PROP_LINE_WEIGHT];
  690. }
  691. }
  692. } else {
  693. if (mergeBorder && mergeBorder[borderStr] && cell[JV.PROP_AREA][borderStr] === mergeBorder[borderStr]) {
  694. const destStyle = pageData[JV.NODE_STYLE_COLLECTION][mergeBand[JV.PROP_STYLE][JV.PROP_ID]];
  695. if (needFurtherChk) {
  696. if (cell[JV.PROP_AREA][JV.PROP_TOP] >= mergeBorder[JV.PROP_TOP] &&
  697. cell[JV.PROP_AREA][JV.PROP_BOTTOM] <= mergeBorder[JV.PROP_BOTTOM]) {
  698. rst = destStyle[borderStr][JV.PROP_LINE_WEIGHT];
  699. }
  700. } else {
  701. rst = destStyle[borderStr][JV.PROP_LINE_WEIGHT];
  702. }
  703. }
  704. }
  705. return parseInt(rst);
  706. };
  707. const private_checkBorder = function(cell, border, sheetBorder) {
  708. let rst = true;
  709. const borderLineWidths = [];
  710. const sheetBorderLineWidths = [];
  711. borderLineWidths.push(border[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]);
  712. borderLineWidths.push(border[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]);
  713. borderLineWidths.push(border[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]);
  714. borderLineWidths.push(border[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]);
  715. if (sheetBorder[JV.PROP_LEFT] && sheetBorder[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]) {
  716. sheetBorderLineWidths.push(private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_LEFT, true));
  717. } else {
  718. sheetBorderLineWidths.push(0);
  719. }
  720. if (sheetBorder[JV.PROP_RIGHT] && sheetBorder[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]) {
  721. sheetBorderLineWidths.push(private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_RIGHT, true));
  722. } else {
  723. sheetBorderLineWidths.push(0);
  724. }
  725. if (sheetBorder[JV.PROP_TOP] && sheetBorder[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]) {
  726. sheetBorderLineWidths.push(private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_TOP, false));
  727. } else {
  728. sheetBorderLineWidths.push(0);
  729. }
  730. if (sheetBorder[JV.PROP_BOTTOM] && sheetBorder[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]) {
  731. sheetBorderLineWidths.push(private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_BOTTOM, false));
  732. } else {
  733. sheetBorderLineWidths.push(0);
  734. }
  735. for (let i = 0; i < 4; i++) {
  736. if (borderLineWidths[i] != sheetBorderLineWidths[i]) {
  737. rst = false;
  738. break;
  739. }
  740. }
  741. return rst;
  742. };
  743. const private_getIniBorder = function() {
  744. const rst = {};
  745. rst[JV.PROP_LEFT] = {};
  746. rst[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT] = 0;
  747. rst[JV.PROP_RIGHT] = {};
  748. rst[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT] = 0;
  749. rst[JV.PROP_TOP] = {};
  750. rst[JV.PROP_TOP][JV.PROP_LINE_WEIGHT] = 0;
  751. rst[JV.PROP_BOTTOM] = {};
  752. rst[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT] = 0;
  753. return rst;
  754. };
  755. const private_getBorderId = function(cell) {
  756. let rst = 0;
  757. let hasBorder = false;
  758. if (!(stylesObj.borders)) {
  759. stylesObj.borders = [];
  760. }
  761. const sheetBorder = pageData[JV.NODE_STYLE_COLLECTION][cell.style];
  762. const mergedBorder = private_getIniBorder();
  763. mergedBorder[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT] = private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_LEFT, true);
  764. mergedBorder[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT] = private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_RIGHT, true);
  765. mergedBorder[JV.PROP_TOP][JV.PROP_LINE_WEIGHT] = private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_TOP, false);
  766. mergedBorder[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT] = private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_BOTTOM, false);
  767. for (let i = 0; i < stylesObj.borders.length; i++) {
  768. const border = stylesObj.borders[i];
  769. if (private_checkBorder(cell, border, mergedBorder)) {
  770. hasBorder = true;
  771. rst = i;
  772. break;
  773. }
  774. }
  775. if (!hasBorder) {
  776. stylesObj.borders.push(mergedBorder);
  777. rst = stylesObj.borders.length - 1;
  778. }
  779. return rst;
  780. };
  781. const private_checkControl = function(cellControl, sheetControl) {
  782. let rst = true;
  783. for (let i = 0; i < JV.CONTROL_PROPS.length; i++) {
  784. if (cellControl[JV.CONTROL_PROPS[i]] !== sheetControl[JV.CONTROL_PROPS[i]]) {
  785. rst = false;
  786. break;
  787. }
  788. }
  789. return rst;
  790. };
  791. const private_getStyleId = function(cell) {
  792. let rst = 1;
  793. let hasStyle = false;
  794. if (!(stylesObj.cellXfs)) stylesObj.cellXfs = [];
  795. const fontId = private_getFontId(cell);
  796. let fontAngle = 0;
  797. if (typeof cell[JV.PROP_FONT] === 'string') {
  798. fontAngle = parseInt(pageData[JV.NODE_FONT_COLLECTION][cell[JV.PROP_FONT]].FontAngle);
  799. } else {
  800. fontAngle = parseInt(cell[JV.PROP_FONT].FontAngle);
  801. }
  802. const borderId = private_getBorderId(cell);
  803. let cellControl = null;
  804. if (typeof cell[JV.PROP_CONTROL] === 'string') {
  805. cellControl = pageData[JV.NODE_CONTROL_COLLECTION][cell[JV.PROP_CONTROL]];
  806. } else {
  807. cellControl = cell[JV.PROP_CONTROL];
  808. }
  809. for (let i = 0; i < stylesObj.cellXfs.length; i++) {
  810. const sheetControl = stylesObj.cellXfs[i];
  811. if (sheetControl.fontId === fontId && sheetControl.borderId === borderId) {
  812. if (private_checkControl(cellControl, sheetControl)) {
  813. rst = i;
  814. hasStyle = true;
  815. break;
  816. }
  817. }
  818. }
  819. if (!hasStyle) {
  820. const sheetControl = {};
  821. sheetControl.fontId = fontId;
  822. sheetControl.borderId = borderId;
  823. sheetControl.fontAngle = fontAngle;
  824. for (let i = 0; i < JV.CONTROL_PROPS.length; i++) {
  825. sheetControl[JV.CONTROL_PROPS[i]] = cellControl[JV.CONTROL_PROPS[i]];
  826. }
  827. stylesObj.cellXfs.push(sheetControl);
  828. rst = stylesObj.cellXfs.length - 1;
  829. }
  830. return rst;
  831. };
  832. const private_setCols = function() {
  833. // remark: 1 excel unit width = 2.117 mm
  834. rst.push('<cols>');
  835. let w = 0;
  836. for (let i = 1; i < xPos.length - 1; i++) {
  837. w = (xPos[i + 1] - xPos[i]) / DPI * 25.4 / 2.117;
  838. w = Math.round(w * 1000) / 1000;
  839. rst.push('<col min="' + i + '" max="' + i + '" width="' + w + '" customWidth="1"/>');
  840. }
  841. rst.push('<col min="' + (xPos.length - 1) + '" max="' + (xPos.length - 1) + '" width="' + 10 + '" customWidth="1"/>');
  842. rst.push('</cols>');
  843. };
  844. const private_setMergedCells = function() {
  845. let cnt = 0;
  846. rst.push('<mergeCells count="?">');
  847. const startIdx = rst.length - 1;
  848. const self_setMergedCells = function(cells, theYPos, offsetY) {
  849. for (let i = 0; i < cells.length; i++) {
  850. const cell = cells[i];
  851. if (!cell.isStamp) {
  852. const idxR = xPos.indexOf(cell[JV.PROP_AREA][JV.PROP_RIGHT]);
  853. const idxL = xPos.indexOf(cell[JV.PROP_AREA][JV.PROP_LEFT]);
  854. const idxB = theYPos.indexOf(cell[JV.PROP_AREA][JV.PROP_BOTTOM]);
  855. const idxT = theYPos.indexOf(cell[JV.PROP_AREA][JV.PROP_TOP]);
  856. if (idxR - idxL > 1 || idxB - idxT > 1) {
  857. rst.push('<mergeCell ref="' + private_getCellIdxStr(idxL - 1) + (idxT + offsetY) + ':' + private_getCellIdxStr(idxR - 2) + (idxB - 1 + offsetY) + '"/>');
  858. cnt++;
  859. }
  860. }
  861. }
  862. };
  863. if (sheetData) {
  864. // self_setMergedCells(sheetData, yPos, 0);
  865. self_setMergedCells(sheetData[JV.PROP_CELLS], yPos, 0);
  866. self_setMergedCells(sheetData[JV.PROP_INTERACT_CELLS], yPos, 0);
  867. if (sheetData[JV.PROP_SIGNATURE_DATE_CELLS]) self_setMergedCells(sheetData[JV.PROP_SIGNATURE_DATE_CELLS], yPos, 0);
  868. if (sheetData[JV.PROP_SIGNATURE_AUDIT_CELLS]) self_setMergedCells(sheetData[JV.PROP_SIGNATURE_AUDIT_CELLS], yPos, 0);
  869. } else {
  870. let osY = 0;
  871. for (let i = 0; i < pageData.items.length; i++) {
  872. const shtItemData = pageData.items[i];
  873. const tmpPos = yMultiPos[i];
  874. // self_setMergedCells(shtItemData, tmpPos, osY);
  875. self_setMergedCells(shtItemData[JV.PROP_CELLS], tmpPos, osY);
  876. self_setMergedCells(shtItemData[JV.PROP_INTERACT_CELLS], tmpPos, osY);
  877. if (shtItemData[JV.PROP_SIGNATURE_DATE_CELLS]) self_setMergedCells(shtItemData[JV.PROP_SIGNATURE_DATE_CELLS], tmpPos, osY);
  878. if (shtItemData[JV.PROP_SIGNATURE_AUDIT_CELLS]) self_setMergedCells(shtItemData[JV.PROP_SIGNATURE_AUDIT_CELLS], tmpPos, osY);
  879. osY += tmpPos.length - 2;
  880. }
  881. }
  882. rst[startIdx] = '<mergeCells count="' + cnt + '">';
  883. rst.push('</mergeCells>');
  884. };
  885. const private_setSheetData = function() {
  886. // remark: 1 excel unit height = 0.3612 mm
  887. rst.push('<sheetData>');
  888. const spanX = xPos.length - 2;
  889. let cellIdx = 0;
  890. let h = 0;
  891. const self_create_cell = function(cells, rows, theYPos) {
  892. let rowIdx1 = 0;
  893. let colIdx1 = 0;
  894. let rowIdx2 = 0;
  895. let colIdx2 = 0;
  896. for (let cIdx = 0; cIdx < cells.length; cIdx++) {
  897. const styleIdx = private_getStyleId(cells[cIdx]);
  898. rowIdx1 = theYPos.indexOf(cells[cIdx][JV.PROP_AREA][JV.PROP_TOP]);
  899. colIdx1 = xPos.indexOf(cells[cIdx][JV.PROP_AREA][JV.PROP_LEFT]);
  900. if (rowIdx1 <= rows.length) {
  901. let cellObj = rows[rowIdx1 - 1].items[colIdx1 - 1];
  902. cellObj.s = styleIdx;
  903. cellObj.isBlank = false;
  904. if (!(stringUtil.isEmptyString(cells[cIdx][JV.PROP_VALUE]))) {
  905. const valIdx = private_getSharedStrIdx(cells[cIdx][JV.PROP_VALUE]);
  906. cellObj.v = valIdx;
  907. }
  908. rowIdx2 = theYPos.indexOf(cells[cIdx][JV.PROP_AREA][JV.PROP_BOTTOM]);
  909. colIdx2 = xPos.indexOf(cells[cIdx][JV.PROP_AREA][JV.PROP_RIGHT]);
  910. if ((rowIdx2 - rowIdx1 > 1) || (colIdx2 - colIdx1 > 1)) {
  911. for (let i = 0; i < rowIdx2 - rowIdx1; i++) {
  912. for (let j = 0; j < colIdx2 - colIdx1; j++) {
  913. if (i === 0 && j === 0) continue;
  914. cellObj = rows[rowIdx1 - 1 + i].items[colIdx1 - 1 + j];
  915. cellObj.s = styleIdx;
  916. cellObj.isBlank = true;
  917. }
  918. }
  919. }
  920. }
  921. }
  922. };
  923. const self_setDataEx = function(theShtData, theYPos, rowOffset) {
  924. const rows = [];
  925. // 1. build full set of blank rows/cells
  926. for (let i = 1; i < theYPos.length - 1; i++) {
  927. const rowObj = {};
  928. h = (theYPos[i + 1] - theYPos[i]) / DPI * 25.4 / 0.3612;
  929. h = Math.round(h * 1000) / 1000;
  930. rowObj.height = h;
  931. rowObj.r = i + rowOffset;
  932. rowObj.items = [];
  933. rows.push(rowObj);
  934. for (let j = 1; j < xPos.length - 1; j++) {
  935. const colIdxStr = private_getCellIdxStr(j - 1);
  936. const cellObj = {};
  937. cellObj.r = colIdxStr + (i + rowOffset);
  938. cellObj.s = 0;
  939. cellObj.isBlank = true;
  940. rows[i - 1].items.push(cellObj);
  941. }
  942. }
  943. // 2. then fill up the cell style-ids and values
  944. self_create_cell(theShtData[JV.PROP_CELLS], rows, theYPos);
  945. self_create_cell(theShtData[JV.PROP_INTERACT_CELLS], rows, theYPos);
  946. self_create_cell(theShtData[JV.PROP_SIGNATURE_DATE_CELLS], rows, theYPos);
  947. self_create_cell(theShtData[JV.PROP_SIGNATURE_AUDIT_CELLS], rows, theYPos);
  948. // fsUtil.writeObjToFile(newPageData, 'D:/GitHome/ConstructionOperation/tmp/combinedHeader.js');
  949. // console.log('theShtData[JV.PROP_SIGNATURE_AUDIT_CELLS]: ');
  950. // console.log(theShtData[JV.PROP_SIGNATURE_AUDIT_CELLS]);
  951. // 3. then fill up rst
  952. for (let i = 0; i < rows.length; i++) {
  953. rst.push('<row r="' + (i + 1 + rowOffset) + '" spans="1:' + spanX + '" ht="' + rows[i].height + '" customHeight="1">');
  954. for (let j = 0; j < rows[i].items.length; j++) {
  955. const cellObj = rows[i].items[j];
  956. if (cellObj.v === undefined) {
  957. rst.push('<c r="' + cellObj.r + '" s="' + cellObj.s + '"/>');
  958. } else {
  959. rst.push('<c r="' + cellObj.r + '" s="' + cellObj.s + '" t="s">');
  960. rst.push('<v>' + cellObj.v + '</v>');
  961. rst.push('</c>');
  962. }
  963. }
  964. rst.push('</row>');
  965. }
  966. // 4. maybe need to dispose the memory
  967. // ...
  968. };
  969. if (sheetData) {
  970. // current sheet data
  971. currentPageMergePos = sheetData[JV.PAGE_SPECIAL_MERGE_POS];
  972. currentMergeBorder = sheetData[JV.PROP_PAGE_MERGE_BORDER];
  973. if (hasSignature && sheetData[JV.PROP_SIGNATURE_CELLS] && sheetData[JV.PROP_SIGNATURE_CELLS].length > 0) {
  974. // 有签名情况下,还是有必要创建一个dummy cell的(画框用)
  975. _createDummyCell(sheetData[JV.PROP_SIGNATURE_CELLS], sheetData);
  976. }
  977. self_setDataEx(sheetData, yPos, 0);
  978. } else {
  979. // total data in one sheet
  980. let rowOffset = 0;
  981. for (let i = 0; i < pageData.items.length; i++) {
  982. const shtItemData = pageData.items[i];
  983. currentPageMergePos = shtItemData[JV.PAGE_SPECIAL_MERGE_POS];
  984. currentMergeBorder = shtItemData[JV.PROP_PAGE_MERGE_BORDER];
  985. const tmpPos = yMultiPos[i];
  986. // console.log(yMultiPos[i]);
  987. cellIdx = 0;
  988. if (hasSignature && shtItemData[JV.PROP_SIGNATURE_CELLS] && shtItemData[JV.PROP_SIGNATURE_CELLS].length > 0) {
  989. // 有签名情况下,还是有必要创建一个dummy cell的(画框用)
  990. _createDummyCell(shtItemData[JV.PROP_SIGNATURE_CELLS], shtItemData);
  991. }
  992. self_setDataEx(shtItemData, tmpPos, rowOffset);
  993. rowOffset += tmpPos.length - 2;
  994. }
  995. }
  996. rst.push('</sheetData>');
  997. };
  998. preAnalyzePos(pageData, sheetData, xPos, yPos, yMultiPos);
  999. rst.push(dftHeadXml + '\r\n');
  1000. rst.push('<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">');
  1001. const colStr = private_getCellIdxStr(xPos.length - 3);
  1002. rst.push('<dimension ref="A1:' + colStr + '' + yPos.length + '"/>');
  1003. if (isFirstSheet) {
  1004. rst.push('<sheetViews><sheetView showGridLines="1" tabSelected="1" workbookViewId="0">');
  1005. } else {
  1006. rst.push('<sheetViews><sheetView showGridLines="1" workbookViewId="0">');
  1007. }
  1008. // rst.push('<selection sqref="A1:' + colStr + '1"/>');
  1009. rst.push('<selection sqref="A1:A1"/>');
  1010. rst.push('</sheetView></sheetViews>');
  1011. rst.push('<sheetFormatPr defaultRowHeight="13.5"/>');
  1012. private_setCols();
  1013. private_setSheetData();
  1014. private_setMergedCells();
  1015. rst.push('<phoneticPr fontId="1" type="noConversion"/>');
  1016. // rst.push('<pageMargins left="0.315" right="0.215" top="0.315" bottom="0.315" header="0" footer="0"/>');
  1017. rst.push('<pageMargins left="' + (parseFloat(pageData[JV.NODE_PAGE_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) * 0.39375) +
  1018. '" right="0.215" top="0.315" bottom="0.315" header="0" footer="0"/>');
  1019. const paperSizeIdx = JV.PAGES_SIZE_STR.indexOf(paperSize);
  1020. let pStr = '';
  1021. if (paperSizeIdx >= 0) {
  1022. pStr = 'paperSize="' + JV.PAGES_SIZE_IDX[paperSizeIdx] + '"';
  1023. }
  1024. let orientationStr = (pageData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE][0] > pageData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE][1]) ? 'landscape' : 'portrait';
  1025. if (currentPageMergePos) {
  1026. orientationStr = (currentPageMergePos[JV.NODE_PAGE_SIZE][0] > currentPageMergePos[JV.NODE_PAGE_SIZE][1]) ? 'landscape' : 'portrait';
  1027. }
  1028. rst.push('<pageSetup ' + pStr + ' fitToWidth="0" fitToHeight="0" orientation="' + orientationStr + '" />');
  1029. rst.push('<headerFooter alignWithMargins="0"/>');
  1030. // 插入分页符---------------------------
  1031. if (pageData.pageBreaks) {
  1032. let pgBrks = [];
  1033. if (sheetData !== null) {
  1034. pgBrks = pageData.pageBreaks[pgBrkIdx];
  1035. } else {
  1036. pgBrks = pageData.pageBreaks[0];
  1037. }
  1038. if (pgBrks.length > 1) {
  1039. rst.push('<rowBreaks count="' + pgBrks.length + '" manualBreakCount="' + pgBrks.length + '" >');
  1040. for (let pbi = 0; pbi < pgBrks.length; pbi++) {
  1041. rst.push('<brk id="' + pgBrks[pbi] + '" max="16383" man="1" />');
  1042. }
  1043. rst.push('</rowBreaks>');
  1044. }
  1045. }
  1046. // 插入分页符结束---------------------------
  1047. // 图形要放在最后,否则excel会报错(但WPS不会)
  1048. if (hasSignature && (sheetData === null || signSheetIdxArr[sheetIdx])) {
  1049. rst.push('<drawing r:id="rId1"/>');
  1050. }
  1051. rst.push('</worksheet>');
  1052. return rst;
  1053. }
  1054. function writeWorkSheetRels(signSheetIdx) {
  1055. const rst = [];
  1056. rst.push('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');
  1057. rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
  1058. rst.push('<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing" Target="../drawings/drawing' + signSheetIdx + '.xml"/>');
  1059. rst.push('</Relationships>');
  1060. return rst;
  1061. }
  1062. async function writeImage(path, pic) {
  1063. let rst = null;
  1064. if (pic) {
  1065. rst = convertPicBase64ToBlob(pic);
  1066. } else if (path) {
  1067. // 前端方式处理不同,不用考虑哪里(水印也是),直接都一股脑地申请下载即可(重复的浏览器会找cache!)
  1068. let picpath = path; // 前端的path已经是完整的了
  1069. rst = await getBlob(picpath); //这里通过getBlob函数得到的结果已经是所需要的流数据,无需转换
  1070. }
  1071. return rst;
  1072. }
  1073. function writeDrawings(pageData, signKeyArr, signPathArr, isSinglePage, signSheetIdxArr) {
  1074. const rst = [];
  1075. // 优化调整,不再每页都设置一个,重复的签名只需要一个即可(极端case: 13xx多页的签名文档,导出有1.3G大)
  1076. if (isSinglePage) {
  1077. rst.push(writeDrawing(pageData, null, signKeyArr, 0));
  1078. } else {
  1079. for (let i = 0; i < pageData.items.length; i++) {
  1080. if (signSheetIdxArr[i]) {
  1081. rst.push(writeDrawing(pageData, pageData.items[i], signKeyArr, i));
  1082. }
  1083. }
  1084. }
  1085. // */
  1086. return rst;
  1087. }
  1088. function writeDrawing(pageData, sheetData, subSignKeyArr, sheetIdx) {
  1089. const rst = [];
  1090. const xPos = [];
  1091. const yPos = [];
  1092. const yMultiPos = [];
  1093. const private_setSheetDrawingCellData = function(signCell, theYPos, startPicIdx, offsetRow) {
  1094. let cellControl;
  1095. if (typeof signCell[JV.PROP_CONTROL] === 'string') {
  1096. cellControl = pageData[JV.NODE_CONTROL_COLLECTION][signCell[JV.PROP_CONTROL]];
  1097. } else {
  1098. cellControl = signCell[JV.PROP_CONTROL];
  1099. }
  1100. const area = getProperSignatureArea(signCell, cellControl);
  1101. if (signCell.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) >= 0) {
  1102. area[JV.IDX_LEFT] = signCell[JV.PROP_AREA][JV.PROP_LEFT];
  1103. area[JV.IDX_TOP] = signCell[JV.PROP_AREA][JV.PROP_TOP];
  1104. area[JV.IDX_RIGHT] = signCell[JV.PROP_AREA][JV.PROP_RIGHT];
  1105. area[JV.IDX_BOTTOM] = signCell[JV.PROP_AREA][JV.PROP_BOTTOM];
  1106. }
  1107. // 1. from
  1108. // let colIdx = xPos.indexOf(signCell[JV.PROP_AREA][JV.PROP_LEFT]);
  1109. // let rowIdx = theYPos.indexOf(signCell[JV.PROP_AREA][JV.PROP_TOP]) + offsetRow; // 这里要考虑Row的偏移量(多页在同同一个sheet输出)
  1110. let colIdx = xPos.indexOf(area[0]);
  1111. let rowIdx = theYPos.indexOf(area[1]) + offsetRow; // 这里要考虑Row的偏移量(多页在同同一个sheet输出)
  1112. // 因为 xPos, theYPos的首位是0,所以还需要减1
  1113. colIdx--;
  1114. rowIdx--;
  1115. rst.push('<xdr:twoCellAnchor editAs="oneCell">');
  1116. rst.push('<xdr:from>');
  1117. rst.push('<xdr:col>' + colIdx + '</xdr:col>');
  1118. rst.push('<xdr:colOff>0</xdr:colOff>');
  1119. rst.push('<xdr:row>' + rowIdx + '</xdr:row>');
  1120. rst.push('<xdr:rowOff>0</xdr:rowOff>');
  1121. rst.push('</xdr:from>');
  1122. // 2. to
  1123. colIdx = xPos.indexOf(area[2]);
  1124. rowIdx = theYPos.indexOf(area[3]) + offsetRow;
  1125. // 因为 xPos, theYPos的首位是0,所以还需要减1
  1126. colIdx--;
  1127. rowIdx--;
  1128. rst.push('<xdr:to>');
  1129. rst.push('<xdr:col>' + colIdx + '</xdr:col>');
  1130. rst.push('<xdr:colOff>0</xdr:colOff>');
  1131. rst.push('<xdr:row>' + rowIdx + '</xdr:row>');
  1132. rst.push('<xdr:rowOff>0</xdr:rowOff>');
  1133. rst.push('</xdr:to>');
  1134. // 3. pic
  1135. rst.push('<xdr:pic>');
  1136. // 3.1
  1137. rst.push('<xdr:nvPicPr>');
  1138. rst.push('<xdr:cNvPr id="' + startPicIdx + '" name="图片 ' + startPicIdx + '"/>');
  1139. rst.push('<xdr:cNvPicPr><a:picLocks noChangeAspect="1" noChangeArrowheads="1"/></xdr:cNvPicPr>');
  1140. rst.push('</xdr:nvPicPr>');
  1141. // 3.2
  1142. rst.push('<xdr:blipFill>');
  1143. // 重点!!!
  1144. const picIdx = subSignKeyArr.indexOf(signCell.signature_name) + 1;
  1145. // 3.2.1
  1146. rst.push('<a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId' + picIdx + '" cstate="print">');
  1147. rst.push('<a:extLst>');
  1148. rst.push('<a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">'); // 参考excel本身,都是固定的uri
  1149. rst.push('<a14:useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0"/>');
  1150. rst.push('</a:ext>');
  1151. rst.push('</a:extLst>');
  1152. rst.push('</a:blip>');
  1153. // 3.2.2
  1154. rst.push('<a:srcRect/>');
  1155. // 3.2.3
  1156. rst.push('<a:stretch><a:fillRect/></a:stretch>');
  1157. rst.push('</xdr:blipFill>');
  1158. // 3.3
  1159. rst.push('<xdr:spPr bwMode="auto">');
  1160. // 3.3.1
  1161. rst.push('<a:xfrm>');
  1162. // 以下经过Excel及WPS的测试,这数据好像没什么意义,都设为0
  1163. rst.push('<a:off x="0" y="0"/>');
  1164. rst.push('<a:ext cx="0" cy="0"/>');
  1165. rst.push('</a:xfrm>');
  1166. // 3.3.2
  1167. rst.push('<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>');
  1168. // 3.3.3
  1169. rst.push('<a:noFill/>');
  1170. // 3.3.4
  1171. rst.push('<a:extLst>');
  1172. rst.push('<a:ext uri="{909E8E84-426E-40DD-AFC4-6F175D3DCCD1}">');
  1173. rst.push('<a14:hiddenFill xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main">');
  1174. rst.push('<a:solidFill><a:srgbClr val="FFFFFF"/></a:solidFill>');
  1175. rst.push('</a14:hiddenFill>');
  1176. rst.push('</a:ext>');
  1177. rst.push('</a:extLst>');
  1178. // 收尾
  1179. rst.push('</xdr:spPr>');
  1180. rst.push('</xdr:pic>');
  1181. // 4. client Data
  1182. rst.push('<xdr:clientData/>');
  1183. rst.push('</xdr:twoCellAnchor>');
  1184. };
  1185. preAnalyzePos(pageData, sheetData, xPos, yPos, yMultiPos);
  1186. rst.push('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');
  1187. rst.push('<xdr:wsDr xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">');
  1188. // console.log('subSignKeyArr');
  1189. // console.log(subSignKeyArr);
  1190. if (sheetData) {
  1191. // console.log('sheetData');
  1192. let startPicIdx = 2 + sheetIdx * 1000;
  1193. for (const sCell of sheetData[JV.PROP_SIGNATURE_CELLS]) {
  1194. if (subSignKeyArr.indexOf(sCell.signature_name) >= 0) {
  1195. private_setSheetDrawingCellData(sCell, yPos, startPicIdx, 0);
  1196. startPicIdx++;
  1197. }
  1198. }
  1199. for (const sCell of sheetData[JV.PROP_WATERMARK_CELLS]) {
  1200. if (subSignKeyArr.indexOf(sCell.signature_name) >= 0) {
  1201. private_setSheetDrawingCellData(sCell, yPos, startPicIdx, 0);
  1202. startPicIdx++;
  1203. }
  1204. }
  1205. } else {
  1206. // total data in one sheet
  1207. let rowOffset = 0;
  1208. for (let i = 0; i < pageData.items.length; i++) {
  1209. const shtItemData = pageData.items[i];
  1210. const tmpPos = yMultiPos[i];
  1211. let startPicIdx = 2;
  1212. for (const sCell of shtItemData[JV.PROP_SIGNATURE_CELLS]) {
  1213. if (subSignKeyArr.indexOf(sCell.signature_name) >= 0) {
  1214. private_setSheetDrawingCellData(sCell, tmpPos, startPicIdx, rowOffset);
  1215. startPicIdx++;
  1216. }
  1217. }
  1218. for (const sCell of shtItemData[JV.PROP_WATERMARK_CELLS]) {
  1219. if (subSignKeyArr.indexOf(sCell.signature_name) >= 0) {
  1220. private_setSheetDrawingCellData(sCell, tmpPos, startPicIdx, rowOffset);
  1221. startPicIdx++;
  1222. }
  1223. }
  1224. rowOffset += tmpPos.length - 2;
  1225. }
  1226. }
  1227. rst.push('</xdr:wsDr>');
  1228. return rst;
  1229. }
  1230. function writeDrawingsRels(amt, startIdx) {
  1231. const rst = [];
  1232. rst.push('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');
  1233. rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
  1234. for (let idx = 0; idx < amt; idx++) {
  1235. rst.push('<Relationship Id="rId' + (idx + 1) + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/image' + (startIdx + idx + 1) + '.png"/>');
  1236. }
  1237. rst.push('</Relationships>');
  1238. return rst;
  1239. }
  1240. function mergeProperties(orgObj, newObj) {
  1241. const orgPropArr = [];
  1242. const newPropArr = [];
  1243. for (const p in orgObj) {
  1244. orgPropArr.push(p);
  1245. }
  1246. for (const p in newObj) {
  1247. newPropArr.push(p);
  1248. }
  1249. for (let i = 0; i < newPropArr.length; i++) {
  1250. if (orgPropArr.indexOf(newPropArr[i]) < 0) {
  1251. orgObj[newPropArr[i]] = newObj[newPropArr[i]];
  1252. }
  1253. }
  1254. }
  1255. async function resetDummySignature(pageData, roleRel) {
  1256. // 备注:计算草图等其他图形需要额外做些处理
  1257. let dummySignIdx = 0;
  1258. const stampPicKeys = [], stampPicFeatures = [];
  1259. const _resetStampArea = function(stampCell, roleRelItem) {
  1260. const ctrl = pageData[JV.NODE_CONTROL_COLLECTION][stampCell[JV.PROP_CONTROL]];
  1261. const rst = { Left: stampCell.area.Left, Right: stampCell.area.Right, Top: stampCell.area.Top, Bottom: stampCell.area.Bottom };
  1262. let pLeft = stampCell.orgArea.Left,
  1263. pTop = stampCell.orgArea.Top;
  1264. let std_stamp_size_width = STD_COMP_STAMP_SIZE_WIDTH, std_stamp_size_height = STD_COMP_STAMP_SIZE_HEIGHT;
  1265. if (roleRelItem.stampFeature) {
  1266. std_stamp_size_width = parseFloat(roleRelItem.stampFeature.ImageWidth.value);
  1267. std_stamp_size_height = parseFloat(roleRelItem.stampFeature.ImageHeight.value);
  1268. }
  1269. switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  1270. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_LEFT]:
  1271. pLeft = stampCell.orgArea.Left;
  1272. break;
  1273. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_CENTER]:
  1274. pLeft = (stampCell.orgArea.Left + stampCell.orgArea.Right - std_stamp_size_width) / 2;
  1275. break;
  1276. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_RIGHT]:
  1277. pLeft = stampCell.orgArea.Right - std_stamp_size_width;
  1278. break;
  1279. default:break;
  1280. }
  1281. switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
  1282. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_TOP]:
  1283. pTop = stampCell.orgArea.Top;
  1284. break;
  1285. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_CENTER]:
  1286. pTop = (stampCell.orgArea.Top + stampCell.orgArea.Bottom - std_stamp_size_height) / 2;
  1287. break;
  1288. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_BOTTOM]:
  1289. pTop = stampCell.orgArea.Bottom - std_stamp_size_height;
  1290. break;
  1291. default:break;
  1292. }
  1293. stampCell.area.Left = pLeft;
  1294. stampCell.area.Top = pTop;
  1295. stampCell.area.Right = pLeft + std_stamp_size_width;
  1296. stampCell.area.Bottom = pTop + std_stamp_size_height;
  1297. // 最后一步,如超过报表范围,则要调整坐标
  1298. // const maxRect = stampCell.maxRect;
  1299. // if (rst.Left < maxRect[0]) {
  1300. // const width = maxRect[0] - rst.Left;
  1301. // rst.Left += width;
  1302. // rst.Right += width;
  1303. // }
  1304. // if (rst.Top < maxRect[1]) {
  1305. // const height = maxRect[1] - rst.Top;
  1306. // rst.Top += height;
  1307. // rst.Bottom += height;
  1308. // }
  1309. // if (rst.Right > maxRect[2]) {
  1310. // const width = maxRect[2] - rst.Right; // 负
  1311. // rst.Left += width;
  1312. // rst.Right += width;
  1313. // }
  1314. // if (rst.Bottom > maxRect[3]) {
  1315. // const height = maxRect[3] - rst.Bottom;
  1316. // rst.Top += height;
  1317. // rst.Bottom += height;
  1318. // }
  1319. return rst;
  1320. };
  1321. for (let pageIdx = 0; pageIdx < pageData.items.length; pageIdx++) {
  1322. const page = pageData.items[pageIdx];
  1323. if (page[JV.PROP_SIGNATURE_CELLS] && page[JV.PROP_SIGNATURE_CELLS].length > 0) {
  1324. for (const signatureCell of page[JV.PROP_SIGNATURE_CELLS]) {
  1325. if (signatureCell.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) >= 0) {
  1326. // 表示这是一个其他类型的非原生电子签名图,只是借用signature的处理机制,每个图都是唯一的,所以需要重新给个唯一的新signature_name
  1327. // signatureCell.signature_name = signatureCell.signature_name + '_' + pageIdx + '_' + dummySignIdx;
  1328. signatureCell.signature_name = signatureCell.signature_name + '_' + page.page_seq + '_' + dummySignIdx; // page_seq在分页后都不会变动
  1329. dummySignIdx++;
  1330. const roleRelItem = { type: '用户', sign_path: signatureCell.path, signature_name: signatureCell.signature_name };
  1331. if (signatureCell.isStamp) {
  1332. let stmpIdx = stampPicKeys.indexOf(signatureCell.path);
  1333. if (stampPicKeys.indexOf(signatureCell.path) < 0) {
  1334. stampPicKeys.push(signatureCell.path);
  1335. stmpIdx = stampPicKeys.length - 1;
  1336. const picRes = await getHttpBlobText(signatureCell.path + '?x-oss-process=image/info');
  1337. stampPicFeatures.push(picRes);
  1338. }
  1339. // { "FileSize": {"value": "2514"}, "Format": {"value": "png"}, "ImageHeight": {"value": "94"}, "ImageWidth": {"value": "94"} }
  1340. roleRelItem.stampFeature = stampPicFeatures[stmpIdx];
  1341. // 重新处理cell坐标
  1342. _resetStampArea(signatureCell, roleRelItem);
  1343. }
  1344. roleRel.push(roleRelItem);
  1345. }
  1346. }
  1347. }
  1348. }
  1349. }
  1350. function _createDummyCell(dummyOrgCells, parentPage) {
  1351. for (const signature of dummyOrgCells) {
  1352. if (!signature.isStamp) {
  1353. const dummyCell = {
  1354. font: 'Content',
  1355. control: 'Default',
  1356. style: 'Default_None',
  1357. Value: '',
  1358. area: { Left: 0, Right: 0, Top: 0, Bottom: 0 },
  1359. };
  1360. if (signature.style) dummyCell.style = signature.style;
  1361. dummyCell[JV.PROP_AREA][JV.PROP_LEFT] = signature[JV.PROP_AREA][JV.PROP_LEFT];
  1362. dummyCell[JV.PROP_AREA][JV.PROP_RIGHT] = signature[JV.PROP_AREA][JV.PROP_RIGHT];
  1363. dummyCell[JV.PROP_AREA][JV.PROP_TOP] = signature[JV.PROP_AREA][JV.PROP_TOP];
  1364. dummyCell[JV.PROP_AREA][JV.PROP_BOTTOM] = signature[JV.PROP_AREA][JV.PROP_BOTTOM];
  1365. parentPage[JV.PROP_CELLS].push(dummyCell);
  1366. }
  1367. }
  1368. }
  1369. function createDummySignatureCell(pageData) {
  1370. for (let pageIdx = 0; pageIdx < pageData.items.length; pageIdx++) {
  1371. const page = pageData.items[pageIdx];
  1372. if (page[JV.PROP_SIGNATURE_CELLS] && page[JV.PROP_SIGNATURE_CELLS].length > 0) {
  1373. _createDummyCell(page[JV.PROP_SIGNATURE_CELLS], page);
  1374. }
  1375. if (page[JV.PROP_SIGNATURE_DATE_CELLS] && page[JV.PROP_SIGNATURE_DATE_CELLS].length > 0) {
  1376. _createDummyCell(page[JV.PROP_SIGNATURE_DATE_CELLS], page);
  1377. }
  1378. if (page[JV.PROP_SIGNATURE_AUDIT_CELLS] && page[JV.PROP_SIGNATURE_AUDIT_CELLS].length > 0) {
  1379. _createDummyCell(page[JV.PROP_SIGNATURE_AUDIT_CELLS], page);
  1380. }
  1381. }
  1382. }
  1383. function _checkAndSetSignatureCache(pageData, signKeyArr, signPathArr, roleRel, signSheetIdxArr, isSinglePage, checkAudit = false) {
  1384. // 备注:电子签名是以图形的方式处理,一页可以有多个签名,多页的签名基本是引用同样的图片,在这里先处理一下,后期统一引用。
  1385. // 另:以后的图片(在电子签名(signature_cells)以外的图片)会单独处理(如计算草图、水印等)
  1386. let rst = false;
  1387. let chkRoles = [];
  1388. if (roleRel instanceof Array) {
  1389. chkRoles = roleRel;
  1390. } else {
  1391. if (roleRel) chkRoles.push(roleRel);
  1392. }
  1393. const _getDupPicPath = function(path) {
  1394. let rst = null;
  1395. for (const sp of signPathArr) {
  1396. if (sp.path === path) {
  1397. rst = sp;
  1398. break;
  1399. }
  1400. }
  1401. return rst;
  1402. };
  1403. for (let pageIdx = 0; pageIdx < pageData.items.length; pageIdx++) {
  1404. const page = pageData.items[pageIdx];
  1405. // 优化调整,不再每页都设置一个,重复的签名只需要一个即可(极端case: 13xx多页的签名文档,导出有1.3G大)
  1406. const curSignIdx = signKeyArr.length - 1;
  1407. signSheetIdxArr[pageIdx] = false;
  1408. if (page[JV.PROP_SIGNATURE_CELLS] && page[JV.PROP_SIGNATURE_CELLS].length > 0) {
  1409. for (const signatureCell of page[JV.PROP_SIGNATURE_CELLS]) {
  1410. // 这里把图片的路径作为key值判断
  1411. if (signKeyArr.indexOf(signatureCell.signature_name) < 0) {
  1412. // 还得判断用户是否有选择签名输出
  1413. for (const role of chkRoles) {
  1414. if (signatureCell.signature_name === role.signature_name) {
  1415. if (!(role.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) < 0 && role.sign_output.indexOf('normal_sign') < 0)) {
  1416. if (!checkAudit || role.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) >= 0 || _chkIfAudit(role)) {
  1417. // 如果签名但用户并没有选择显示签名,则不输出!
  1418. if (signatureCell.isStamp) {
  1419. //签章不能用role的图片!!!
  1420. let sPObj = _getDupPicPath(signatureCell.path);
  1421. if (sPObj !== null && isSinglePage) { // 只有在isSinglePage为true时,才需要优化签名
  1422. signatureCell.signature_name = sPObj.signature_name; // 重点,如果有相同路径的,修改signature_name!
  1423. rst = true;
  1424. } else {
  1425. const signPath = { signature_name: signatureCell.signature_name, path: null, pic: null };
  1426. signPathArr.push(signPath);
  1427. signPath.path = signatureCell.path;
  1428. signKeyArr.push(signatureCell.signature_name);
  1429. rst = true;
  1430. signSheetIdxArr[pageIdx] = true;
  1431. }
  1432. } else if (role.sign_pic) {
  1433. const signPath = { signature_name: signatureCell.signature_name, path: null, pic: null };
  1434. signPathArr.push(signPath);
  1435. signPath.pic = role.sign_pic;
  1436. signKeyArr.push(signatureCell.signature_name);
  1437. rst = true;
  1438. signSheetIdxArr[pageIdx] = true;
  1439. } else if (role.sign_path) {
  1440. let sPObj = _getDupPicPath(role.sign_path);
  1441. if (sPObj !== null && isSinglePage) { // 只有在isSinglePage为true时,才需要优化签名
  1442. signatureCell.signature_name = sPObj.signature_name; // 重点,如果有相同路径的,修改signature_name!
  1443. rst = true;
  1444. } else {
  1445. const signPath = { signature_name: signatureCell.signature_name, path: null, pic: null };
  1446. signPathArr.push(signPath);
  1447. signPath.path = role.sign_path;
  1448. signKeyArr.push(signatureCell.signature_name);
  1449. rst = true;
  1450. signSheetIdxArr[pageIdx] = true;
  1451. }
  1452. }
  1453. }
  1454. }
  1455. break;
  1456. }
  1457. }
  1458. } else {
  1459. // console.log(`duplicate signature: ${signatureCell.signature_name}`);
  1460. // signSheetIdxArr[pageIdx] = true;
  1461. }
  1462. }
  1463. }
  1464. if (page[JV.PROP_WATERMARK_CELLS] && page[JV.PROP_WATERMARK_CELLS].length > 0) {
  1465. // 水印,单独处理
  1466. const waterMarkCell = page[JV.PROP_WATERMARK_CELLS][0];
  1467. if (signKeyArr.indexOf(waterMarkCell.signature_name) < 0) {
  1468. const signPath = { path: null, pic: null };
  1469. signPathArr.push(signPath);
  1470. signPath.pic = waterMarkCell.pic;
  1471. signPath.path = waterMarkCell.path;
  1472. signKeyArr.push(waterMarkCell.signature_name);
  1473. rst = true;
  1474. signSheetIdxArr[pageIdx] = true;
  1475. } else if (!isSinglePage) {
  1476. signSheetIdxArr[pageIdx] = true;
  1477. }
  1478. }
  1479. }
  1480. return rst;
  1481. }
  1482. function _chkIfAudit(role_rel) {
  1483. // STAGE_AUDIT, STAGE_LIST 已在index.ejs定义
  1484. let rst = false;
  1485. for (const stg_audit of STAGE_AUDIT) {
  1486. if (role_rel.acc_id === stg_audit.aid) {
  1487. if (stg_audit.status === 3) {
  1488. rst = true;
  1489. } else {
  1490. rst = false;
  1491. }
  1492. // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
  1493. }
  1494. }
  1495. if (!rst) {
  1496. // 还有原报需要检测
  1497. for (const stg_ort_rpt of STAGE_LIST) {
  1498. if (role_rel.acc_id === stg_ort_rpt.user_id) {
  1499. if (stg_ort_rpt.status !== 1 && stg_ort_rpt.status !== 4) {
  1500. // 只要不是待上报(1)、退回审批(4) 状态,都需要显示
  1501. rst = true;
  1502. } else {
  1503. rst = false;
  1504. }
  1505. // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
  1506. }
  1507. }
  1508. }
  1509. // rst = true; //测试,未来将屏蔽
  1510. return rst;
  1511. }
  1512. const excelExportUtil = {
  1513. exportExcel: async function(pageData, paperSize, fName, options, custSheetNames, custSheetMergeBands, roleRel, callback, checkAudit = false) {
  1514. const rptOptions = ({ singlePage: false, fileName: 'report' });
  1515. if (options === 'true' || options === true) {
  1516. rptOptions.singlePage = true;
  1517. }
  1518. const isSinglePage = rptOptions.singlePage;
  1519. const sheets = [];
  1520. const signKeyArr = [];
  1521. const signPathArr = [];
  1522. const signSheetIdxArr = []; // 确定哪些sheet有签名(在多表导出的时候,有些表可能没有签名,但其他的表有签名)
  1523. let thisRoleRel = [];
  1524. if (roleRel !== null && roleRel !== undefined) {
  1525. thisRoleRel = JSON.parse(JSON.stringify(roleRel));
  1526. }
  1527. await rptSignatureHelper.resetDummySignature(pageData, thisRoleRel, true); // 把草图转换一下roleRel
  1528. // const hasSignature = false; // 暂时不支持电子签名、草图导出excel
  1529. const hasSignature = _checkAndSetSignatureCache(pageData, signKeyArr, signPathArr, thisRoleRel, signSheetIdxArr, isSinglePage, checkAudit); // 因草图的关系,thisRoleRel是否为null就不是充要的条件
  1530. if (!hasSignature) {
  1531. createDummySignatureCell(pageData);
  1532. }
  1533. if (isSinglePage) {
  1534. // 加分页符(分页符要在外部处理好)-------------------
  1535. _setupPgBrks(pageData);
  1536. // 加分页符结束-------------------
  1537. sheets.push({ sheetName: '全部页' });
  1538. } else {
  1539. if (custSheetNames && custSheetNames.length === pageData.items.length) {
  1540. for (let i = 0; i < pageData.items.length; i++) {
  1541. sheets.push({ sheetName: custSheetNames[i] });
  1542. }
  1543. } else {
  1544. for (let i = 0; i < pageData.items.length; i++) {
  1545. sheets.push({ sheetName: '第' + (i + 1) + '页' });
  1546. }
  1547. }
  1548. }
  1549. // 1.
  1550. let file = '[Content_Types].xml';
  1551. let data = writeContentTypes(sheets, isSinglePage, hasSignature);
  1552. const zip = new JSZip();
  1553. zip.file(file, data.join(''), { compression: 'DEFLATE' });
  1554. // 2.
  1555. const zip_rels = zip.folder('_rels');
  1556. file = '.rels';
  1557. data = writeRootRels();
  1558. zip_rels.file(file, data.join(''), { compression: 'DEFLATE' });
  1559. // 3.
  1560. const zip_docProps = zip.folder('docProps');
  1561. file = 'app.xml';
  1562. data = writeApp(sheets, isSinglePage);
  1563. zip_docProps.file(file, data.join(''), { compression: 'DEFLATE' });
  1564. file = 'core.xml';
  1565. data = writeCore();
  1566. zip_docProps.file(file, data.join(''), { compression: 'DEFLATE' });
  1567. // 4.
  1568. const zip_xl = zip.folder('xl');
  1569. file = 'workbook.xml';
  1570. data = writeXlWorkBook(sheets, isSinglePage);
  1571. zip_xl.file(file, data.join(''), { compression: 'DEFLATE' });
  1572. const zip_rels2 = zip_xl.folder('_rels');
  1573. file = 'workbook.xml.rels';
  1574. data = writeXlRels(sheets, isSinglePage);
  1575. zip_rels2.file(file, data.join(''), { compression: 'DEFLATE' });
  1576. // 5.
  1577. const zip_theme = zip_xl.folder('theme');
  1578. file = 'theme1.xml';
  1579. data = writeTheme();
  1580. zip_theme.file(file, data, { compression: 'DEFLATE' });
  1581. if (hasSignature) {
  1582. // 5.1 写所有的image
  1583. const zip_media = zip_xl.folder('media');
  1584. let picIdx = 0;
  1585. // 优化调整,不再每页都设置一个,重复的签名只需要一个即可(极端case: 13xx多页的签名文档,导出有1.3G大)
  1586. for (let pathIdx = 0; pathIdx < signPathArr.length; pathIdx++) {
  1587. picIdx++;
  1588. data = await writeImage(signPathArr[pathIdx].path, signPathArr[pathIdx].pic);
  1589. file = 'image' + picIdx + '.png';
  1590. zip_media.file(file, data, { compression: 'DEFLATE' });
  1591. }
  1592. // 5.2
  1593. const zip_drawings = zip_xl.folder('drawings');
  1594. data = writeDrawings(pageData, signKeyArr, signPathArr, isSinglePage, signSheetIdxArr);
  1595. // data = writeDrawings(pageData, signKeyArr, signPathArr, false, signSheetIdxArr); // 备注:这里根本不需要考虑是否single page
  1596. for (let psIdx = 0; psIdx < data.length; psIdx++) {
  1597. file = 'drawing' + (psIdx + 1) + '.xml';
  1598. zip_drawings.file(file, data[psIdx].join(''), { compression: 'DEFLATE' });
  1599. }
  1600. // 5.3
  1601. const zip_drawings_rels = zip_drawings.folder('_rels');
  1602. let relsIdx = 0;
  1603. let relsImgAmt = 0;
  1604. for (let ssIdx = 0; ssIdx < signKeyArr.length; ssIdx++) {
  1605. data = writeDrawingsRels(signKeyArr.length, relsImgAmt); // 一个drawingX.xml.rels文件与一个drawingX.xml对应
  1606. relsIdx++;
  1607. if (isSinglePage) {
  1608. relsImgAmt += signKeyArr.length;
  1609. }
  1610. file = 'drawing' + relsIdx + '.xml.rels';
  1611. zip_drawings_rels.file(file, data.join(''), { compression: 'DEFLATE' });
  1612. }
  1613. }
  1614. // 6.
  1615. const zip_xl_worksheets = zip_xl.folder('worksheets');
  1616. const sharedStrList = [];
  1617. const stylesObj = {};
  1618. data = writeSheets(pageData, paperSize, sharedStrList, stylesObj, isSinglePage, custSheetMergeBands, hasSignature, signSheetIdxArr);
  1619. if (isSinglePage) {
  1620. for (let i = 0; i < 1; i++) {
  1621. file = 'sheet' + (i + 1) + '.xml';
  1622. zip_xl_worksheets.file(file, data[i].join(''), { compression: 'DEFLATE' });
  1623. }
  1624. } else {
  1625. for (let i = 0; i < data.length; i++) {
  1626. file = 'sheet' + (i + 1) + '.xml';
  1627. zip_xl_worksheets.file(file, data[i].join(''), { compression: 'DEFLATE' });
  1628. }
  1629. }
  1630. // 7.
  1631. if (hasSignature) {
  1632. const zip_xl_worksheets_rels = zip_xl_worksheets.folder('_rels');
  1633. if (isSinglePage) {
  1634. data = writeWorkSheetRels(1);
  1635. file = 'sheet1.xml.rels';
  1636. zip_xl_worksheets_rels.file(file, data.join(''), { compression: 'DEFLATE' });
  1637. } else {
  1638. let ssIdx = 0;
  1639. for (let i = 0; i < data.length; i++) {
  1640. if (signSheetIdxArr[i]) {
  1641. ssIdx++;
  1642. const ssData = writeWorkSheetRels(ssIdx);
  1643. file = 'sheet' + (i + 1) + '.xml.rels';
  1644. zip_xl_worksheets_rels.file(file, ssData.join(''), { compression: 'DEFLATE' });
  1645. }
  1646. }
  1647. }
  1648. }
  1649. file = 'sharedStrings.xml';
  1650. data = writeSharedString(sharedStrList);
  1651. zip_xl.file(file, data.join(''), { compression: 'DEFLATE' });
  1652. file = 'styles.xml';
  1653. data = writeStyles(stylesObj, hasSignature);
  1654. zip_xl.file(file, data.join(''), { compression: 'DEFLATE' });
  1655. zip.generateAsync({type: 'blob'}).then(function(content){
  1656. saveAs(content, `${fName}.xlsx`); // 页面需要引用 FileSaver.js 才有这个方法
  1657. });
  1658. },
  1659. exportExcelInOneBook: async function(pageDataArray, paperSize, fName, roleRelArr, callback, checkAudit = false) {
  1660. const me = this;
  1661. const newPageData = {};
  1662. // 1. 重新编排一下数据,把一份报表的pageData合并到一起作为一个Sheet输出(需要重新调整数据纵向坐标),多份报表数据就形成多个Sheet
  1663. // -- 简单来说,就是重新包装数据
  1664. try {
  1665. // 1.1 newPageData外围属性
  1666. const newContrl = {};
  1667. const newFont = {};
  1668. const newStyle = {};
  1669. const custMergeBands = [];
  1670. for (let i = 0; i < pageDataArray.length; i++) {
  1671. mergeProperties(newContrl, pageDataArray[i][JV.NODE_CONTROL_COLLECTION]);
  1672. mergeProperties(newFont, pageDataArray[i][JV.NODE_FONT_COLLECTION]);
  1673. mergeProperties(newStyle, pageDataArray[i][JV.NODE_STYLE_COLLECTION]);
  1674. }
  1675. newPageData[JV.NODE_CONTROL_COLLECTION] = newContrl;
  1676. newPageData[JV.NODE_FONT_COLLECTION] = newFont;
  1677. newPageData[JV.NODE_STYLE_COLLECTION] = newStyle;
  1678. newPageData[JV.NODE_PAGE_INFO] = pageDataArray[0][JV.NODE_PAGE_INFO];
  1679. newPageData[JV.BAND_PROP_MERGE_BAND] = pageDataArray[0][JV.BAND_PROP_MERGE_BAND];
  1680. // 1.2 重新设置pageDataArray的各个cell的Top/Bottom坐标
  1681. const sheetNames = [];
  1682. const newPagePos = [];
  1683. for (let i = 0; i < pageDataArray.length; i++) {
  1684. let offsetY = 0;
  1685. const mergeBand = {};
  1686. custMergeBands.push(pageDataArray[i][JV.BAND_PROP_MERGE_BAND]);
  1687. // 备注:不同的报表有可能有不同的边框,如封面表就是无边框的
  1688. mergeBand[JV.PROP_LEFT] = [];
  1689. mergeBand[JV.PROP_RIGHT] = [];
  1690. mergeBand[JV.PROP_TOP] = [];
  1691. mergeBand[JV.PROP_BOTTOM] = [];
  1692. newPagePos.push(mergeBand);
  1693. mergeBand[JV.PROP_LEFT].push(pageDataArray[i][JV.BAND_PROP_MERGE_BAND][JV.PROP_LEFT]);
  1694. mergeBand[JV.PROP_RIGHT].push(pageDataArray[i][JV.BAND_PROP_MERGE_BAND][JV.PROP_RIGHT]);
  1695. sheetNames.push(pageDataArray[i][JV.NODE_PAGE_INFO][JV.NODE_MAIN_INFO_RPT_NAME]);
  1696. // 加分页符(分页符要在外部处理好)-------------------
  1697. _setupPgBrks(pageDataArray[i]);
  1698. // 加分页符结束-------------------
  1699. let maxY = 0;
  1700. let minY = 100000;
  1701. const checkAndResetCellYPos = function(cells) {
  1702. if (cells && cells.length > 0) {
  1703. for (const cell of cells) {
  1704. if (maxY < cell[JV.PROP_AREA][JV.PROP_BOTTOM]) {
  1705. maxY = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  1706. }
  1707. if (minY > cell[JV.PROP_AREA][JV.PROP_TOP]) {
  1708. minY = cell[JV.PROP_AREA][JV.PROP_TOP];
  1709. }
  1710. cell[JV.PROP_AREA][JV.PROP_BOTTOM] += offsetY;
  1711. cell[JV.PROP_AREA][JV.PROP_TOP] += offsetY;
  1712. }
  1713. }
  1714. };
  1715. for (let j = 0; j < pageDataArray[i].items.length; j++) {
  1716. maxY = 0;
  1717. minY = 100000;
  1718. if (pageDataArray[i].items[j][JV.PAGE_SPECIAL_MERGE_POS]) {
  1719. let pos = pageDataArray[i].items[j][JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_TOP][0] + offsetY;
  1720. mergeBand[JV.PROP_TOP].push(pos);
  1721. pos = pageDataArray[i].items[j][JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_BOTTOM][0] + offsetY;
  1722. mergeBand[JV.PROP_BOTTOM].push(pos);
  1723. } else if (pageDataArray[i].items[j][JV.PROP_PAGE_MERGE_BORDER]) {
  1724. let pos = pageDataArray[i].items[j][JV.PROP_PAGE_MERGE_BORDER][JV.PROP_TOP] + offsetY;
  1725. mergeBand[JV.PROP_TOP].push(pos);
  1726. pos = pageDataArray[i].items[j][JV.PROP_PAGE_MERGE_BORDER][JV.PROP_BOTTOM] + offsetY;
  1727. mergeBand[JV.PROP_BOTTOM].push(pos);
  1728. } else {
  1729. mergeBand[JV.PROP_TOP].push(pageDataArray[i][JV.BAND_PROP_MERGE_BAND][JV.PROP_TOP] + offsetY);
  1730. mergeBand[JV.PROP_BOTTOM].push(pageDataArray[i][JV.BAND_PROP_MERGE_BAND][JV.PROP_BOTTOM] + offsetY);
  1731. }
  1732. // 1.2.1 重新设置普通cells的Top Bottom坐标
  1733. checkAndResetCellYPos(pageDataArray[i].items[j][JV.PROP_CELLS]);
  1734. checkAndResetCellYPos(pageDataArray[i].items[j][JV.PROP_INTERACT_CELLS]);
  1735. // 1.2.2 重新设置电子签名cells的Top Bottom坐标
  1736. checkAndResetCellYPos(pageDataArray[i].items[j][JV.PROP_SIGNATURE_CELLS]);
  1737. // 1.2.3 重新设置电子签名日期cells的Top Bottom坐标
  1738. checkAndResetCellYPos(pageDataArray[i].items[j][JV.PROP_SIGNATURE_DATE_CELLS]);
  1739. // 1.2.4 重置电子签名审核意见cells的Top Bottom坐标
  1740. checkAndResetCellYPos(pageDataArray[i].items[j][JV.PROP_SIGNATURE_AUDIT_CELLS]);
  1741. // 1.2.5 重置水印的Top Bottom坐标
  1742. checkAndResetCellYPos(pageDataArray[i].items[j][JV.PROP_WATERMARK_CELLS]);
  1743. const bottomGap = Math.round((pageDataArray[i][JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE][1] - parseFloat(pageDataArray[i][JV.NODE_PAGE_INFO][JV.NODE_MARGINS][JV.PROP_BOTTOM]) / 2.54) * DPI) - maxY;
  1744. offsetY += (maxY - minY);
  1745. if (bottomGap > 10) {
  1746. offsetY += (bottomGap - 10);
  1747. }
  1748. }
  1749. }
  1750. // 2. newPageData的items属性及相关分页符
  1751. newPageData.items = [];
  1752. newPageData.pageBreaks = [];
  1753. for (let i = 0; i < pageDataArray.length; i++) {
  1754. const pageItem = {};
  1755. pageItem[JV.PROP_PAGE_SEQ] = i + 1;
  1756. pageItem[JV.PROP_CELLS] = [];
  1757. for (let j = 0; j < pageDataArray[i].items.length; j++) {
  1758. for (let k = 0; k < pageDataArray[i].items[j][JV.PROP_CELLS].length; k++) {
  1759. pageItem[JV.PROP_CELLS].push(pageDataArray[i].items[j][JV.PROP_CELLS][k]);
  1760. }
  1761. }
  1762. pageItem[JV.PROP_INTERACT_CELLS] = [];
  1763. for (let j = 0; j < pageDataArray[i].items.length; j++) {
  1764. for (let k = 0; k < pageDataArray[i].items[j][JV.PROP_INTERACT_CELLS].length; k++) {
  1765. pageItem[JV.PROP_INTERACT_CELLS].push(pageDataArray[i].items[j][JV.PROP_INTERACT_CELLS][k]);
  1766. }
  1767. }
  1768. pageItem[JV.PROP_SIGNATURE_CELLS] = [];
  1769. for (let j = 0; j < pageDataArray[i].items.length; j++) {
  1770. for (let k = 0; k < pageDataArray[i].items[j][JV.PROP_SIGNATURE_CELLS].length; k++) {
  1771. pageItem[JV.PROP_SIGNATURE_CELLS].push(pageDataArray[i].items[j][JV.PROP_SIGNATURE_CELLS][k]);
  1772. }
  1773. }
  1774. pageItem[JV.PROP_SIGNATURE_DATE_CELLS] = [];
  1775. for (let j = 0; j < pageDataArray[i].items.length; j++) {
  1776. for (let k = 0; k < pageDataArray[i].items[j][JV.PROP_SIGNATURE_DATE_CELLS].length; k++) {
  1777. pageItem[JV.PROP_SIGNATURE_DATE_CELLS].push(pageDataArray[i].items[j][JV.PROP_SIGNATURE_DATE_CELLS][k]);
  1778. }
  1779. }
  1780. pageItem[JV.PROP_SIGNATURE_AUDIT_CELLS] = [];
  1781. for (let j = 0; j < pageDataArray[i].items.length; j++) {
  1782. for (let k = 0; k < pageDataArray[i].items[j][JV.PROP_SIGNATURE_AUDIT_CELLS].length; k++) {
  1783. pageItem[JV.PROP_SIGNATURE_AUDIT_CELLS].push(pageDataArray[i].items[j][JV.PROP_SIGNATURE_AUDIT_CELLS][k]);
  1784. }
  1785. }
  1786. pageItem[JV.PROP_WATERMARK_CELLS] = [];
  1787. for (let j = 0; j < pageDataArray[i].items.length; j++) {
  1788. for (let k = 0; k < pageDataArray[i].items[j][JV.PROP_WATERMARK_CELLS].length; k++) {
  1789. pageItem[JV.PROP_WATERMARK_CELLS].push(pageDataArray[i].items[j][JV.PROP_WATERMARK_CELLS][k]);
  1790. }
  1791. }
  1792. newPagePos[i][JV.NODE_PAGE_SIZE] = pageDataArray[i][JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE];
  1793. pageItem[JV.PAGE_SPECIAL_MERGE_POS] = newPagePos[i];
  1794. newPageData.items.push(pageItem);
  1795. // 重新分配分页符()------------------
  1796. if (pageDataArray[i].pageBreaks.length === 1) {
  1797. newPageData.pageBreaks.push(pageDataArray[i].pageBreaks[0]);
  1798. } else {
  1799. newPageData.pageBreaks.push([]);
  1800. }
  1801. // 重新分配分页符结束------------------
  1802. }
  1803. // 3. everything is ok, then call me
  1804. await me.exportExcel(newPageData, paperSize, fName, 'false', sheetNames, custMergeBands, roleRelArr, callback, checkAudit);
  1805. } catch (e) {
  1806. console.log(e);
  1807. }
  1808. }
  1809. };
  1810. function convertPicBase64ToBlob(picdata) {
  1811. //去掉头(如:'data:image/png;base64,'),并转换为byte
  1812. let splitPic = picdata.split(',');
  1813. let tmpPicData = '';
  1814. if (splitPic.length === 2) {
  1815. tmpPicData = splitPic[1];
  1816. } else {
  1817. tmpPicData = splitPic[0];
  1818. }
  1819. var bytes = window.atob(tmpPicData);
  1820. //处理异常,将ascii码小于0的转换为大于0
  1821. var ab = new Uint8Array(bytes.length);
  1822. for (var i = 0; i < bytes.length; i++) {
  1823. ab[i] = bytes.charCodeAt(i);
  1824. }
  1825. return new Blob([ab], { type: 'application/pdf' });
  1826. }