123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- /**
- * Created by Tony on 2017/4/1.
- */
- var JV = require('../rpt_component/Jpc_ValueDefine');
- var fs = require('fs');
- const dftHeadXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
- function writeContentTypes(sheets) {
- var 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"/>');
- rst.push('<Default Extension="xml" ContentType="application/xml"/>');
- rst.push('<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>');
- rst.push('<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>');
- rst.push('<Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>');
- for (var i = 0; i < sheets.length; i++) {
- rst.push('<Override PartName="/xl/worksheets/' + sheets[i].sheetName + '.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>')
- }
- rst.push('<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>');
- rst.push('</Types>');
- return rst;
- }
- function writeRootRels(){
- var 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"/>');
- rst.push('<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>');
- rst.push('<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>');
- rst.push('</Relationships>');
- return rst;
- }
- function writeApp(sheets) {
- var 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>');
- rst.push('<DocSecurity>0</DocSecurity>');
- rst.push('<ScaleCrop>false</ScaleCrop>');
- rst.push('<HeadingPairs>');
- rst.push('<vt:vector size="2" baseType="variant">');
- rst.push('<vt:variant><vt:lpstr>¹¤×÷±í</vt:lpstr></vt:variant>');
- rst.push('<vt:variant><vt:i4>' + sheets.length + '</vt:i4></vt:variant>');
- rst.push('</vt:vector>');
- rst.push('</HeadingPairs>');
- rst.push('<TitlesOfParts>');
- rst.push('<vt:vector size="' + sheets.length + '" baseType="lpstr">');
- for (var i = 0; i < sheets.length; i++) {
- rst.push('<vt:lpstr>' + sheets[i].sheetName + '</vt:lpstr>')
- }
- rst.push('</vt:vector>');
- rst.push('</TitlesOfParts>');
- rst.push('<Company>SmartCost</Company>');
- rst.push('<LinksUpToDate>false</LinksUpToDate>');
- rst.push('<SharedDoc>false</SharedDoc>');
- rst.push('<HyperlinksChanged>false</HyperlinksChanged>');
- rst.push('<AppVersion>12.0000</AppVersion>');
- //rst.push('');
- rst.push('</Properties>');
- return rst;
- }
- function writeCore() {
- var rst = [];
- p_fillZero = function(val){
- var rst = val;
- if (val < 10) {
- rst = '0' + val;
- }
- return rst;
- };
- rst.push(dftHeadXml + '\r\n');
- 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>');
- var dt = new Date(), dtStr = dt.getFullYear() + '-' + p_fillZero(dt.getMonth()) + '-' + 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){
- var 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"/>');
- rst.push('<workbookPr defaultThemeVersion="124226"/>');
- rst.push('<bookViews><workbookView xWindow="360" yWindow="345" windowWidth="14655" windowHeight="4305"/></bookViews>');
- rst.push('<sheets>');
- for (var i = 0; i < sheets.length; i++) {
- rst.push('<sheet name="' + sheets[i].sheetName + '" sheetId="' + (i + 1) + 'r:id="rId' + (i + 1) + '1"/>')
- }
- rst.push('</sheets>');
- rst.push('<calcPr calcId="124519"/>');
- //rst.push('');
- rst.push('</workbook>');
- return rst;
- }
- function writeXlRels(sheets){
- var rst = [], idx = 1;
- rst.push(dftHeadXml + '\r\n');
- rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
- for (var i = 0; i < sheets.length; i++) {
- rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/' + sheets[i].sheetName + '.xml/>"')
- idx++;
- }
- rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>');
- idx++;
- rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>');
- idx++;
- rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/>');
- //rst.push('');
- rst.push('</Relationships>');
- return rst;
- }
- function writeTheme(){
- var rst = fs.readFileSync('./excel_base_files/theme1.xml', 'utf8', 'r');
- return rst;
- }
- function writeStyles(pageData){
- //
- }
- function writeSharedString(pageData){
- //
- }
- function writeSheets(pageData){
- var rst = [], sharedStrList = [];
- for (var i = 0; i < pageData.items.length; i++) {
- //
- }
- }
- function writeSheet(sheetData, sharedStrList){
- var rst = [], x = [0], y = [0], headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- private_pre_analyze_pos = function(){
- var cell, pos;
- for (var i = 0; i < sheetData.cells.length; i++) {
- cell = sheetData.cells[i];
- pos = cell[JV.PROP_AREA][JV.PROP_LEFT];
- if (x.indexOf(pos) < 0) x.push(pos);
- pos = cell[JV.PROP_AREA][JV.PROP_RIGHT];
- if (x.indexOf(pos) < 0) x.push(pos);
- pos = cell[JV.PROP_AREA][JV.PROP_TOP];
- if (y.indexOf(pos) < 0) y.push(pos);
- pos = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
- if (y.indexOf(pos) < 0) y.push(pos);
- }
- x.sort();
- y.sort();
- };
- private_getCellIdxStr = function(idx){
- var rst = 'A', prefix = '', tmpIdx = idx;
- if (tmpIdx > 26) {
- var ti = Math.floor(tmpIdx / 26), tj = tmpIdx % 26;
- if (ti < 26) {
- //
- } else {
- prefix = ''
- }
- } else {
- //
- }
- //if (idx < )
- };
- private_getStrIdx = function(val) {
- //
- };
- private_pre_analyze_pos();
- rst.push(dftHeadXml + '\r\n');
- rst.push('<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">');
- rst.push('<dimension ref="A1:U4332"/>');
- rst.push('');
- rst.push('');
- rst.push('');
- rst.push('');
- rst.push('');
- rst.push('');
- rst.push('');
- rst.push('');
- rst.push('');
- rst.push('');
- //rst.push('');
- return rst;
- }
- module.exports = {
- exportExcel: function (pageData, options) {
- var rptOptions = (options || {singlePage: false, fileName: 'report'});
- }
- }
|