|
@@ -1,21 +1,21 @@
|
|
|
+'use strict';
|
|
|
/**
|
|
|
* Created by Tony on 2017/4/1.
|
|
|
*/
|
|
|
-let JV = require('../rpt_component/jpc_value_define');
|
|
|
-let fs = require('fs');
|
|
|
-let JSZip = require("jszip");
|
|
|
-let strUtil = require('../public/stringUtil');
|
|
|
-let jpcCmnHelper = require('../rpt_component/helper/jpc_helper_common');
|
|
|
-let DPI = jpcCmnHelper.getScreenDPI()[0];
|
|
|
-let fsUtil = require('../public/fsUtil');
|
|
|
+const JV = require('../rpt_component/jpc_value_define');
|
|
|
+const fs = require('fs');
|
|
|
+const JSZip = require('jszip');
|
|
|
+const strUtil = require('../public/stringUtil');
|
|
|
+const jpcCmnHelper = require('../rpt_component/helper/jpc_helper_common');
|
|
|
+const DPI = jpcCmnHelper.getScreenDPI()[0];
|
|
|
+const fsUtil = require('../public/fsUtil');
|
|
|
const dftHeadXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
|
const uuidV1 = require('uuid/v1');
|
|
|
|
|
|
function writeContentTypes(sheets, isSinglePage) {
|
|
|
- let rst = [];
|
|
|
+ const rst = [];
|
|
|
rst.push(dftHeadXml + '\r\n');
|
|
|
rst.push('<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">');
|
|
|
- //...
|
|
|
rst.push('<Override PartName="/xl/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>');
|
|
|
rst.push('<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>');
|
|
|
rst.push('<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>');
|
|
@@ -34,8 +34,8 @@ function writeContentTypes(sheets, isSinglePage) {
|
|
|
rst.push('</Types>');
|
|
|
return rst;
|
|
|
}
|
|
|
-function writeRootRels(){
|
|
|
- let rst = [];
|
|
|
+function writeRootRels() {
|
|
|
+ const rst = [];
|
|
|
rst.push(dftHeadXml + '\r\n');
|
|
|
rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
|
|
|
rst.push('<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>');
|
|
@@ -45,7 +45,7 @@ function writeRootRels(){
|
|
|
return rst;
|
|
|
}
|
|
|
function writeApp(sheets, isSinglePage) {
|
|
|
- let rst = [];
|
|
|
+ const rst = [];
|
|
|
rst.push(dftHeadXml + '\r\n');
|
|
|
rst.push('<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">');
|
|
|
rst.push('<Application>Microsoft Excel</Application>');
|
|
@@ -54,7 +54,7 @@ function writeApp(sheets, isSinglePage) {
|
|
|
rst.push('<HeadingPairs>');
|
|
|
rst.push('<vt:vector size="2" baseType="variant">');
|
|
|
rst.push('<vt:variant><vt:lpstr>工作表</vt:lpstr></vt:variant>');
|
|
|
- if (isSinglePage) rst.push('<vt:variant><vt:i4>1</vt:i4></vt:variant>')
|
|
|
+ if (isSinglePage) rst.push('<vt:variant><vt:i4>1</vt:i4></vt:variant>');
|
|
|
else rst.push('<vt:variant><vt:i4>' + sheets.length + '</vt:i4></vt:variant>');
|
|
|
rst.push('</vt:vector>');
|
|
|
rst.push('</HeadingPairs>');
|
|
@@ -79,8 +79,8 @@ function writeApp(sheets, isSinglePage) {
|
|
|
return rst;
|
|
|
}
|
|
|
function writeCore() {
|
|
|
- let rst = [];
|
|
|
- let p_fillZero = function(val){
|
|
|
+ const rst = [];
|
|
|
+ const p_fillZero = function(val) {
|
|
|
let rst = val;
|
|
|
if (val < 10) {
|
|
|
rst = '0' + val;
|
|
@@ -91,18 +91,17 @@ function writeCore() {
|
|
|
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">');
|
|
|
rst.push('<dc:creator>SmartCost</dc:creator>');
|
|
|
rst.push('<cp:lastModifiedBy>SmartCost</cp:lastModifiedBy>');
|
|
|
- let dt = new Date();
|
|
|
- dt.setDate(dt.getDate() - 8/24); //it's GMT time, so please add the server offset time ( -8 hours )
|
|
|
- let dtStr = dt.getFullYear() + '-' + p_fillZero(dt.getMonth()+1) + '-' + p_fillZero(dt.getDate()) + 'T' +
|
|
|
+ const dt = new Date();
|
|
|
+ dt.setDate(dt.getDate() - 8 / 24); // it's GMT time, so please add the server offset time ( -8 hours )
|
|
|
+ const dtStr = dt.getFullYear() + '-' + p_fillZero(dt.getMonth() + 1) + '-' + p_fillZero(dt.getDate()) + 'T' +
|
|
|
p_fillZero(dt.getHours()) + ':' + p_fillZero(dt.getMinutes()) + ':' + p_fillZero(dt.getSeconds()) + 'Z';
|
|
|
rst.push('<dcterms:created xsi:type="dcterms:W3CDTF">' + dtStr + '</dcterms:created>');
|
|
|
rst.push('<dcterms:modified xsi:type="dcterms:W3CDTF">' + dtStr + '</dcterms:modified>');
|
|
|
- //rst.push('');
|
|
|
rst.push('</cp:coreProperties>');
|
|
|
return rst;
|
|
|
}
|
|
|
-function writeXlWorkBook(sheets, isSinglePage){
|
|
|
- let rst = [];
|
|
|
+function writeXlWorkBook(sheets, isSinglePage) {
|
|
|
+ const rst = [];
|
|
|
rst.push(dftHeadXml + '\r\n');
|
|
|
rst.push('<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">');
|
|
|
rst.push('<fileVersion appName="xl" lastEdited="4" lowestEdited="4" rupBuild="4505"/>');
|
|
@@ -121,8 +120,9 @@ function writeXlWorkBook(sheets, isSinglePage){
|
|
|
rst.push('</workbook>');
|
|
|
return rst;
|
|
|
}
|
|
|
-function writeXlRels(sheets, isSinglePage){
|
|
|
- let rst = [], idx = 1;
|
|
|
+function writeXlRels(sheets, isSinglePage) {
|
|
|
+ const rst = [];
|
|
|
+ let idx = 1;
|
|
|
rst.push(dftHeadXml + '\r\n');
|
|
|
rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
|
|
|
if (isSinglePage) {
|
|
@@ -142,51 +142,51 @@ function writeXlRels(sheets, isSinglePage){
|
|
|
rst.push('</Relationships>');
|
|
|
return rst;
|
|
|
}
|
|
|
-function writeTheme(){
|
|
|
- let rst = fs.readFileSync(__dirname + '/excel_base_files/theme1.xml', 'utf8', 'r');
|
|
|
+function writeTheme() {
|
|
|
+ const rst = fs.readFileSync(__dirname + '/excel_base_files/theme1.xml', 'utf8', 'r');
|
|
|
return rst;
|
|
|
}
|
|
|
-function writeStyles(stylesObj){
|
|
|
- let rst = [];
|
|
|
+function writeStyles(stylesObj) {
|
|
|
+ const rst = [];
|
|
|
rst.push(dftHeadXml + '\r\n');
|
|
|
rst.push('<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">');
|
|
|
- //1. push fonts
|
|
|
+ // 1. push fonts
|
|
|
rst.push('<fonts count="' + stylesObj.fonts.length + '">');
|
|
|
for (let i = 0; i < stylesObj.fonts.length; i++) {
|
|
|
- let font = stylesObj.fonts[i];
|
|
|
+ const font = stylesObj.fonts[i];
|
|
|
rst.push('<font>');
|
|
|
- if (strUtil.convertStrToBoolean(font[JV.FONT_PROPS[3]])) {
|
|
|
+ if (strUtil.convertStrToBoolean(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]])) {
|
|
|
rst.push('<b/>');
|
|
|
}
|
|
|
- if (strUtil.convertStrToBoolean(font[JV.FONT_PROPS[4]])) {
|
|
|
+ if (strUtil.convertStrToBoolean(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]])) {
|
|
|
rst.push('<i/>');
|
|
|
}
|
|
|
- if (strUtil.convertStrToBoolean(font[JV.FONT_PROPS[5]])) {
|
|
|
+ if (strUtil.convertStrToBoolean(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]])) {
|
|
|
rst.push('<u/>');
|
|
|
}
|
|
|
rst.push('<sz val="' + font.size + '"/>');
|
|
|
rst.push('<color indexed="' + font.colorIdx + '"/>');
|
|
|
- rst.push('<name val="' + font[JV.FONT_PROPS[0]] + '"/>');
|
|
|
+ rst.push('<name val="' + font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]] + '"/>');
|
|
|
rst.push('<charset val="' + font.charset + '"/>');
|
|
|
rst.push('</font>');
|
|
|
}
|
|
|
rst.push('</fonts>');
|
|
|
- //2. push default fills
|
|
|
+ // 2. push default fills
|
|
|
rst.push('<fills count="2"><fill><patternFill patternType="none" /></fill><fill><patternFill patternType="gray125" /></fill></fills>');
|
|
|
- //3. push borders
|
|
|
+ // 3. push borders
|
|
|
rst.push('<borders count="' + stylesObj.borders.length + '">');
|
|
|
- let private_setBorder = function(border, borderDirection) {
|
|
|
+ const private_setBorder = function(border, borderDirection) {
|
|
|
if (parseInt(border[borderDirection][JV.PROP_LINE_WEIGHT]) === 0) {
|
|
|
rst.push('<' + borderDirection.toLowerCase() + '/>');
|
|
|
} else {
|
|
|
let bW = 'thin';
|
|
|
if (parseInt(border[borderDirection][JV.PROP_LINE_WEIGHT]) === 2) bW = 'medium';
|
|
|
if (parseInt(border[borderDirection][JV.PROP_LINE_WEIGHT]) > 2) bW = 'thick';
|
|
|
- rst.push('<' + borderDirection.toLowerCase() + ' style="' + bW + '">' + '<color indexed="64"/>' + '</' + borderDirection.toLowerCase() + '>');
|
|
|
+ rst.push('<' + borderDirection.toLowerCase() + ' style="' + bW + '"><color indexed="64"/></' + borderDirection.toLowerCase() + '>');
|
|
|
}
|
|
|
};
|
|
|
for (let i = 0; i < stylesObj.borders.length; i++) {
|
|
|
- let border = stylesObj.borders[i];
|
|
|
+ const border = stylesObj.borders[i];
|
|
|
rst.push('<border>');
|
|
|
private_setBorder(border, JV.PROP_LEFT);
|
|
|
private_setBorder(border, JV.PROP_RIGHT);
|
|
@@ -196,15 +196,15 @@ function writeStyles(stylesObj){
|
|
|
rst.push('</border>');
|
|
|
}
|
|
|
rst.push('</borders>');
|
|
|
- //4. push cellStyleXfs
|
|
|
+ // 4. push cellStyleXfs
|
|
|
rst.push('<cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"><alignment vertical="center"/></xf></cellStyleXfs>');
|
|
|
- //5. push cellXfs
|
|
|
+ // 5. push cellXfs
|
|
|
rst.push('<cellXfs count="' + stylesObj.cellXfs.length + '">');
|
|
|
for (let i = 0; i < stylesObj.cellXfs.length; i++) {
|
|
|
- let excelStyle = stylesObj.cellXfs[i];
|
|
|
+ const excelStyle = stylesObj.cellXfs[i];
|
|
|
rst.push('<xf numFmtId="0" fontId="' + excelStyle.fontId + '" fillId="0" borderId="' + excelStyle.borderId + '" xfId="0">');
|
|
|
- //pageData[JV.NODE_FONT_COLLECTION] excelStyle.fontId
|
|
|
- let alignStr = "<alignment";
|
|
|
+ // pageData[JV.NODE_FONT_COLLECTION] excelStyle.fontId
|
|
|
+ let alignStr = '<alignment';
|
|
|
let textRotation = 0;
|
|
|
let newHorizontal = excelStyle[JV.CONTROL_PROPS[2]];
|
|
|
let newVertical = excelStyle[JV.CONTROL_PROPS[3]];
|
|
@@ -212,37 +212,38 @@ function writeStyles(stylesObj){
|
|
|
newVertical = excelStyle[JV.CONTROL_PROPS[5]];
|
|
|
}
|
|
|
if (parseInt(excelStyle.fontAngle) !== 0) {
|
|
|
- let tmpH = newHorizontal, tmpV = newVertical;
|
|
|
+ let tmpH = newHorizontal;
|
|
|
+ let tmpV = newVertical;
|
|
|
if (excelStyle.fontAngle > 0) {
|
|
|
textRotation = 180;
|
|
|
- if (newHorizontal === "left") {
|
|
|
+ if (newHorizontal === 'left') {
|
|
|
tmpV = 'top';
|
|
|
- } else if (newHorizontal === "right") {
|
|
|
+ } else if (newHorizontal === 'right') {
|
|
|
tmpV = 'bottom';
|
|
|
} else {
|
|
|
tmpV = 'center';
|
|
|
}
|
|
|
- if (newVertical === "top") {
|
|
|
+ if (newVertical === 'top') {
|
|
|
tmpH = 'right';
|
|
|
- } else if (newVertical === "bottom") {
|
|
|
+ } else if (newVertical === 'bottom') {
|
|
|
tmpH = 'left';
|
|
|
- } else if (newVertical === "justify") {
|
|
|
+ } else if (newVertical === 'justify') {
|
|
|
tmpH = 'justify';
|
|
|
} else {
|
|
|
tmpH = 'center';
|
|
|
}
|
|
|
} else {
|
|
|
textRotation = 90;
|
|
|
- if (newHorizontal === "left") {
|
|
|
+ if (newHorizontal === 'left') {
|
|
|
tmpV = 'bottom';
|
|
|
- } else if (newHorizontal === "right") {
|
|
|
+ } else if (newHorizontal === 'right') {
|
|
|
tmpV = 'top';
|
|
|
} else {
|
|
|
tmpV = 'center';
|
|
|
}
|
|
|
- if (newVertical === "top") {
|
|
|
+ if (newVertical === 'top') {
|
|
|
tmpH = 'left';
|
|
|
- } else if (newVertical === "bottom") {
|
|
|
+ } else if (newVertical === 'bottom') {
|
|
|
tmpH = 'right';
|
|
|
} else {
|
|
|
tmpH = 'center';
|
|
@@ -266,16 +267,16 @@ function writeStyles(stylesObj){
|
|
|
rst.push('</xf>');
|
|
|
}
|
|
|
rst.push('</cellXfs>');
|
|
|
- //6. others (xfl style / dxfs / tableStyles)
|
|
|
+ // 6. others (xfl style / dxfs / tableStyles)
|
|
|
rst.push('<cellStyles count="1"><cellStyle name="常规" xfId="0" builtinId="0"/></cellStyles>');
|
|
|
rst.push('<dxfs count="0"/>');
|
|
|
rst.push('<tableStyles count="0" defaultTableStyle="TableStyleMedium9" defaultPivotStyle="PivotStyleLight16"/>');
|
|
|
rst.push('</styleSheet>');
|
|
|
return rst;
|
|
|
}
|
|
|
-function writeSharedString(sharedStrList){
|
|
|
- let rst = [];
|
|
|
- let pri_func_write = function(cellVal) {
|
|
|
+function writeSharedString(sharedStrList) {
|
|
|
+ const rst = [];
|
|
|
+ const pri_func_write = function(cellVal) {
|
|
|
if (cellVal !== null) {
|
|
|
if ((typeof cellVal === 'string') && cellVal.indexOf(' ') === 0) {
|
|
|
rst.push('<si><t xml:space="preserve">' + cellVal + '</t></si>');
|
|
@@ -287,13 +288,13 @@ function writeSharedString(sharedStrList){
|
|
|
if (sharedStrList && sharedStrList.length > 0) {
|
|
|
rst.push(dftHeadXml + '\r\n');
|
|
|
rst.push('<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="' + sharedStrList.length + '" uniqueCount="' + sharedStrList.length + '">');
|
|
|
- let regExp = new RegExp("<", "gm");
|
|
|
+ const regExp = new RegExp('<', 'gm');
|
|
|
for (let i = 0; i < sharedStrList.length; i++) {
|
|
|
if (typeof sharedStrList[i] === 'string') {
|
|
|
- //转换特殊字符,如 < , 则需要转义一下
|
|
|
- sharedStrList[i] = sharedStrList[i].replace(regExp, "<");
|
|
|
+ // 转换特殊字符,如 < , 则需要转义一下
|
|
|
+ sharedStrList[i] = sharedStrList[i].replace(regExp, '<');
|
|
|
if (sharedStrList[i].indexOf('|') >= 0) {
|
|
|
- //rst.push('<si><t>' + sharedStrList[i].split('|').join('\r\n') + '</t></si>');
|
|
|
+ // rst.push('<si><t>' + sharedStrList[i].split('|').join('\r\n') + '</t></si>');
|
|
|
// rst.push('<si><t>' + sharedStrList[i].split('|').join('\n') + '</t></si>');
|
|
|
pri_func_write(sharedStrList[i].split('|').join('\n'));
|
|
|
} else {
|
|
@@ -310,25 +311,25 @@ function writeSharedString(sharedStrList){
|
|
|
}
|
|
|
return rst;
|
|
|
}
|
|
|
-function writeSheets(pageData, paperSize, sharedStrList, stylesObj, isSinglePage, custSheetMergeBands){
|
|
|
- let rst = [];
|
|
|
- let private_pushDftFont = function(){
|
|
|
- let font = {};
|
|
|
+function writeSheets(pageData, paperSize, sharedStrList, stylesObj, isSinglePage, custSheetMergeBands) {
|
|
|
+ const rst = [];
|
|
|
+ const private_pushDftFont = function() {
|
|
|
+ const font = {};
|
|
|
if (!(stylesObj.fonts)) {
|
|
|
stylesObj.fonts = [];
|
|
|
}
|
|
|
- font[JV.FONT_PROPS[0]] = "宋体"; //font name
|
|
|
+ font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]] = '宋体'; // font name
|
|
|
font.size = 12;
|
|
|
font.charset = 134;
|
|
|
- font.colorIdx = "8";
|
|
|
+ font.colorIdx = '8';
|
|
|
stylesObj.fonts.push(font);
|
|
|
};
|
|
|
- let private_buildFirstDftStyle = function () {
|
|
|
+ const private_buildFirstDftStyle = function() {
|
|
|
stylesObj.cellXfs = [];
|
|
|
stylesObj.borders = [];
|
|
|
- let fontId = 0;
|
|
|
- let borderId = 0;
|
|
|
- let border = {};
|
|
|
+ const fontId = 0;
|
|
|
+ const borderId = 0;
|
|
|
+ const border = {};
|
|
|
border[JV.PROP_LEFT] = {};
|
|
|
border[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT] = 0;
|
|
|
border[JV.PROP_RIGHT] = {};
|
|
@@ -339,8 +340,8 @@ function writeSheets(pageData, paperSize, sharedStrList, stylesObj, isSinglePage
|
|
|
border[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT] = 0;
|
|
|
stylesObj.borders.push(border);
|
|
|
|
|
|
- let cellControl = pageData[JV.NODE_CONTROL_COLLECTION].Default;
|
|
|
- let sheetControl = {};
|
|
|
+ const cellControl = pageData[JV.NODE_CONTROL_COLLECTION].Default;
|
|
|
+ const sheetControl = {};
|
|
|
sheetControl.fontId = fontId;
|
|
|
sheetControl.borderId = borderId;
|
|
|
sheetControl.fontAngle = 0;
|
|
@@ -348,7 +349,7 @@ function writeSheets(pageData, paperSize, sharedStrList, stylesObj, isSinglePage
|
|
|
sheetControl[JV.CONTROL_PROPS[i]] = cellControl[JV.CONTROL_PROPS[i]];
|
|
|
}
|
|
|
stylesObj.cellXfs.push(sheetControl);
|
|
|
- }
|
|
|
+ };
|
|
|
private_pushDftFont();
|
|
|
private_buildFirstDftStyle();
|
|
|
if (isSinglePage) {
|
|
@@ -364,28 +365,24 @@ function writeSheets(pageData, paperSize, sharedStrList, stylesObj, isSinglePage
|
|
|
}
|
|
|
return rst;
|
|
|
}
|
|
|
-function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, appointedMergeBand){
|
|
|
- let rst = [], xPos = [], yPos = [], yMultiPos = [], currentMergeBorder = null,
|
|
|
- headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
- let currentPageMergePos = null; //在 JV.PAGING_OPTION_INFINITY 场合应用
|
|
|
- let private_pre_analyze_pos = function(){
|
|
|
- let cell, pos;
|
|
|
- let self_analyze_sheet_pos = function (theShtData, theXPos, theYPos) {
|
|
|
- // theShtData.cells.sort(function(cell1, cell2) {
|
|
|
- // let rst = 0;
|
|
|
- // if (cell1[JV.PROP_AREA][JV.PROP_TOP] > cell2[JV.PROP_AREA][JV.PROP_TOP]) {
|
|
|
- // rst = 1;
|
|
|
- // } else if (cell1[JV.PROP_AREA][JV.PROP_TOP] < cell2[JV.PROP_AREA][JV.PROP_TOP]) {
|
|
|
- // rst = -1;
|
|
|
- // } else {
|
|
|
- // if (cell1[JV.PROP_AREA][JV.PROP_LEFT] > cell2[JV.PROP_AREA][JV.PROP_LEFT]) {
|
|
|
- // rst = 1;
|
|
|
- // } else if (cell1[JV.PROP_AREA][JV.PROP_LEFT] < cell2[JV.PROP_AREA][JV.PROP_LEFT]) {
|
|
|
- // rst = -1;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // return rst;
|
|
|
- // });
|
|
|
+function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, appointedMergeBand) {
|
|
|
+ const rst = [];
|
|
|
+ const xPos = [];
|
|
|
+ let yPos = [];
|
|
|
+ const yMultiPos = [];
|
|
|
+ let currentMergeBorder = null;
|
|
|
+ const headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
+ let currentPageMergePos = null; // 在 JV.PAGING_OPTION_INFINITY 场合应用
|
|
|
+ const private_pre_analyze_pos = function() {
|
|
|
+ let cell;
|
|
|
+ let pos;
|
|
|
+ const private_array_sort = function(i1, i2) {
|
|
|
+ let rst = 0;
|
|
|
+ if (i1 > i2) { rst = 1; } else
|
|
|
+ if (i1 < i2) rst = -1;
|
|
|
+ return rst;
|
|
|
+ };
|
|
|
+ const self_analyze_sheet_pos = function(theShtData, theXPos, theYPos) {
|
|
|
for (let i = 0; i < theShtData.cells.length; i++) {
|
|
|
cell = theShtData.cells[i];
|
|
|
pos = cell[JV.PROP_AREA][JV.PROP_LEFT];
|
|
@@ -400,21 +397,21 @@ function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, ap
|
|
|
};
|
|
|
xPos.push(0);
|
|
|
if (sheetData) {
|
|
|
- //current sheet data
|
|
|
+ // current sheet data
|
|
|
yPos.push(0);
|
|
|
self_analyze_sheet_pos(sheetData, xPos, yPos);
|
|
|
xPos.sort(private_array_sort);
|
|
|
yPos.sort(private_array_sort);
|
|
|
} else {
|
|
|
- //total data in one sheet
|
|
|
- let 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);
|
|
|
- for (let shtItemData of pageData.items) {
|
|
|
- let tmpPos = [];
|
|
|
+ // total data in one sheet
|
|
|
+ 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);
|
|
|
+ for (const shtItemData of pageData.items) {
|
|
|
+ const tmpPos = [];
|
|
|
tmpPos.push(0);
|
|
|
self_analyze_sheet_pos(shtItemData, xPos, tmpPos);
|
|
|
tmpPos.sort(private_array_sort);
|
|
|
if (marginBottomPos - tmpPos[tmpPos.length - 1] > 10) {
|
|
|
- //此逻辑是为了防止打印跨页(假设有些报表模板高度设置离底部margin还好远,导出excel后预览时会发现跨页现象(即下一页的某几行数据会挪到前一页来预览))
|
|
|
+ // 此逻辑是为了防止打印跨页(假设有些报表模板高度设置离底部margin还好远,导出excel后预览时会发现跨页现象(即下一页的某几行数据会挪到前一页来预览))
|
|
|
tmpPos.push(marginBottomPos - 10);
|
|
|
}
|
|
|
yMultiPos.push(tmpPos);
|
|
@@ -423,29 +420,26 @@ function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, ap
|
|
|
yPos = yMultiPos[0];
|
|
|
}
|
|
|
};
|
|
|
- let private_array_sort = function(i1, i2){
|
|
|
- let rst = 0;
|
|
|
- if (i1 > i2) {rst = 1} else
|
|
|
- if (i1 < i2) rst = -1;
|
|
|
- return rst;
|
|
|
- };
|
|
|
- let private_getCellIdxStr = function(idx){
|
|
|
+ const private_getCellIdxStr = function(idx) {
|
|
|
let rst = 'A';
|
|
|
if (idx < 26) {
|
|
|
rst = headerStr[idx];
|
|
|
- } else if (idx < 26*26+26) {
|
|
|
- let ti = Math.floor(idx / 26), tj = idx % 26;
|
|
|
+ } else if (idx < 26 * 26 + 26) {
|
|
|
+ const ti = Math.floor(idx / 26);
|
|
|
+ const tj = idx % 26;
|
|
|
rst = headerStr[ti - 1] + headerStr[tj];
|
|
|
- } else if (idx < 26*26*26+26) {
|
|
|
- let ti = Math.floor(idx / (26*26)), tj = Math.floor((idx - ti * 26*26) / 26), tk = idx % 26;
|
|
|
- rst = headerStr[ti - 1] + headerStr[tj-1] + headerStr[tk];
|
|
|
+ } else if (idx < 26 * 26 * 26 + 26) {
|
|
|
+ const ti = Math.floor(idx / (26 * 26));
|
|
|
+ const tj = Math.floor((idx - ti * 26 * 26) / 26);
|
|
|
+ const tk = idx % 26;
|
|
|
+ rst = headerStr[ti - 1] + headerStr[tj - 1] + headerStr[tk];
|
|
|
}
|
|
|
return rst;
|
|
|
};
|
|
|
- let private_getSharedStrIdx = function(val) {
|
|
|
+ const private_getSharedStrIdx = function(val) {
|
|
|
let strVal = val;
|
|
|
if (val === null || val === undefined || (typeof val === 'number' && isNaN(val))) {
|
|
|
- strVal = "";
|
|
|
+ strVal = '';
|
|
|
}
|
|
|
let rst = sharedStrList.indexOf(strVal);
|
|
|
if (rst < 0) {
|
|
@@ -454,25 +448,25 @@ function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, ap
|
|
|
}
|
|
|
return rst;
|
|
|
};
|
|
|
- let private_getFontId = function(cell) {
|
|
|
- let rst = 0, hasFont = false;
|
|
|
+ const private_getFontId = function(cell) {
|
|
|
+ let rst = 0;
|
|
|
+ let hasFont = false;
|
|
|
if (!(stylesObj.fonts)) {
|
|
|
stylesObj.fonts = [];
|
|
|
- //for (let i = 0; i < sheetData.font_collection)
|
|
|
+ // for (let i = 0; i < sheetData.font_collection)
|
|
|
}
|
|
|
let sheetFont = null;
|
|
|
- if (typeof cell[JV.PROP_FONT] === "string") {
|
|
|
+ if (typeof cell[JV.PROP_FONT] === 'string') {
|
|
|
sheetFont = pageData[JV.NODE_FONT_COLLECTION][cell[JV.PROP_FONT]];
|
|
|
} else {
|
|
|
sheetFont = cell[JV.PROP_FONT];
|
|
|
}
|
|
|
for (let i = 0; i < stylesObj.fonts.length; i++) {
|
|
|
- let font = stylesObj.fonts[i];
|
|
|
+ const font = stylesObj.fonts[i];
|
|
|
if (sheetFont) {
|
|
|
- // if (font[JV.FONT_PROPS[0]] === sheetFont[JV.FONT_PROPS[0]] && font.size === Math.round(sheetFont[JV.FONT_PROPS[1]] * 3 / 4)
|
|
|
- if (font[JV.FONT_PROPS[0]] === sheetFont[JV.FONT_PROPS[0]] && font.size === Math.floor(sheetFont[JV.FONT_PROPS[1]] * 3 / 4)
|
|
|
- && font[JV.FONT_PROPS[3]] === sheetFont[JV.FONT_PROPS[3]] && font[JV.FONT_PROPS[4]] === sheetFont[JV.FONT_PROPS[4]]
|
|
|
- && font[JV.FONT_PROPS[5]] === sheetFont[JV.FONT_PROPS[5]] ) {
|
|
|
+ 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)
|
|
|
+ && 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]]
|
|
|
+ && font[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]] === sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]]) {
|
|
|
hasFont = true;
|
|
|
rst = i;
|
|
|
break;
|
|
@@ -482,15 +476,15 @@ function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, ap
|
|
|
}
|
|
|
}
|
|
|
if (!hasFont) {
|
|
|
- let font = {};
|
|
|
- font[JV.FONT_PROPS[0]] = sheetFont[JV.FONT_PROPS[0]]; //font name
|
|
|
+ const font = {};
|
|
|
+ font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]] = sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]]; // font name
|
|
|
// font.size = Math.round(sheetFont[JV.FONT_PROPS[1]] * 3 / 4);
|
|
|
font.size = Math.floor(sheetFont[JV.FONT_PROPS[1]] * 3 / 4);
|
|
|
font.charset = 134;
|
|
|
- font.colorIdx = "8";
|
|
|
- font[JV.FONT_PROPS[3]] = sheetFont[JV.FONT_PROPS[3]]; //font bold
|
|
|
- font[JV.FONT_PROPS[4]] = sheetFont[JV.FONT_PROPS[4]]; //font italic
|
|
|
- font[JV.FONT_PROPS[5]] = sheetFont[JV.FONT_PROPS[5]]; //font underline
|
|
|
+ font.colorIdx = '8';
|
|
|
+ font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] = sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]]; // font bold
|
|
|
+ font[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]] = sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]]; // font italic
|
|
|
+ font[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]] = sheetFont[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]]; // font underline
|
|
|
stylesObj.fonts.push(font);
|
|
|
rst = stylesObj.fonts.length - 1;
|
|
|
}
|
|
@@ -928,13 +922,16 @@ module.exports = {
|
|
|
// let newName = '' + (new Date()).valueOf();
|
|
|
let newName = uuidV1();
|
|
|
|
|
|
+ // console.log('current path: ' + __dirname);
|
|
|
+ // const filePath = this.app.baseDir + '/app/public/download/';
|
|
|
+
|
|
|
zip.generateNodeStream({type:'nodebuffer',streamFiles:true})
|
|
|
- .pipe(fs.createWriteStream(__dirname.slice(0, __dirname.length - 21) + '/tmp/' + newName + '.xlsx'))
|
|
|
+ .pipe(fs.createWriteStream(__dirname.slice(0, __dirname.length - 13) + '/public/download/' + newName + '.xlsx'))
|
|
|
.on('finish', function () {
|
|
|
// JSZip generates a readable stream with a "end" event,
|
|
|
// but is piped here in a writable stream which emits a "finish" event.
|
|
|
console.log(newName + ".xlsx was written.");
|
|
|
- if (callback) callback(newName);
|
|
|
+ if (callback) callback(null, newName);
|
|
|
}
|
|
|
);
|
|
|
} else {
|