Explorar el Código

报表导出日期格式控制

zhuth hace 6 años
padre
commit
8978dd423e
Se han modificado 1 ficheros con 7 adiciones y 3 borrados
  1. 7 3
      src/utils/exportor.js

+ 7 - 3
src/utils/exportor.js

@@ -17,7 +17,7 @@ let Base64 = require('./base64.js');
     tmpStyleXML = '<Styles>'
         + '<Style ss:ID="Bold"><Font ss:Bold="1"/></Style>'
         + '<Style ss:ID="Currency"><NumberFormat ss:Format="Currency"></NumberFormat></Style>'
-        + '<Style ss:ID="Date"><NumberFormat ss:Format="Medium Date"></NumberFormat></Style>'
+        + '<Style ss:ID="Date"><NumberFormat ss:Format="yyyy-mm-dd"></NumberFormat></Style>'
         + '<Style ss:ID="Center"><Alignment ss:Horizontal="Center" ss:Vertical="Center"/></Style>'
     + '</Styles>',
     tmplWorksheetXML = '<Worksheet ss:Name="{nameWS}"><Table>{columnWidth}{rows}</Table></Worksheet>',
@@ -25,6 +25,9 @@ let Base64 = require('./base64.js');
     tmplTableHeaderXML = '<Row><Cell ss:StyleID="Center" ss:MergeAcross="{columnCount}"><Data ss:Type="String">{header}</Data></Cell></Row>',
     tmplRowXML = '<Row>{cells}</Row>',
     tmplCellXML = '<Cell{attributeStyleID}{attributeFormula}><Data ss:Type="{nameType}">{data}</Data></Cell>',
+    _defaultStyleIDs = {
+        DateTime: 'Date',
+    },
     _format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) },
     _export = function(workbookXML, wbname) {
         let link = document.createElement("A");
@@ -114,7 +117,7 @@ let Base64 = require('./base64.js');
     };
 
     Exportor.prototype.generateRowsXML = function(columns, rows) {
-        let cols = columns.map(c => ({ type: c.type, name: c.name }));
+        let cols = columns.map(c => ({ type: c.type, name: c.name, styleID: c.styleID }));
         let str = '';
         for(let i = 0; i < rows.length; i++) {
             let r = rows[i];
@@ -122,7 +125,8 @@ let Base64 = require('./base64.js');
             for(let j = 0; j < cols.length; j++) {
                 cells.push({
                     type: cols[j].type,
-                    value: r[j]
+                    value: r[j],
+                    styleID: cols[j].styleID || _defaultStyleIDs[cols[j].type]
                 });
             }
             let ctx = {