rpt_excel_util.js 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664
  1. 'use strict';
  2. /**
  3. * Created by Tony on 2017/4/1.
  4. */
  5. const JV = require('../rpt_component/jpc_value_define');
  6. const fs = require('fs');
  7. const JSZip = require('jszip');
  8. const strUtil = require('../public/stringUtil');
  9. const jpcCmnHelper = require('../rpt_component/helper/jpc_helper_common');
  10. const DPI = jpcCmnHelper.getScreenDPI()[0];
  11. const fsUtil = require('../public/fsUtil');
  12. const dftHeadXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
  13. const uuidV1 = require('uuid/v1');
  14. const atob = require('atob');
  15. function writeContentTypes(sheets, isSinglePage, hasSignature) {
  16. const rst = [];
  17. rst.push(dftHeadXml + '\r\n');
  18. rst.push('<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">');
  19. rst.push('<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>');
  20. rst.push('<Default Extension="xml" ContentType="application/xml"/>');
  21. if (hasSignature) {
  22. rst.push('<Default Extension="png" ContentType="image/png"/>');
  23. }
  24. rst.push('<Override PartName="/xl/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>');
  25. rst.push('<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>');
  26. rst.push('<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>');
  27. rst.push('<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>');
  28. rst.push('<Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>');
  29. if (isSinglePage) {
  30. rst.push('<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>');
  31. if (hasSignature) {
  32. rst.push('<Override PartName="/xl/drawings/drawing1.xml" ContentType="application/vnd.openxmlformats-officedocument.drawing+xml"/>');
  33. }
  34. } else {
  35. for (let i = 0; i < sheets.length; i++) {
  36. rst.push('<Override PartName="/xl/worksheets/sheet' + (i + 1) + '.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>');
  37. if (hasSignature) {
  38. rst.push('<Override PartName="/xl/drawings/drawing' + (i + 1) + '.xml" ContentType="application/vnd.openxmlformats-officedocument.drawing+xml"/>');
  39. }
  40. }
  41. }
  42. rst.push('<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>');
  43. rst.push('</Types>');
  44. return rst;
  45. }
  46. function writeRootRels() {
  47. const rst = [];
  48. rst.push(dftHeadXml + '\r\n');
  49. rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
  50. rst.push('<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>');
  51. rst.push('<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>');
  52. rst.push('<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>');
  53. rst.push('</Relationships>');
  54. return rst;
  55. }
  56. function writeApp(sheets, isSinglePage) {
  57. const rst = [];
  58. rst.push(dftHeadXml + '\r\n');
  59. rst.push('<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">');
  60. rst.push('<Application>Microsoft Excel</Application>');
  61. rst.push('<DocSecurity>0</DocSecurity>');
  62. rst.push('<ScaleCrop>false</ScaleCrop>');
  63. rst.push('<HeadingPairs>');
  64. rst.push('<vt:vector size="2" baseType="variant">');
  65. rst.push('<vt:variant><vt:lpstr>工作表</vt:lpstr></vt:variant>');
  66. if (isSinglePage) rst.push('<vt:variant><vt:i4>1</vt:i4></vt:variant>');
  67. else rst.push('<vt:variant><vt:i4>' + sheets.length + '</vt:i4></vt:variant>');
  68. rst.push('</vt:vector>');
  69. rst.push('</HeadingPairs>');
  70. rst.push('<TitlesOfParts>');
  71. if (isSinglePage) {
  72. rst.push('<vt:vector size="1" baseType="lpstr">');
  73. rst.push('<vt:lpstr>' + sheets[0].sheetName + '</vt:lpstr>');
  74. } else {
  75. rst.push('<vt:vector size="' + sheets.length + '" baseType="lpstr">');
  76. for (let i = 0; i < sheets.length; i++) {
  77. rst.push('<vt:lpstr>' + sheets[i].sheetName + '</vt:lpstr>');
  78. }
  79. }
  80. rst.push('</vt:vector>');
  81. rst.push('</TitlesOfParts>');
  82. rst.push('<Company>SmartCost</Company>');
  83. rst.push('<LinksUpToDate>false</LinksUpToDate>');
  84. rst.push('<SharedDoc>false</SharedDoc>');
  85. rst.push('<HyperlinksChanged>false</HyperlinksChanged>');
  86. rst.push('<AppVersion>12.0000</AppVersion>');
  87. rst.push('</Properties>');
  88. return rst;
  89. }
  90. function writeCore() {
  91. const rst = [];
  92. const p_fillZero = function(val) {
  93. let rst = val;
  94. if (val < 10) {
  95. rst = '0' + val;
  96. }
  97. return rst;
  98. };
  99. rst.push(dftHeadXml + '\r\n');
  100. 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">');
  101. rst.push('<dc:creator>SmartCost</dc:creator>');
  102. rst.push('<cp:lastModifiedBy>SmartCost</cp:lastModifiedBy>');
  103. const dt = new Date();
  104. dt.setDate(dt.getDate() - 8 / 24); // it's GMT time, so please add the server offset time ( -8 hours )
  105. const dtStr = dt.getFullYear() + '-' + p_fillZero(dt.getMonth() + 1) + '-' + p_fillZero(dt.getDate()) + 'T' +
  106. p_fillZero(dt.getHours()) + ':' + p_fillZero(dt.getMinutes()) + ':' + p_fillZero(dt.getSeconds()) + 'Z';
  107. rst.push('<dcterms:created xsi:type="dcterms:W3CDTF">' + dtStr + '</dcterms:created>');
  108. rst.push('<dcterms:modified xsi:type="dcterms:W3CDTF">' + dtStr + '</dcterms:modified>');
  109. rst.push('</cp:coreProperties>');
  110. return rst;
  111. }
  112. function writeXlWorkBook(sheets, isSinglePage) {
  113. const rst = [];
  114. rst.push(dftHeadXml + '\r\n');
  115. rst.push('<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">');
  116. rst.push('<fileVersion appName="xl" lastEdited="4" lowestEdited="4" rupBuild="4505"/>');
  117. rst.push('<workbookPr defaultThemeVersion="124226"/>');
  118. rst.push('<bookViews><workbookView xWindow="360" yWindow="345" windowWidth="14655" windowHeight="4305"/></bookViews>');
  119. rst.push('<sheets>');
  120. if (isSinglePage) {
  121. rst.push('<sheet name="' + sheets[0].sheetName + '" sheetId="1" r:id="rId1"/>');
  122. } else {
  123. for (let i = 0; i < sheets.length; i++) {
  124. rst.push('<sheet name="' + sheets[i].sheetName + '" sheetId="' + (i + 1) + '" r:id="rId' + (i + 1) + '"/>');
  125. }
  126. }
  127. rst.push('</sheets>');
  128. rst.push('<calcPr calcId="124519"/>');
  129. rst.push('</workbook>');
  130. return rst;
  131. }
  132. function writeXlRels(sheets, isSinglePage) {
  133. const rst = [];
  134. let idx = 1;
  135. rst.push(dftHeadXml + '\r\n');
  136. rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
  137. if (isSinglePage) {
  138. rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>');
  139. idx++;
  140. } else {
  141. for (let i = 0; i < sheets.length; i++) {
  142. rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet' + (i + 1) + '.xml"/>');
  143. idx++;
  144. }
  145. }
  146. rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>');
  147. idx++;
  148. rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>');
  149. idx++;
  150. rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/>');
  151. rst.push('</Relationships>');
  152. return rst;
  153. }
  154. function writeTheme() {
  155. const rst = fs.readFileSync(__dirname + '/excel_base_files/theme1.xml', 'utf8', 'r');
  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 (strUtil.convertStrToBoolean(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]])) {
  168. rst.push('<b/>');
  169. }
  170. if (strUtil.convertStrToBoolean(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]])) {
  171. rst.push('<i/>');
  172. }
  173. if (strUtil.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]] && !strUtil.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 (strUtil.convertStrToBoolean(excelStyle[JV.CONTROL_PROPS[0]])) {
  266. alignStr += ' shrinkToFit="1"';
  267. }
  268. if (strUtil.convertStrToBoolean(excelStyle[JV.CONTROL_PROPS[4]]) && !strUtil.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) {
  338. if (pCells) {
  339. for (const cell of pCells) {
  340. if (targetBottomArr.indexOf(cell[JV.PROP_AREA][JV.PROP_BOTTOM]) < 0) {
  341. targetBottomArr.push(cell[JV.PROP_AREA][JV.PROP_BOTTOM]);
  342. }
  343. }
  344. }
  345. }
  346. for (const page of pageData.items) {
  347. const maxBottomArr = [];
  348. _insertMaxBottom(page.cells, maxBottomArr);
  349. _insertMaxBottom(page.signature_cells, maxBottomArr);
  350. _insertMaxBottom(page.signature_date_cells, maxBottomArr);
  351. _insertMaxBottom(page.signature_audit_cells, maxBottomArr);
  352. pgBrkIdx += maxBottomArr.length;
  353. pgBrk.push(pgBrkIdx);
  354. }
  355. pageData.pageBreaks.push(pgBrk);
  356. }
  357. function writeSheets(pageData, paperSize, sharedStrList, stylesObj, isSinglePage, custSheetMergeBands, hasSignature, signSheetIdxArr) {
  358. const rst = [];
  359. const private_pushDftFont = function() {
  360. const font = {};
  361. if (!(stylesObj.fonts)) {
  362. stylesObj.fonts = [];
  363. }
  364. font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]] = '宋体'; // font name
  365. font.size = 12;
  366. font.charset = 134;
  367. font.colorIdx = '8';
  368. stylesObj.fonts.push(font);
  369. };
  370. const private_buildFirstDftStyle = function() {
  371. stylesObj.cellXfs = [];
  372. stylesObj.borders = [];
  373. const fontId = 0;
  374. const borderId = 0;
  375. const border = {};
  376. border[JV.PROP_LEFT] = {};
  377. border[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT] = 0;
  378. border[JV.PROP_RIGHT] = {};
  379. border[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT] = 0;
  380. border[JV.PROP_TOP] = {};
  381. border[JV.PROP_TOP][JV.PROP_LINE_WEIGHT] = 0;
  382. border[JV.PROP_BOTTOM] = {};
  383. border[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT] = 0;
  384. stylesObj.borders.push(border);
  385. const cellControl = pageData[JV.NODE_CONTROL_COLLECTION].Default;
  386. const sheetControl = {};
  387. sheetControl.fontId = fontId;
  388. sheetControl.borderId = borderId;
  389. sheetControl.fontAngle = 0;
  390. for (let i = 0; i < JV.CONTROL_PROPS.length; i++) {
  391. sheetControl[JV.CONTROL_PROPS[i]] = cellControl[JV.CONTROL_PROPS[i]];
  392. }
  393. stylesObj.cellXfs.push(sheetControl);
  394. };
  395. private_pushDftFont();
  396. private_buildFirstDftStyle();
  397. let sheetIdx = 0;
  398. if (isSinglePage) {
  399. rst.push(writeSheet(pageData, null, paperSize, sharedStrList, stylesObj, null, hasSignature, sheetIdx, signSheetIdxArr, true, -1));
  400. } else {
  401. for (let i = 0; i < pageData.items.length; i++) {
  402. let appointedMergeBand = null;
  403. if (custSheetMergeBands && custSheetMergeBands.length > i) {
  404. appointedMergeBand = custSheetMergeBands[i];
  405. }
  406. rst.push(writeSheet(pageData, pageData.items[i], paperSize, sharedStrList, stylesObj, appointedMergeBand, hasSignature, sheetIdx, signSheetIdxArr, i === 0, i));
  407. sheetIdx++;
  408. }
  409. }
  410. return rst;
  411. }
  412. function getProperSignatureArea(cell, control) {
  413. // 约定默认长宽比例是2:1,图片分辨率是600*300
  414. const rst = [0, 0, 0, 0]; // left, top, right, bottom
  415. if (cell && cell[JV.PROP_AREA]) {
  416. let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
  417. height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP];
  418. if (width > height * 2) {
  419. width = height * 2;
  420. } else {
  421. height = width / 2;
  422. }
  423. switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  424. case 'left':
  425. rst[0] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  426. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  427. rst[2] = rst[0] + width;
  428. rst[3] = rst[1] + height;
  429. break;
  430. case 'right':
  431. rst[2] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  432. rst[3] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  433. rst[0] = rst[2] - width;
  434. rst[1] = rst[3] - height;
  435. break;
  436. default:
  437. // center
  438. rst[0] = (cell[JV.PROP_AREA][JV.PROP_LEFT] + cell[JV.PROP_AREA][JV.PROP_RIGHT] - width) / 2;
  439. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  440. rst[2] = rst[0] + width;
  441. rst[3] = rst[1] + height;
  442. break;
  443. }
  444. }
  445. // rst[0] = rst[0] + JpcCanvasOutput.offsetX;
  446. // rst[2] = rst[2] + JpcCanvasOutput.offsetX;
  447. // rst[1] = rst[1] + JpcCanvasOutput.offsetY;
  448. // rst[3] = rst[3] + JpcCanvasOutput.offsetY;
  449. return rst;
  450. }
  451. function preAnalyzePos(pageData, sheetData, xPos, yPos, yMultiPos) {
  452. let cell;
  453. let pos;
  454. const private_array_sort = function(i1, i2) {
  455. return (i1 - i2);
  456. };
  457. const private_set_cell_pos = function(theCell, theXPos, theYPos) {
  458. pos = theCell[JV.PROP_AREA][JV.PROP_LEFT];
  459. if (theXPos.indexOf(pos) < 0) theXPos.push(pos);
  460. pos = theCell[JV.PROP_AREA][JV.PROP_RIGHT];
  461. if (theXPos.indexOf(pos) < 0) theXPos.push(pos);
  462. pos = theCell[JV.PROP_AREA][JV.PROP_TOP];
  463. if (theYPos.indexOf(pos) < 0) theYPos.push(pos);
  464. pos = theCell[JV.PROP_AREA][JV.PROP_BOTTOM];
  465. if (theYPos.indexOf(pos) < 0) theYPos.push(pos);
  466. };
  467. const private_set_cell_pos2 = function(area, theXPos, theYPos) {
  468. pos = area[0];
  469. if (theXPos.indexOf(pos) < 0) theXPos.push(pos);
  470. pos = area[2];
  471. if (theXPos.indexOf(pos) < 0) theXPos.push(pos);
  472. pos = area[1];
  473. if (theYPos.indexOf(pos) < 0) theYPos.push(pos);
  474. pos = area[3];
  475. if (theYPos.indexOf(pos) < 0) theYPos.push(pos);
  476. };
  477. const self_analyze_sheet_pos = function(theShtData, theXPos, theYPos) {
  478. for (let i = 0; i < theShtData[JV.PROP_CELLS].length; i++) {
  479. cell = theShtData[JV.PROP_CELLS][i];
  480. private_set_cell_pos(cell, theXPos, theYPos);
  481. }
  482. for (let i = 0; i < theShtData[JV.PROP_SIGNATURE_CELLS].length; i++) {
  483. cell = theShtData[JV.PROP_SIGNATURE_CELLS][i];
  484. private_set_cell_pos(cell, theXPos, theYPos);
  485. let cellControl;
  486. if (typeof cell[JV.PROP_CONTROL] === 'string') {
  487. cellControl = pageData[JV.NODE_CONTROL_COLLECTION][cell[JV.PROP_CONTROL]];
  488. } else {
  489. cellControl = cell[JV.PROP_CONTROL];
  490. }
  491. const area = getProperSignatureArea(cell, cellControl);
  492. private_set_cell_pos2(area, theXPos, theYPos);
  493. }
  494. for (let i = 0; i < theShtData[JV.PROP_SIGNATURE_DATE_CELLS].length; i++) {
  495. cell = theShtData[JV.PROP_SIGNATURE_DATE_CELLS][i];
  496. private_set_cell_pos(cell, theXPos, theYPos);
  497. }
  498. for (let i = 0; i < theShtData[JV.PROP_SIGNATURE_AUDIT_CELLS].length; i++) {
  499. cell = theShtData[JV.PROP_SIGNATURE_AUDIT_CELLS][i];
  500. private_set_cell_pos(cell, theXPos, theYPos);
  501. }
  502. };
  503. xPos.push(0);
  504. if (sheetData) {
  505. // current sheet data
  506. // console.log('preAnalyzePos not single');
  507. yPos.push(0);
  508. self_analyze_sheet_pos(sheetData, xPos, yPos);
  509. xPos.sort(private_array_sort);
  510. yPos.sort(private_array_sort);
  511. } else {
  512. // total data in one sheet
  513. 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);
  514. // console.log('preAnalyzePos isSingle start');
  515. for (const shtItemData of pageData.items) {
  516. const tmpPos = [];
  517. tmpPos.push(0);
  518. self_analyze_sheet_pos(shtItemData, xPos, tmpPos);
  519. tmpPos.sort(private_array_sort);
  520. if (marginBottomPos - tmpPos[tmpPos.length - 1] > 10) {
  521. // 此逻辑是为了防止打印跨页(假设有些报表模板高度设置离底部margin还好远,导出excel后预览时会发现跨页现象(即下一页的某几行数据会挪到前一页来预览))
  522. tmpPos.push(marginBottomPos - 10);
  523. }
  524. // console.log('preAnalyzePos push to yMultiPos');
  525. yMultiPos.push(tmpPos);
  526. }
  527. xPos.sort(private_array_sort);
  528. yPos.splice(0, yPos.length);
  529. for (const p of yMultiPos[0]) {
  530. yPos.push(p);
  531. }
  532. }
  533. }
  534. function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, appointedMergeBand, hasSignature, sheetIdx, signSheetIdxArr, isFirstSheet, pgBrkIdx) {
  535. const rst = [];
  536. const xPos = [];
  537. const yPos = [];
  538. const yMultiPos = [];
  539. let currentMergeBorder = null;
  540. const headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  541. let currentPageMergePos = null; // 在 JV.PAGING_OPTION_INFINITY 场合应用
  542. const private_getCellIdxStr = function(idx) {
  543. let rst = 'A';
  544. if (idx < 26) {
  545. rst = headerStr[idx];
  546. } else if (idx < 26 * 26 + 26) {
  547. const ti = Math.floor(idx / 26);
  548. const tj = idx % 26;
  549. rst = headerStr[ti - 1] + headerStr[tj];
  550. } else if (idx < 26 * 26 * 26 + 26) {
  551. const ti = Math.floor(idx / (26 * 26));
  552. const tj = Math.floor((idx - ti * 26 * 26) / 26);
  553. const tk = idx % 26;
  554. rst = headerStr[ti - 1] + headerStr[tj - 1] + headerStr[tk];
  555. }
  556. return rst;
  557. };
  558. const private_getSharedStrIdx = function(val) {
  559. let strVal = val;
  560. if (val === null || val === undefined || (typeof val === 'number' && isNaN(val))) {
  561. strVal = '';
  562. }
  563. let rst = sharedStrList.indexOf(strVal);
  564. if (rst < 0) {
  565. sharedStrList.push(strVal);
  566. rst = sharedStrList.length - 1;
  567. }
  568. return rst;
  569. };
  570. const private_getFontId = function(cell) {
  571. let rst = 0;
  572. let hasFont = false;
  573. if (!(stylesObj.fonts)) {
  574. stylesObj.fonts = [];
  575. // for (let i = 0; i < sheetData.font_collection)
  576. }
  577. let sheetFont = null;
  578. if (typeof cell[JV.PROP_FONT] === 'string') {
  579. sheetFont = pageData[JV.NODE_FONT_COLLECTION][cell[JV.PROP_FONT]];
  580. } else {
  581. sheetFont = cell[JV.PROP_FONT];
  582. }
  583. for (let i = 0; i < stylesObj.fonts.length; i++) {
  584. const font = stylesObj.fonts[i];
  585. if (sheetFont) {
  586. 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)
  587. && 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]]
  588. && font[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]] === sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]]) {
  589. hasFont = true;
  590. rst = i;
  591. break;
  592. }
  593. } else {
  594. break;
  595. }
  596. }
  597. if (!hasFont) {
  598. const font = {};
  599. font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]] = sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]]; // font name
  600. // font.size = Math.round(sheetFont[JV.FONT_PROPS[1]] * 3 / 4);
  601. font.size = Math.floor(sheetFont[JV.FONT_PROPS[1]] * 3 / 4);
  602. font.charset = 134;
  603. font.colorIdx = '8';
  604. font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] = sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]]; // font bold
  605. font[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]] = sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]]; // font italic
  606. font[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]] = sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]]; // font underline
  607. stylesObj.fonts.push(font);
  608. rst = stylesObj.fonts.length - 1;
  609. }
  610. return rst;
  611. };
  612. const private_chkAndGetMergeLine = function(cell, sheetBorder, borderStr, needFurtherChk) {
  613. let rst = 0;
  614. const mergeBorder = currentMergeBorder;
  615. let mergeBand = pageData[JV.BAND_PROP_MERGE_BAND];
  616. if (appointedMergeBand !== null) {
  617. mergeBand = appointedMergeBand;
  618. }
  619. if (sheetBorder[borderStr] && sheetBorder[borderStr][JV.PROP_LINE_WEIGHT] !== undefined) {
  620. rst = sheetBorder[borderStr][JV.PROP_LINE_WEIGHT];
  621. }
  622. if (currentPageMergePos) {
  623. const side = currentPageMergePos[borderStr];
  624. if (side.indexOf(cell[JV.PROP_AREA][borderStr]) >= 0) {
  625. if (needFurtherChk) {
  626. const topSide = currentPageMergePos[JV.PROP_TOP];
  627. const bottomSide = currentPageMergePos[JV.PROP_BOTTOM];
  628. for (let i = 0; i < topSide.length; i++) {
  629. if (cell[JV.PROP_AREA][JV.PROP_TOP] >= topSide[i]) {
  630. if (cell[JV.PROP_AREA][JV.PROP_BOTTOM] <= bottomSide[i]) {
  631. const destStyle = pageData[JV.NODE_STYLE_COLLECTION][mergeBand[JV.PROP_STYLE][JV.PROP_ID]];
  632. rst = destStyle[borderStr][JV.PROP_LINE_WEIGHT];
  633. break;
  634. }
  635. } else {
  636. break;
  637. }
  638. }
  639. } else {
  640. const destStyle = pageData[JV.NODE_STYLE_COLLECTION][mergeBand[JV.PROP_STYLE][JV.PROP_ID]];
  641. rst = destStyle[borderStr][JV.PROP_LINE_WEIGHT];
  642. }
  643. }
  644. } else {
  645. if (mergeBorder && mergeBorder[borderStr] && cell[JV.PROP_AREA][borderStr] === mergeBorder[borderStr]) {
  646. const destStyle = pageData[JV.NODE_STYLE_COLLECTION][mergeBand[JV.PROP_STYLE][JV.PROP_ID]];
  647. if (needFurtherChk) {
  648. if (cell[JV.PROP_AREA][JV.PROP_TOP] >= mergeBorder[JV.PROP_TOP] &&
  649. cell[JV.PROP_AREA][JV.PROP_BOTTOM] <= mergeBorder[JV.PROP_BOTTOM]) {
  650. rst = destStyle[borderStr][JV.PROP_LINE_WEIGHT];
  651. }
  652. } else {
  653. rst = destStyle[borderStr][JV.PROP_LINE_WEIGHT];
  654. }
  655. }
  656. }
  657. return parseInt(rst);
  658. };
  659. const private_checkBorder = function(cell, border, sheetBorder) {
  660. let rst = true;
  661. const borderLineWidths = [];
  662. const sheetBorderLineWidths = [];
  663. borderLineWidths.push(border[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]);
  664. borderLineWidths.push(border[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]);
  665. borderLineWidths.push(border[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]);
  666. borderLineWidths.push(border[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]);
  667. if (sheetBorder[JV.PROP_LEFT] && sheetBorder[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]) {
  668. sheetBorderLineWidths.push(private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_LEFT, true));
  669. } else {
  670. sheetBorderLineWidths.push(0);
  671. }
  672. if (sheetBorder[JV.PROP_RIGHT] && sheetBorder[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]) {
  673. sheetBorderLineWidths.push(private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_RIGHT, true));
  674. } else {
  675. sheetBorderLineWidths.push(0);
  676. }
  677. if (sheetBorder[JV.PROP_TOP] && sheetBorder[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]) {
  678. sheetBorderLineWidths.push(private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_TOP, false));
  679. } else {
  680. sheetBorderLineWidths.push(0);
  681. }
  682. if (sheetBorder[JV.PROP_BOTTOM] && sheetBorder[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]) {
  683. sheetBorderLineWidths.push(private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_BOTTOM, false));
  684. } else {
  685. sheetBorderLineWidths.push(0);
  686. }
  687. for (let i = 0; i < 4; i++) {
  688. if (borderLineWidths[i] != sheetBorderLineWidths[i]) {
  689. rst = false;
  690. break;
  691. }
  692. }
  693. return rst;
  694. };
  695. const private_getIniBorder = function() {
  696. const rst = {};
  697. rst[JV.PROP_LEFT] = {};
  698. rst[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT] = 0;
  699. rst[JV.PROP_RIGHT] = {};
  700. rst[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT] = 0;
  701. rst[JV.PROP_TOP] = {};
  702. rst[JV.PROP_TOP][JV.PROP_LINE_WEIGHT] = 0;
  703. rst[JV.PROP_BOTTOM] = {};
  704. rst[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT] = 0;
  705. return rst;
  706. };
  707. const private_getBorderId = function(cell) {
  708. let rst = 0;
  709. let hasBorder = false;
  710. if (!(stylesObj.borders)) {
  711. stylesObj.borders = [];
  712. }
  713. const sheetBorder = pageData[JV.NODE_STYLE_COLLECTION][cell.style];
  714. const mergedBorder = private_getIniBorder();
  715. mergedBorder[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT] = private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_LEFT, true);
  716. mergedBorder[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT] = private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_RIGHT, true);
  717. mergedBorder[JV.PROP_TOP][JV.PROP_LINE_WEIGHT] = private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_TOP, false);
  718. mergedBorder[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT] = private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_BOTTOM, false);
  719. for (let i = 0; i < stylesObj.borders.length; i++) {
  720. const border = stylesObj.borders[i];
  721. if (private_checkBorder(cell, border, mergedBorder)) {
  722. hasBorder = true;
  723. rst = i;
  724. break;
  725. }
  726. }
  727. if (!hasBorder) {
  728. stylesObj.borders.push(mergedBorder);
  729. rst = stylesObj.borders.length - 1;
  730. }
  731. return rst;
  732. };
  733. const private_checkControl = function(cellControl, sheetControl) {
  734. let rst = true;
  735. for (let i = 0; i < JV.CONTROL_PROPS.length; i++) {
  736. if (cellControl[JV.CONTROL_PROPS[i]] !== sheetControl[JV.CONTROL_PROPS[i]]) {
  737. rst = false;
  738. break;
  739. }
  740. }
  741. return rst;
  742. };
  743. const private_getStyleId = function(cell) {
  744. let rst = 1;
  745. let hasStyle = false;
  746. if (!(stylesObj.cellXfs)) stylesObj.cellXfs = [];
  747. const fontId = private_getFontId(cell);
  748. let fontAngle = 0;
  749. if (typeof cell[JV.PROP_FONT] === 'string') {
  750. fontAngle = parseInt(pageData[JV.NODE_FONT_COLLECTION][cell[JV.PROP_FONT]].FontAngle);
  751. } else {
  752. fontAngle = parseInt(cell[JV.PROP_FONT].FontAngle);
  753. }
  754. const borderId = private_getBorderId(cell);
  755. let cellControl = null;
  756. if (typeof cell[JV.PROP_CONTROL] === 'string') {
  757. cellControl = pageData[JV.NODE_CONTROL_COLLECTION][cell[JV.PROP_CONTROL]];
  758. } else {
  759. cellControl = cell[JV.PROP_CONTROL];
  760. }
  761. for (let i = 0; i < stylesObj.cellXfs.length; i++) {
  762. const sheetControl = stylesObj.cellXfs[i];
  763. if (sheetControl.fontId === fontId && sheetControl.borderId === borderId) {
  764. if (private_checkControl(cellControl, sheetControl)) {
  765. rst = i;
  766. hasStyle = true;
  767. break;
  768. }
  769. }
  770. }
  771. if (!hasStyle) {
  772. const sheetControl = {};
  773. sheetControl.fontId = fontId;
  774. sheetControl.borderId = borderId;
  775. sheetControl.fontAngle = fontAngle;
  776. for (let i = 0; i < JV.CONTROL_PROPS.length; i++) {
  777. sheetControl[JV.CONTROL_PROPS[i]] = cellControl[JV.CONTROL_PROPS[i]];
  778. }
  779. stylesObj.cellXfs.push(sheetControl);
  780. rst = stylesObj.cellXfs.length - 1;
  781. }
  782. return rst;
  783. };
  784. const private_setCols = function() {
  785. // remark: 1 excel unit width = 2.117 mm
  786. rst.push('<cols>');
  787. let w = 0;
  788. for (let i = 1; i < xPos.length - 1; i++) {
  789. w = (xPos[i + 1] - xPos[i]) / DPI * 25.4 / 2.117;
  790. w = Math.round(w * 1000) / 1000;
  791. rst.push('<col min="' + i + '" max="' + i + '" width="' + w + '" customWidth="1"/>');
  792. }
  793. rst.push('<col min="' + (xPos.length - 1) + '" max="' + (xPos.length - 1) + '" width="' + 10 + '" customWidth="1"/>');
  794. rst.push('</cols>');
  795. };
  796. const private_setMergedCells = function() {
  797. let cnt = 0;
  798. rst.push('<mergeCells count="?">');
  799. const startIdx = rst.length - 1;
  800. const self_setMergedCells = function(theData, theYPos, offsetY) {
  801. for (let i = 0; i < theData.cells.length; i++) {
  802. const cell = theData.cells[i];
  803. const idxR = xPos.indexOf(cell[JV.PROP_AREA][JV.PROP_RIGHT]);
  804. const idxL = xPos.indexOf(cell[JV.PROP_AREA][JV.PROP_LEFT]);
  805. const idxB = theYPos.indexOf(cell[JV.PROP_AREA][JV.PROP_BOTTOM]);
  806. const idxT = theYPos.indexOf(cell[JV.PROP_AREA][JV.PROP_TOP]);
  807. if (idxR - idxL > 1 || idxB - idxT > 1) {
  808. rst.push('<mergeCell ref="' + private_getCellIdxStr(idxL - 1) + (idxT + offsetY) + ':' + private_getCellIdxStr(idxR - 2) + (idxB - 1 + offsetY) + '"/>');
  809. cnt++;
  810. }
  811. }
  812. };
  813. if (sheetData) {
  814. self_setMergedCells(sheetData, yPos, 0);
  815. } else {
  816. let osY = 0;
  817. for (let i = 0; i < pageData.items.length; i++) {
  818. const shtItemData = pageData.items[i];
  819. const tmpPos = yMultiPos[i];
  820. self_setMergedCells(shtItemData, tmpPos, osY);
  821. osY += tmpPos.length - 2;
  822. }
  823. }
  824. rst[startIdx] = '<mergeCells count="' + cnt + '">';
  825. rst.push('</mergeCells>');
  826. };
  827. const private_setSheetData = function() {
  828. // remark: 1 excel unit height = 0.3612 mm
  829. rst.push('<sheetData>');
  830. const spanX = xPos.length - 2;
  831. let cellIdx = 0;
  832. let h = 0;
  833. const self_setDataEx = function(theShtData, theYPos, rowOffset) {
  834. const rows = [];
  835. // 1. build full set of blank rows/cells
  836. for (let i = 1; i < theYPos.length - 1; i++) {
  837. const rowObj = {};
  838. h = (theYPos[i + 1] - theYPos[i]) / DPI * 25.4 / 0.3612;
  839. h = Math.round(h * 1000) / 1000;
  840. rowObj.height = h;
  841. rowObj.r = i + rowOffset;
  842. rowObj.items = [];
  843. rows.push(rowObj);
  844. for (let j = 1; j < xPos.length - 1; j++) {
  845. const colIdxStr = private_getCellIdxStr(j - 1);
  846. const cellObj = {};
  847. cellObj.r = colIdxStr + (i + rowOffset);
  848. cellObj.s = 0;
  849. cellObj.isBlank = true;
  850. rows[i - 1].items.push(cellObj);
  851. }
  852. }
  853. // 2. then fill up the cell style-ids and values
  854. let rowIdx1 = 0;
  855. let colIdx1 = 0;
  856. let rowIdx2 = 0;
  857. let colIdx2 = 0;
  858. // let colIdxStr = '';
  859. for (let cIdx = 0; cIdx < theShtData.cells.length; cIdx++) {
  860. const styleIdx = private_getStyleId(theShtData.cells[cIdx]);
  861. rowIdx1 = theYPos.indexOf(theShtData.cells[cIdx][JV.PROP_AREA][JV.PROP_TOP]);
  862. colIdx1 = xPos.indexOf(theShtData.cells[cIdx][JV.PROP_AREA][JV.PROP_LEFT]);
  863. let cellObj = rows[rowIdx1 - 1].items[colIdx1 - 1];
  864. cellObj.s = styleIdx;
  865. cellObj.isBlank = false;
  866. if (!(strUtil.isEmptyString(theShtData.cells[cIdx][JV.PROP_VALUE]))) {
  867. const valIdx = private_getSharedStrIdx(theShtData.cells[cIdx][JV.PROP_VALUE]);
  868. cellObj.v = valIdx;
  869. }
  870. rowIdx2 = theYPos.indexOf(theShtData.cells[cIdx][JV.PROP_AREA][JV.PROP_BOTTOM]);
  871. colIdx2 = xPos.indexOf(theShtData.cells[cIdx][JV.PROP_AREA][JV.PROP_RIGHT]);
  872. if ((rowIdx2 - rowIdx1 > 1) || (colIdx2 - colIdx1 > 1)) {
  873. for (let i = 0; i < rowIdx2 - rowIdx1; i++) {
  874. for (let j = 0; j < colIdx2 - colIdx1; j++) {
  875. if (i === 0 && j === 0) continue;
  876. cellObj = rows[rowIdx1 - 1 + i].items[colIdx1 - 1 + j];
  877. cellObj.s = styleIdx;
  878. cellObj.isBlank = true;
  879. }
  880. }
  881. }
  882. }
  883. // 3. then fill up rst
  884. for (let i = 0; i < rows.length; i++) {
  885. rst.push('<row r="' + (i + 1 + rowOffset) + '" spans="1:' + spanX + '" ht="' + rows[i].height + '" customHeight="1">');
  886. for (let j = 0; j < rows[i].items.length; j++) {
  887. const cellObj = rows[i].items[j];
  888. if (cellObj.v === undefined) {
  889. rst.push('<c r="' + cellObj.r + '" s="' + cellObj.s + '"/>');
  890. } else {
  891. rst.push('<c r="' + cellObj.r + '" s="' + cellObj.s + '" t="s">');
  892. rst.push('<v>' + cellObj.v + '</v>');
  893. rst.push('</c>');
  894. }
  895. }
  896. rst.push('</row>');
  897. }
  898. // 4. maybe need to dispose the memory
  899. // ...
  900. };
  901. if (sheetData) {
  902. // current sheet data
  903. currentPageMergePos = sheetData[JV.PAGE_SPECIAL_MERGE_POS];
  904. currentMergeBorder = sheetData[JV.PROP_PAGE_MERGE_BORDER];
  905. self_setDataEx(sheetData, yPos, 0);
  906. } else {
  907. // total data in one sheet
  908. let rowOffset = 0;
  909. for (let i = 0; i < pageData.items.length; i++) {
  910. const shtItemData = pageData.items[i];
  911. currentPageMergePos = shtItemData[JV.PAGE_SPECIAL_MERGE_POS];
  912. currentMergeBorder = shtItemData[JV.PROP_PAGE_MERGE_BORDER];
  913. const tmpPos = yMultiPos[i];
  914. cellIdx = 0;
  915. self_setDataEx(shtItemData, tmpPos, rowOffset);
  916. rowOffset += tmpPos.length - 2;
  917. }
  918. }
  919. rst.push('</sheetData>');
  920. };
  921. preAnalyzePos(pageData, sheetData, xPos, yPos, yMultiPos);
  922. // console.log('yMultiPos');
  923. // console.log(yMultiPos);
  924. rst.push(dftHeadXml + '\r\n');
  925. rst.push('<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">');
  926. const colStr = private_getCellIdxStr(xPos.length - 3);
  927. rst.push('<dimension ref="A1:' + colStr + '' + yPos.length + '"/>');
  928. if (isFirstSheet) {
  929. rst.push('<sheetViews><sheetView showGridLines="1" tabSelected="1" workbookViewId="0">');
  930. } else {
  931. rst.push('<sheetViews><sheetView showGridLines="1" workbookViewId="0">');
  932. }
  933. // rst.push('<selection sqref="A1:' + colStr + '1"/>');
  934. rst.push('<selection sqref="A1:A1"/>');
  935. rst.push('</sheetView></sheetViews>');
  936. rst.push('<sheetFormatPr defaultRowHeight="13.5"/>');
  937. private_setCols();
  938. private_setSheetData();
  939. private_setMergedCells();
  940. rst.push('<phoneticPr fontId="1" type="noConversion"/>');
  941. // rst.push('<pageMargins left="0.315" right="0.215" top="0.315" bottom="0.315" header="0" footer="0"/>');
  942. rst.push('<pageMargins left="' + (parseFloat(pageData[JV.NODE_PAGE_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) * 0.39375) +
  943. '" right="0.215" top="0.315" bottom="0.315" header="0" footer="0"/>');
  944. const paperSizeIdx = JV.PAGES_SIZE_STR.indexOf(paperSize);
  945. let pStr = '';
  946. if (paperSizeIdx >= 0) {
  947. pStr = 'paperSize="' + JV.PAGES_SIZE_IDX[paperSizeIdx] + '"';
  948. }
  949. let orientationStr = (pageData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE][0] > pageData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE][1]) ? 'landscape' : 'portrait';
  950. if (currentPageMergePos) {
  951. orientationStr = (currentPageMergePos[JV.NODE_PAGE_SIZE][0] > currentPageMergePos[JV.NODE_PAGE_SIZE][1]) ? 'landscape' : 'portrait';
  952. }
  953. rst.push('<pageSetup ' + pStr + ' fitToWidth="0" fitToHeight="0" orientation="' + orientationStr + '" />');
  954. rst.push('<headerFooter alignWithMargins="0"/>');
  955. if (hasSignature && signSheetIdxArr[sheetIdx]) {
  956. // let rIdx = 1;
  957. // for (let ssIdx = 0; ssIdx < signSheetIdxArr.length; ssIdx++) {
  958. // if (signSheetIdxArr[ssIdx]) {
  959. // if (ssIdx < sheetIdx) rIdx++
  960. // else break;
  961. // }
  962. // }
  963. rst.push('<drawing r:id="rId1"/>');
  964. }
  965. // 插入分页符---------------------------
  966. if (pageData.pageBreaks) {
  967. let pgBrks = [];
  968. if (sheetData !== null) {
  969. pgBrks = pageData.pageBreaks[pgBrkIdx];
  970. } else {
  971. pgBrks = pageData.pageBreaks[0];
  972. }
  973. if (pgBrks.length > 1) {
  974. rst.push('<rowBreaks count="' + pgBrks.length + '" manualBreakCount="' + pgBrks.length + '" >');
  975. for (let pbi = 0; pbi < pgBrks.length; pbi++) {
  976. rst.push('<brk id="' + pgBrks[pbi] + '" max="16383" man="1" />');
  977. }
  978. rst.push('</rowBreaks>');
  979. }
  980. }
  981. // 插入分页符结束---------------------------
  982. rst.push('</worksheet>');
  983. return rst;
  984. }
  985. function writeWorkSheetRels(signSheetIdx) {
  986. const rst = [];
  987. rst.push('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');
  988. rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
  989. rst.push('<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing" Target="../drawings/drawing' + signSheetIdx + '.xml"/>');
  990. rst.push('</Relationships>');
  991. return rst;
  992. }
  993. function writeImage(path, pic, baseDir) {
  994. let rst = null;
  995. if (pic) {
  996. // 这里pic的数据就是base64的,不能是其他
  997. rst = base64ToBuffer(pic);
  998. // fs.createReadStream
  999. } else if (path) {
  1000. const filePath = baseDir + '/app' + path;
  1001. // console.log(filePath);
  1002. rst = fs.readFileSync(filePath);
  1003. // console.log(rst);
  1004. }
  1005. return rst;
  1006. }
  1007. function writeDrawings(pageData, signKeyArr, signPathArr, isSinglePage, signSheetIdxArr) {
  1008. const rst = [];
  1009. // console.log('isSinglePage: ' + isSinglePage);
  1010. if (isSinglePage) {
  1011. rst.push(writeDrawing(pageData, null, signKeyArr[0]));
  1012. } else {
  1013. for (let i = 0; i < pageData.items.length; i++) {
  1014. if (signSheetIdxArr[i]) {
  1015. rst.push(writeDrawing(pageData, pageData.items[i], signKeyArr[i]));
  1016. }
  1017. }
  1018. }
  1019. return rst;
  1020. }
  1021. function writeDrawing(pageData, sheetData, subSignKeyArr) {
  1022. const rst = [];
  1023. const xPos = [];
  1024. const yPos = [];
  1025. const yMultiPos = [];
  1026. const private_setSheetDrawingCellData = function(signCell, theYPos, startPicIdx, offsetRow) {
  1027. let cellControl;
  1028. if (typeof signCell[JV.PROP_CONTROL] === 'string') {
  1029. cellControl = pageData[JV.NODE_CONTROL_COLLECTION][signCell[JV.PROP_CONTROL]];
  1030. } else {
  1031. cellControl = signCell[JV.PROP_CONTROL];
  1032. }
  1033. const area = getProperSignatureArea(signCell, cellControl);
  1034. // 1. from
  1035. // let colIdx = xPos.indexOf(signCell[JV.PROP_AREA][JV.PROP_LEFT]);
  1036. // let rowIdx = theYPos.indexOf(signCell[JV.PROP_AREA][JV.PROP_TOP]) + offsetRow; // 这里要考虑Row的偏移量(多页在同同一个sheet输出)
  1037. let colIdx = xPos.indexOf(area[0]);
  1038. let rowIdx = theYPos.indexOf(area[1]) + offsetRow; // 这里要考虑Row的偏移量(多页在同同一个sheet输出)
  1039. // 因为 xPos, theYPos的首位是0,所以还需要减1
  1040. colIdx--;
  1041. rowIdx--;
  1042. rst.push('<xdr:twoCellAnchor editAs="oneCell">');
  1043. rst.push('<xdr:from>');
  1044. rst.push('<xdr:col>' + colIdx + '</xdr:col>');
  1045. rst.push('<xdr:colOff>0</xdr:colOff>');
  1046. rst.push('<xdr:row>' + rowIdx + '</xdr:row>');
  1047. rst.push('<xdr:rowOff>0</xdr:rowOff>');
  1048. rst.push('</xdr:from>');
  1049. // 2. to
  1050. colIdx = xPos.indexOf(area[2]);
  1051. rowIdx = theYPos.indexOf(area[3]) + offsetRow;
  1052. // 因为 xPos, theYPos的首位是0,所以还需要减1
  1053. colIdx--;
  1054. rowIdx--;
  1055. rst.push('<xdr:to>');
  1056. rst.push('<xdr:col>' + colIdx + '</xdr:col>');
  1057. rst.push('<xdr:colOff>0</xdr:colOff>');
  1058. rst.push('<xdr:row>' + rowIdx + '</xdr:row>');
  1059. rst.push('<xdr:rowOff>0</xdr:rowOff>');
  1060. rst.push('</xdr:to>');
  1061. // 3. pic
  1062. rst.push('<xdr:pic>');
  1063. // 3.1
  1064. rst.push('<xdr:nvPicPr>');
  1065. rst.push('<xdr:cNvPr id="' + startPicIdx + '" name="图片 ' + startPicIdx + '"/>');
  1066. rst.push('<xdr:cNvPicPr><a:picLocks noChangeAspect="1" noChangeArrowheads="1"/></xdr:cNvPicPr>');
  1067. rst.push('</xdr:nvPicPr>');
  1068. // 3.2
  1069. rst.push('<xdr:blipFill>');
  1070. // 重点!!!
  1071. const picIdx = subSignKeyArr.indexOf(signCell.signature_name) + 1;
  1072. // 3.2.1
  1073. rst.push('<a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId' + picIdx + '" cstate="print">');
  1074. rst.push('<a:extLst>');
  1075. rst.push('<a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">'); // 参考excel本身,都是固定的uri
  1076. rst.push('<a14:useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0"/>');
  1077. rst.push('</a:ext>');
  1078. rst.push('</a:extLst>');
  1079. rst.push('</a:blip>');
  1080. // 3.2.2
  1081. rst.push('<a:srcRect/>');
  1082. // 3.2.3
  1083. rst.push('<a:stretch><a:fillRect/></a:stretch>');
  1084. rst.push('</xdr:blipFill>');
  1085. // 3.3
  1086. rst.push('<xdr:spPr bwMode="auto">');
  1087. // 3.3.1
  1088. rst.push('<a:xfrm>');
  1089. // 以下经过Excel及WPS的测试,这数据好像没什么意义,都设为0
  1090. rst.push('<a:off x="0" y="0"/>');
  1091. rst.push('<a:ext cx="0" cy="0"/>');
  1092. rst.push('</a:xfrm>');
  1093. // 3.3.2
  1094. rst.push('<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>');
  1095. // 3.3.3
  1096. rst.push('<a:noFill/>');
  1097. // 3.3.4
  1098. rst.push('<a:extLst>');
  1099. rst.push('<a:ext uri="{909E8E84-426E-40DD-AFC4-6F175D3DCCD1}">');
  1100. rst.push('<a14:hiddenFill xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main">');
  1101. rst.push('<a:solidFill><a:srgbClr val="FFFFFF"/></a:solidFill>');
  1102. rst.push('</a14:hiddenFill>');
  1103. rst.push('</a:ext>');
  1104. rst.push('</a:extLst>');
  1105. // 收尾
  1106. rst.push('</xdr:spPr>');
  1107. rst.push('</xdr:pic>');
  1108. // 4. client Data
  1109. rst.push('<xdr:clientData/>');
  1110. rst.push('</xdr:twoCellAnchor>');
  1111. };
  1112. preAnalyzePos(pageData, sheetData, xPos, yPos, yMultiPos);
  1113. rst.push('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');
  1114. rst.push('<xdr:wsDr xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">');
  1115. if (sheetData) {
  1116. let startPicIdx = 2;
  1117. for (const sCell of sheetData[JV.PROP_SIGNATURE_CELLS]) {
  1118. if (subSignKeyArr.indexOf(sCell.signature_name) >= 0) {
  1119. private_setSheetDrawingCellData(sCell, yPos, startPicIdx, 0);
  1120. startPicIdx++;
  1121. }
  1122. }
  1123. } else {
  1124. // total data in one sheet
  1125. let rowOffset = 0;
  1126. for (let i = 0; i < pageData.items.length; i++) {
  1127. const shtItemData = pageData.items[i];
  1128. const tmpPos = yMultiPos[i];
  1129. let startPicIdx = 2;
  1130. for (const sCell of shtItemData[JV.PROP_SIGNATURE_CELLS]) {
  1131. if (subSignKeyArr.indexOf(sCell.signature_name) >= 0) {
  1132. private_setSheetDrawingCellData(sCell, tmpPos, startPicIdx, rowOffset);
  1133. startPicIdx++;
  1134. }
  1135. }
  1136. rowOffset += tmpPos.length - 2;
  1137. }
  1138. }
  1139. rst.push('</xdr:wsDr>');
  1140. return rst;
  1141. }
  1142. function writeDrawingsRels(amt, startIdx) {
  1143. const rst = [];
  1144. rst.push('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');
  1145. rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
  1146. for (let idx = 0; idx < amt; idx++) {
  1147. rst.push('<Relationship Id="rId' + (idx + 1) + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/image' + (startIdx + idx + 1) + '.png"/>');
  1148. }
  1149. rst.push('</Relationships>');
  1150. return rst;
  1151. }
  1152. function mergeProperties(orgObj, newObj) {
  1153. const orgPropArr = [];
  1154. const newPropArr = [];
  1155. for (const p in orgObj) {
  1156. orgPropArr.push(p);
  1157. }
  1158. for (const p in newObj) {
  1159. newPropArr.push(p);
  1160. }
  1161. for (let i = 0; i < newPropArr.length; i++) {
  1162. if (orgPropArr.indexOf(newPropArr[i]) < 0) {
  1163. orgObj[newPropArr[i]] = newObj[newPropArr[i]];
  1164. }
  1165. }
  1166. }
  1167. function resetDummuySignature(pageData, roleRel) {
  1168. // 备注:计算草图等其他图形需要额外做些处理
  1169. let dummySignIdx = 0;
  1170. for (let pageIdx = 0; pageIdx < pageData.items.length; pageIdx++) {
  1171. const page = pageData.items[pageIdx];
  1172. if (page[JV.PROP_SIGNATURE_CELLS] && page[JV.PROP_SIGNATURE_CELLS].length > 0) {
  1173. for (const signature of page[JV.PROP_SIGNATURE_CELLS]) {
  1174. if (signature.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) >= 0) {
  1175. // 表示这是一个其他类型的非原生电子签名图,只是借用signature的处理机制,每个图都是唯一的,所以需要重新给个唯一的新signature_name
  1176. signature.signature_name = signature.signature_name + '_' + pageIdx + '_' + dummySignIdx;
  1177. dummySignIdx++;
  1178. const roleRelItem = { type: '用户', sign_path: signature.path, signature_name: signature.signature_name };
  1179. roleRel.push(roleRelItem);
  1180. }
  1181. }
  1182. }
  1183. }
  1184. }
  1185. function _createDummyCell(dummyOrgCells, parentPage) {
  1186. for (const signature of dummyOrgCells) {
  1187. const dummyCell = {
  1188. font: 'Content',
  1189. control: 'Default',
  1190. style: 'Default_None',
  1191. Value: '',
  1192. area: { Left: 0, Right: 0, Top: 0, Bottom: 0 },
  1193. };
  1194. if (signature.style) dummyCell.style = signature.style;
  1195. dummyCell[JV.PROP_AREA][JV.PROP_LEFT] = signature[JV.PROP_AREA][JV.PROP_LEFT];
  1196. dummyCell[JV.PROP_AREA][JV.PROP_RIGHT] = signature[JV.PROP_AREA][JV.PROP_RIGHT];
  1197. dummyCell[JV.PROP_AREA][JV.PROP_TOP] = signature[JV.PROP_AREA][JV.PROP_TOP];
  1198. dummyCell[JV.PROP_AREA][JV.PROP_BOTTOM] = signature[JV.PROP_AREA][JV.PROP_BOTTOM];
  1199. parentPage[JV.PROP_CELLS].push(dummyCell);
  1200. }
  1201. }
  1202. function createDummySignatureCell(pageData) {
  1203. for (let pageIdx = 0; pageIdx < pageData.items.length; pageIdx++) {
  1204. const page = pageData.items[pageIdx];
  1205. if (page[JV.PROP_SIGNATURE_CELLS] && page[JV.PROP_SIGNATURE_CELLS].length > 0) {
  1206. _createDummyCell(page[JV.PROP_SIGNATURE_CELLS], page);
  1207. // for (const signature of page[JV.PROP_SIGNATURE_CELLS]) {
  1208. // const dummyCell = {
  1209. // font: 'Content',
  1210. // control: 'Default',
  1211. // style: 'Default_None',
  1212. // Value: '',
  1213. // area: { Left: 0, Right: 0, Top: 0, Bottom: 0 }
  1214. // };
  1215. // if (signature.style) dummyCell.style = signature.style;
  1216. // dummyCell[JV.PROP_AREA][JV.PROP_LEFT] = signature[JV.PROP_AREA][JV.PROP_LEFT];
  1217. // dummyCell[JV.PROP_AREA][JV.PROP_RIGHT] = signature[JV.PROP_AREA][JV.PROP_RIGHT];
  1218. // dummyCell[JV.PROP_AREA][JV.PROP_TOP] = signature[JV.PROP_AREA][JV.PROP_TOP];
  1219. // dummyCell[JV.PROP_AREA][JV.PROP_BOTTOM] = signature[JV.PROP_AREA][JV.PROP_BOTTOM];
  1220. // page[JV.PROP_CELLS].push(dummyCell);
  1221. // }
  1222. }
  1223. if (page[JV.PROP_SIGNATURE_DATE_CELLS] && page[JV.PROP_SIGNATURE_DATE_CELLS].length > 0) {
  1224. _createDummyCell(page[JV.PROP_SIGNATURE_DATE_CELLS], page);
  1225. }
  1226. if (page[JV.PROP_SIGNATURE_AUDIT_CELLS] && page[JV.PROP_SIGNATURE_AUDIT_CELLS].length > 0) {
  1227. _createDummyCell(page[JV.PROP_SIGNATURE_AUDIT_CELLS], page);
  1228. }
  1229. }
  1230. }
  1231. function checkAndSetSignatureCache(pageData, signKeyArr, signPathArr, roleRel, signSheetIdxArr) {
  1232. // 备注:电子签名是以图形的方式处理,一页可以有多个签名,多页的签名基本是引用同样的图片,在这里先处理一下,后期统一引用。
  1233. // 另:以后的图片(在电子签名(signature_cells)以外的图片)会单独处理(如计算草图等)
  1234. let rst = false;
  1235. let chkRoles = [];
  1236. if (roleRel instanceof Array) {
  1237. chkRoles = roleRel;
  1238. } else {
  1239. if (roleRel) chkRoles.push(roleRel);
  1240. }
  1241. // console.log(chkRoles);
  1242. // console.log(signKeyArr);
  1243. // for (const page of pageData.items) {
  1244. for (let pageIdx = 0; pageIdx < pageData.items.length; pageIdx++) {
  1245. const page = pageData.items[pageIdx];
  1246. signKeyArr.push([]);
  1247. signPathArr.push([]);
  1248. signSheetIdxArr[pageIdx] = false;
  1249. // console.log('page index: ' + pageIdx);
  1250. // console.log(page[JV.PROP_SIGNATURE_CELLS]);
  1251. if (page[JV.PROP_SIGNATURE_CELLS] && page[JV.PROP_SIGNATURE_CELLS].length > 0) {
  1252. // let dummySignIdx = 0;
  1253. for (const signature of page[JV.PROP_SIGNATURE_CELLS]) {
  1254. // if (signature.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) >= 0) {
  1255. // // 表示这是一个其他类型的非原生电子签名图,只是借用signature的处理机制,每个图都是唯一的,所以需要重新给个唯一的新signature_name
  1256. // signature.signature_name = signature.signature_name + '_' + pageIdx + '_' + dummySignIdx;
  1257. // dummySignIdx++;
  1258. // rst = true;
  1259. // signSheetIdxArr[pageIdx] = true;
  1260. // }
  1261. if (signKeyArr[pageIdx].indexOf(signature.signature_name) < 0) {
  1262. if (signature.pic) {
  1263. const signPath = { path: null, pic: null };
  1264. signPathArr[pageIdx].push(signPath);
  1265. signPath.pic = signature.pic; // 历史报表
  1266. signKeyArr[pageIdx].push(signature.signature_name);
  1267. rst = true;
  1268. signSheetIdxArr[pageIdx] = true;
  1269. } else {
  1270. for (const role of chkRoles) {
  1271. if (signature.signature_name === role.signature_name) {
  1272. // console.log('signature.signature_name: ' + signature.signature_name);
  1273. if (role.sign_pic) {
  1274. const signPath = { path: null, pic: null };
  1275. signPathArr[pageIdx].push(signPath);
  1276. signPath.pic = role.sign_pic;
  1277. signKeyArr[pageIdx].push(signature.signature_name);
  1278. rst = true;
  1279. signSheetIdxArr[pageIdx] = true;
  1280. } else if (role.sign_path) {
  1281. const signPath = { path: null, pic: null };
  1282. signPathArr[pageIdx].push(signPath);
  1283. signPath.path = role.sign_path;
  1284. signKeyArr[pageIdx].push(signature.signature_name);
  1285. rst = true;
  1286. signSheetIdxArr[pageIdx] = true;
  1287. }
  1288. break;
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. }
  1295. }
  1296. return rst;
  1297. }
  1298. function base64ToBuffer(dataurl) {
  1299. // 将base64转换为buffer
  1300. const arr = dataurl.split(',');
  1301. // console.log(arr[1]);
  1302. const rst = new Buffer(arr[1], 'base64');
  1303. return rst;
  1304. }
  1305. module.exports = {
  1306. exportExcel: function(pageData, paperSize, fName, options, custSheetNames, custSheetMergeBands, baseDir, roleRel, callback) {
  1307. const rptOptions = ({ singlePage: false, fileName: 'report' });
  1308. if (options === 'true' || options === true) {
  1309. rptOptions.singlePage = true;
  1310. }
  1311. const isSinglePage = rptOptions.singlePage;
  1312. const sheets = [];
  1313. const signKeyArr = [];
  1314. const signPathArr = [];
  1315. const signSheetIdxArr = []; // 确定哪些sheet有签名(在多表导出的时候,有些表可能没有签名,但其他的表有签名)
  1316. // console.log('in exportExcel!');
  1317. // console.log(roleRel);
  1318. // const hasSignature = (roleRel !== null) ? checkAndSetSignatureCache(pageData, signKeyArr, signPathArr, roleRel, signSheetIdxArr) : false;
  1319. let thisRoleRel = [];
  1320. if (roleRel !== null && roleRel !== undefined) {
  1321. thisRoleRel = roleRel;
  1322. }
  1323. resetDummuySignature(pageData, thisRoleRel); // 把草图转换一下roleRel
  1324. // console.log(thisRoleRel);
  1325. const hasSignature = false; // 暂时不支持电子签名、草图导出excel
  1326. // const hasSignature = checkAndSetSignatureCache(pageData, signKeyArr, signPathArr, thisRoleRel, signSheetIdxArr); // 因草图的关系,thisRoleRel是否为null就不是充要的条件
  1327. // console.log('signKeyArr');
  1328. // console.log(signKeyArr);
  1329. // console.log('signPathArr');
  1330. // console.log(signPathArr);
  1331. // console.log('hasSignature: ' + hasSignature);
  1332. if (!hasSignature) {
  1333. createDummySignatureCell(pageData);
  1334. }
  1335. if (isSinglePage) {
  1336. // 加分页符(分页符要在外部处理好)-------------------
  1337. _setupPgBrks(pageData);
  1338. // 加分页符结束-------------------
  1339. sheets.push({ sheetName: '全部页' });
  1340. } else {
  1341. if (custSheetNames && custSheetNames.length === pageData.items.length) {
  1342. for (let i = 0; i < pageData.items.length; i++) {
  1343. sheets.push({ sheetName: custSheetNames[i] });
  1344. }
  1345. } else {
  1346. for (let i = 0; i < pageData.items.length; i++) {
  1347. sheets.push({ sheetName: '第' + (i + 1) + '页' });
  1348. }
  1349. }
  1350. }
  1351. // 1.
  1352. let file = '[Content_Types].xml';
  1353. let data = writeContentTypes(sheets, isSinglePage, hasSignature);
  1354. const zip = new JSZip();
  1355. zip.file(file, data.join(''), { compression: 'DEFLATE' });
  1356. // console.log('step 1');
  1357. // 2.
  1358. const zip_rels = zip.folder('_rels');
  1359. file = '.rels';
  1360. data = writeRootRels();
  1361. zip_rels.file(file, data.join(''), { compression: 'DEFLATE' });
  1362. // console.log('step 2');
  1363. // 3.
  1364. const zip_docProps = zip.folder('docProps');
  1365. file = 'app.xml';
  1366. data = writeApp(sheets, isSinglePage);
  1367. zip_docProps.file(file, data.join(''), { compression: 'DEFLATE' });
  1368. file = 'core.xml';
  1369. data = writeCore();
  1370. zip_docProps.file(file, data.join(''), { compression: 'DEFLATE' });
  1371. // console.log('step 3');
  1372. // 4.
  1373. const zip_xl = zip.folder('xl');
  1374. file = 'workbook.xml';
  1375. data = writeXlWorkBook(sheets, isSinglePage);
  1376. zip_xl.file(file, data.join(''), { compression: 'DEFLATE' });
  1377. const zip_rels2 = zip_xl.folder('_rels');
  1378. file = 'workbook.xml.rels';
  1379. data = writeXlRels(sheets, isSinglePage);
  1380. zip_rels2.file(file, data.join(''), { compression: 'DEFLATE' });
  1381. // console.log('step 4');
  1382. // 5.
  1383. const zip_theme = zip_xl.folder('theme');
  1384. file = 'theme1.xml';
  1385. data = writeTheme();
  1386. zip_theme.file(file, data, { compression: 'DEFLATE' });
  1387. if (hasSignature) {
  1388. // 5.1 写所有的image
  1389. const zip_media = zip_xl.folder('media');
  1390. let picIdx = 0;
  1391. // console.log(signKeyArr);
  1392. // console.log(signPathArr);
  1393. for (let signIdx = 0; signIdx < signPathArr.length; signIdx++) {
  1394. if (signKeyArr[signIdx].length > 0) {
  1395. for (let pathIdx = 0; pathIdx < signPathArr[signIdx].length; pathIdx++) {
  1396. picIdx++;
  1397. data = writeImage(signPathArr[signIdx][pathIdx].path, signPathArr[signIdx][pathIdx].pic, baseDir);
  1398. file = 'image' + picIdx + '.png';
  1399. zip_media.file(file, data, { compression: 'DEFLATE' });
  1400. }
  1401. }
  1402. }
  1403. // 5.2
  1404. const zip_drawings = zip_xl.folder('drawings');
  1405. data = writeDrawings(pageData, signKeyArr, signPathArr, isSinglePage, signSheetIdxArr);
  1406. // console.log('isSinglePage: ' + isSinglePage);
  1407. // console.log(data);
  1408. for (let psIdx = 0; psIdx < data.length; psIdx++) {
  1409. file = 'drawing' + (psIdx + 1) + '.xml';
  1410. // console.log('drawing1' + (psIdx + 1) + '.xml data');
  1411. // console.log(data);
  1412. zip_drawings.file(file, data[psIdx].join(''), { compression: 'DEFLATE' });
  1413. }
  1414. // 5.3
  1415. const zip_drawings_rels = zip_drawings.folder('_rels');
  1416. let relsIdx = 0;
  1417. let relsImgAmt = 0;
  1418. for (let ssIdx = 0; ssIdx < signKeyArr.length; ssIdx++) {
  1419. if (signKeyArr[ssIdx].length > 0) {
  1420. data = writeDrawingsRels(signKeyArr[ssIdx].length, relsImgAmt); // 一个drawingX.xml.rels文件与一个drawingX.xml对应
  1421. relsIdx++;
  1422. relsImgAmt += signKeyArr[ssIdx].length;
  1423. // console.log('drawing1.xml.rels data');
  1424. // console.log(data);
  1425. file = 'drawing' + relsIdx + '.xml.rels';
  1426. zip_drawings_rels.file(file, data.join(''), { compression: 'DEFLATE' });
  1427. }
  1428. }
  1429. }
  1430. // console.log('step 5');
  1431. // 6.
  1432. const zip_xl_worksheets = zip_xl.folder('worksheets');
  1433. const sharedStrList = [];
  1434. const stylesObj = {};
  1435. data = writeSheets(pageData, paperSize, sharedStrList, stylesObj, isSinglePage, custSheetMergeBands, hasSignature, signSheetIdxArr);
  1436. if (isSinglePage) {
  1437. for (let i = 0; i < 1; i++) {
  1438. file = 'sheet' + (i + 1) + '.xml';
  1439. zip_xl_worksheets.file(file, data[i].join(''), { compression: 'DEFLATE' });
  1440. }
  1441. } else {
  1442. for (let i = 0; i < data.length; i++) {
  1443. file = 'sheet' + (i + 1) + '.xml';
  1444. zip_xl_worksheets.file(file, data[i].join(''), { compression: 'DEFLATE' });
  1445. }
  1446. }
  1447. // console.log('step 6');
  1448. // 7.
  1449. if (hasSignature) {
  1450. const zip_xl_worksheets_rels = zip_xl_worksheets.folder('_rels');
  1451. if (isSinglePage) {
  1452. data = writeWorkSheetRels(1);
  1453. file = 'sheet1.xml.rels';
  1454. zip_xl_worksheets_rels.file(file, data.join(''), { compression: 'DEFLATE' });
  1455. } else {
  1456. let ssIdx = 0;
  1457. for (let i = 0; i < data.length; i++) {
  1458. if (signSheetIdxArr[i]) {
  1459. ssIdx++;
  1460. const ssData = writeWorkSheetRels(ssIdx);
  1461. file = 'sheet' + (i + 1) + '.xml.rels';
  1462. zip_xl_worksheets_rels.file(file, ssData.join(''), { compression: 'DEFLATE' });
  1463. }
  1464. }
  1465. }
  1466. }
  1467. file = 'sharedStrings.xml';
  1468. data = writeSharedString(sharedStrList);
  1469. zip_xl.file(file, data.join(''), { compression: 'DEFLATE' });
  1470. file = 'styles.xml';
  1471. data = writeStyles(stylesObj, hasSignature);
  1472. zip_xl.file(file, data.join(''), { compression: 'DEFLATE' });
  1473. // console.log('step 7');
  1474. if (fName) {
  1475. // let newName = '' + (new Date()).valueOf();
  1476. const newName = uuidV1();
  1477. // console.log('current path: ' + __dirname);
  1478. // const filePath = this.app.baseDir + '/app/public/download/';
  1479. zip.generateNodeStream({ type: 'nodebuffer', streamFiles: true })
  1480. .pipe(fs.createWriteStream(__dirname.slice(0, __dirname.length - 13) + '/public/download/' + newName + '.xlsx'))
  1481. .on('finish', function() {
  1482. // JSZip generates a readable stream with a "end" event,
  1483. // but is piped here in a writable stream which emits a "finish" event.
  1484. console.log(newName + '.xlsx was written.');
  1485. if (callback) callback(null, newName);
  1486. });
  1487. } else {
  1488. // return zip.generateNodeStream({type:'nodebuffer',streamFiles:true});
  1489. return zip;
  1490. }
  1491. },
  1492. exportExcelInOneBook: function(pageDataArray, paperSize, fName, baseDir, roleRelArr, callback) {
  1493. const me = this;
  1494. const newPageData = {};
  1495. // 1. 重新编排一下数据,把一份报表的pageData合并到一起作为一个Sheet输出(需要重新调整数据纵向坐标),多份报表数据就形成多个Sheet
  1496. // -- 简单来说,就是重新包装数据
  1497. try {
  1498. // 1.1 newPageData外围属性
  1499. const newContrl = {};
  1500. const newFont = {};
  1501. const newStyle = {};
  1502. const custMergeBands = [];
  1503. for (let i = 0; i < pageDataArray.length; i++) {
  1504. mergeProperties(newContrl, pageDataArray[i][JV.NODE_CONTROL_COLLECTION]);
  1505. mergeProperties(newFont, pageDataArray[i][JV.NODE_FONT_COLLECTION]);
  1506. mergeProperties(newStyle, pageDataArray[i][JV.NODE_STYLE_COLLECTION]);
  1507. }
  1508. newPageData[JV.NODE_CONTROL_COLLECTION] = newContrl;
  1509. newPageData[JV.NODE_FONT_COLLECTION] = newFont;
  1510. newPageData[JV.NODE_STYLE_COLLECTION] = newStyle;
  1511. newPageData[JV.NODE_PAGE_INFO] = pageDataArray[0][JV.NODE_PAGE_INFO];
  1512. newPageData[JV.BAND_PROP_MERGE_BAND] = pageDataArray[0][JV.BAND_PROP_MERGE_BAND];
  1513. // 1.2 重新设置pageDataArray的各个cell的Top/Bottom坐标
  1514. const sheetNames = [];
  1515. const newPagePos = [];
  1516. for (let i = 0; i < pageDataArray.length; i++) {
  1517. let offsetY = 0;
  1518. const mergeBand = {};
  1519. custMergeBands.push(pageDataArray[i][JV.BAND_PROP_MERGE_BAND]);
  1520. // 备注:不同的报表有可能有不同的边框,如封面表就是无边框的
  1521. mergeBand[JV.PROP_LEFT] = [];
  1522. mergeBand[JV.PROP_RIGHT] = [];
  1523. mergeBand[JV.PROP_TOP] = [];
  1524. mergeBand[JV.PROP_BOTTOM] = [];
  1525. newPagePos.push(mergeBand);
  1526. mergeBand[JV.PROP_LEFT].push(pageDataArray[i][JV.BAND_PROP_MERGE_BAND][JV.PROP_LEFT]);
  1527. mergeBand[JV.PROP_RIGHT].push(pageDataArray[i][JV.BAND_PROP_MERGE_BAND][JV.PROP_RIGHT]);
  1528. sheetNames.push(pageDataArray[i][JV.NODE_PAGE_INFO][JV.NODE_MAIN_INFO_RPT_NAME]);
  1529. // 加分页符(分页符要在外部处理好)-------------------
  1530. _setupPgBrks(pageDataArray[i]);
  1531. // 加分页符结束-------------------
  1532. for (let j = 0; j < pageDataArray[i].items.length; j++) {
  1533. let maxY = 0;
  1534. let minY = 100000;
  1535. if (pageDataArray[i].items[j][JV.PAGE_SPECIAL_MERGE_POS]) {
  1536. let pos = pageDataArray[i].items[j][JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_TOP][0] + offsetY;
  1537. mergeBand[JV.PROP_TOP].push(pos);
  1538. pos = pageDataArray[i].items[j][JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_BOTTOM][0] + offsetY;
  1539. mergeBand[JV.PROP_BOTTOM].push(pos);
  1540. } else if (pageDataArray[i].items[j][JV.PROP_PAGE_MERGE_BORDER]) {
  1541. let pos = pageDataArray[i].items[j][JV.PROP_PAGE_MERGE_BORDER][JV.PROP_TOP] + offsetY;
  1542. mergeBand[JV.PROP_TOP].push(pos);
  1543. pos = pageDataArray[i].items[j][JV.PROP_PAGE_MERGE_BORDER][JV.PROP_BOTTOM] + offsetY;
  1544. mergeBand[JV.PROP_BOTTOM].push(pos);
  1545. } else {
  1546. mergeBand[JV.PROP_TOP].push(pageDataArray[i][JV.BAND_PROP_MERGE_BAND][JV.PROP_TOP] + offsetY);
  1547. mergeBand[JV.PROP_BOTTOM].push(pageDataArray[i][JV.BAND_PROP_MERGE_BAND][JV.PROP_BOTTOM] + offsetY);
  1548. }
  1549. // 1.2.1 重新设置普通cells的Top Bottom坐标
  1550. for (const cell of pageDataArray[i].items[j].cells) {
  1551. // for (let k = 0; k < pageDataArray[i].items[j].cells.length; k++) {
  1552. if (maxY < cell[JV.PROP_AREA][JV.PROP_BOTTOM]) {
  1553. maxY = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  1554. }
  1555. if (minY > cell[JV.PROP_AREA][JV.PROP_TOP]) {
  1556. minY = cell[JV.PROP_AREA][JV.PROP_TOP];
  1557. }
  1558. cell[JV.PROP_AREA][JV.PROP_BOTTOM] += offsetY;
  1559. cell[JV.PROP_AREA][JV.PROP_TOP] += offsetY;
  1560. }
  1561. // 1.2.2 重新设置电子签名cells的Top Bottom坐标
  1562. for (const cell of pageDataArray[i].items[j].signature_cells) {
  1563. if (maxY < cell[JV.PROP_AREA][JV.PROP_BOTTOM]) {
  1564. maxY = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  1565. }
  1566. if (minY > cell[JV.PROP_AREA][JV.PROP_TOP]) {
  1567. minY = cell[JV.PROP_AREA][JV.PROP_TOP];
  1568. }
  1569. // console.log('before');
  1570. // console.log(cell);
  1571. cell[JV.PROP_AREA][JV.PROP_BOTTOM] += offsetY;
  1572. cell[JV.PROP_AREA][JV.PROP_TOP] += offsetY;
  1573. // console.log('after');
  1574. // console.log(cell);
  1575. }
  1576. // 1.2.3 重新设置电子签名日期cells的Top Bottom坐标
  1577. for (const cell of pageDataArray[i].items[j].signature_date_cells) {
  1578. if (maxY < cell[JV.PROP_AREA][JV.PROP_BOTTOM]) {
  1579. maxY = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  1580. }
  1581. if (minY > cell[JV.PROP_AREA][JV.PROP_TOP]) {
  1582. minY = cell[JV.PROP_AREA][JV.PROP_TOP];
  1583. }
  1584. cell[JV.PROP_AREA][JV.PROP_BOTTOM] += offsetY;
  1585. cell[JV.PROP_AREA][JV.PROP_TOP] += offsetY;
  1586. }
  1587. 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;
  1588. offsetY += (maxY - minY);
  1589. if (bottomGap > 10) {
  1590. offsetY += (bottomGap - 10);
  1591. }
  1592. }
  1593. }
  1594. // 2. newPageData的items属性及相关分页符
  1595. newPageData.items = [];
  1596. newPageData.pageBreaks = [];
  1597. for (let i = 0; i < pageDataArray.length; i++) {
  1598. const pageItem = {};
  1599. pageItem[JV.PROP_PAGE_SEQ] = i + 1;
  1600. pageItem[JV.PROP_CELLS] = [];
  1601. for (let j = 0; j < pageDataArray[i].items.length; j++) {
  1602. for (let k = 0; k < pageDataArray[i].items[j][JV.PROP_CELLS].length; k++) {
  1603. pageItem[JV.PROP_CELLS].push(pageDataArray[i].items[j][JV.PROP_CELLS][k]);
  1604. }
  1605. }
  1606. pageItem[JV.PROP_SIGNATURE_CELLS] = [];
  1607. for (let j = 0; j < pageDataArray[i].items.length; j++) {
  1608. for (let k = 0; k < pageDataArray[i].items[j][JV.PROP_SIGNATURE_CELLS].length; k++) {
  1609. pageItem[JV.PROP_SIGNATURE_CELLS].push(pageDataArray[i].items[j][JV.PROP_SIGNATURE_CELLS][k]);
  1610. }
  1611. }
  1612. pageItem[JV.PROP_SIGNATURE_DATE_CELLS] = [];
  1613. for (let j = 0; j < pageDataArray[i].items.length; j++) {
  1614. for (let k = 0; k < pageDataArray[i].items[j][JV.PROP_SIGNATURE_DATE_CELLS].length; k++) {
  1615. pageItem[JV.PROP_SIGNATURE_DATE_CELLS].push(pageDataArray[i].items[j][JV.PROP_SIGNATURE_DATE_CELLS][k]);
  1616. }
  1617. }
  1618. pageItem[JV.PROP_SIGNATURE_AUDIT_CELLS] = [];
  1619. for (let j = 0; j < pageDataArray[i].items.length; j++) {
  1620. for (let k = 0; k < pageDataArray[i].items[j][JV.PROP_SIGNATURE_AUDIT_CELLS].length; k++) {
  1621. pageItem[JV.PROP_SIGNATURE_AUDIT_CELLS].push(pageDataArray[i].items[j][JV.PROP_SIGNATURE_AUDIT_CELLS][k]);
  1622. }
  1623. }
  1624. newPagePos[i][JV.NODE_PAGE_SIZE] = pageDataArray[i][JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE];
  1625. pageItem[JV.PAGE_SPECIAL_MERGE_POS] = newPagePos[i];
  1626. newPageData.items.push(pageItem);
  1627. // 重新分配分页符()------------------
  1628. if (pageDataArray[i].pageBreaks.length === 1) {
  1629. newPageData.pageBreaks.push(pageDataArray[i].pageBreaks[0]);
  1630. } else {
  1631. newPageData.pageBreaks.push([]);
  1632. }
  1633. // 重新分配分页符结束------------------
  1634. }
  1635. // 3. everything is ok, then call me
  1636. // let roleRel = null; // 未来调用的时候,这个属性要从外面给!!!
  1637. // roleRelArr
  1638. me.exportExcel(newPageData, paperSize, fName, 'false', sheetNames, custMergeBands, baseDir, roleRelArr, callback);
  1639. // fsUtil.writeObjToFile(newPageData, 'D:/GitHome/ConstructionOperation/tmp/combinedHeader.js');
  1640. } catch (e) {
  1641. console.log(e);
  1642. }
  1643. },
  1644. };