提交 01f88e5b 编写于 作者: U unknown

导出功能优化

上级 8d313320
o2.xApplication.Template = o2.xApplication.Template || {};
o2.xApplication.Template.LP = {
MWF.xApplication = MWF.xApplication || {};
MWF.xApplication.Template = MWF.xApplication.Template || {};
MWF.xApplication.Template.LP={
"title": "Template",
"delete": "Delete",
"deleteDocumentTitle": "Delete Confirmation",
......@@ -8,69 +9,59 @@ o2.xApplication.Template.LP = {
"createSuccess": "Created successfully",
"updateSuccess": "Update successful",
"inputName": "Please enter a name",
"dateFormatMonth": "%Y-%m",
"dateFormatOnlyMonth": "%m",
"dateFormatDay": "%Y-%m-%d",
"dateFormatMonthDayLocal": "%m-%d",
"dateFormat": "db",
"month": "month",
"today": "Today",
"day": "day",
"cancel": "Cancel",
"ok": "OK",
"name": "Name",
"create_cancel_title": "Cancel New Confirmation",
"create_cancel": "Are you sure you want to cancel the new creation?",
"index": {
},
"index": {},
"explorer": {
"returnText": "Return to home page",
"pageJumperText": "Enter the page number and press enter to jump",
"prePage": "Previous Page",
"nextPage": "Next Page"
},
"MDomItem": {
"emptyTip": "{text} cannot be empty",
"emailTip":"Please enter an email in the correct format",
"urlTip":"Please enter a valid URL",
"phoneNumberTip" :"Please enter the correct phone number",
"dateTip":"Please enter a valid date",
"dateISOTip":"Please enter a valid date.",
"numberTip":"Please enter a valid number",
"digitsTip":"Only integers can be entered",
"maxlengthTip":"The length cannot exceed {n}",
"minlengthTip":"The length cannot be less than {n}",
"rangelengthTip":"The length cannot be between {n0} and {n1}",
"rangeTip":"Please enter a value between {n0} and {n1}",
"minTip":"Please enter a minimum value of {n}",
"maxTip":"Please enter a value up to {n}",
"extensionTip":"Please upload an attachment in {text} format",
"defaultTip" :"Please enter the correct {text}",
"emailTip": "Please enter an email in the correct format",
"urlTip": "Please enter a valid URL",
"phoneNumberTip": "Please enter the correct phone number",
"dateTip": "Please enter a valid date",
"dateISOTip": "Please enter a valid date.",
"numberTip": "Please enter a valid number",
"digitsTip": "Only integers can be entered",
"maxlengthTip": "The length cannot exceed {n}",
"minlengthTip": "The length cannot be less than {n}",
"rangelengthTip": "The length cannot be between {n0} and {n1}",
"rangeTip": "Please enter a value between {n0} and {n1}",
"minTip": "Please enter a minimum value of {n}",
"maxTip": "Please enter a value up to {n}",
"extensionTip": "Please upload an attachment in {text} format",
"defaultTip": "Please enter the correct {text}",
"selectTip": "Please select {text} first",
"defaultOption": "Please choose",
"setPicture": "Set Picture",
"uploadPictureNotice": "Please upload a picture first",
"selectCoundPicture": "Select Cloud File Picture"
},
"MGrid": {
"sequence": "Sequence Number",
"add": "Add",
"delete": "Delete",
"addMaxLimitText": "You can only add up to {count} items"
},
"MPopupForm": {
"close": "Close",
"max": "Maximize",
"restore": "Restore"
}
};
\ No newline at end of file
}
MWF.xApplication.Template["lp."+o2.language] = MWF.xApplication.Template.LP
\ No newline at end of file
o2.xApplication.Template = o2.xApplication.Template || {};
o2.xApplication.Template.LP = {
MWF.xApplication = MWF.xApplication || {};
MWF.xApplication.Template = MWF.xApplication.Template || {};
MWF.xApplication.Template.LP={
"title": "Plantilla",
"delete" : "Eliminar",
"delete": "Eliminar",
"deleteDocumentTitle": "Confirmación para eliminar",
"deleteDocument": "¿Está seguro que desea eliminar esta información?",
"deleteDocumentOK": "Eliminado con éxito",
"createSuccess" : "Creado con éxito",
"updateSuccess" : "Actualizado con éxito",
"inputName" : "Ingrese un nombre",
"createSuccess": "Creado con éxito",
"updateSuccess": "Actualizado con éxito",
"inputName": "Ingrese un nombre",
"dateFormatMonth": "%Y年%m月",
"dateFormatOnlyMonth": "%m",
"dateFormatDay": "%Y-%m-%d",
"dateFormatMonthDayLocal": "%d de %B",
"dateFormat": "db",
"month" : "mes",
"today" : "hoy",
"day" : "día",
"cancel" : "Cancelar",
"ok" : "Aceptar",
"name" : "Nombre",
"month": "mes",
"today": "hoy",
"day": "día",
"cancel": "Cancelar",
"ok": "Aceptar",
"name": "Nombre",
"create_cancel_title": "Confirmación para cancelar la creación",
"create_cancel": "¿Está seguro que desea cancelar la creación?",
"index" : {
},
"explorer" : {
"returnText" : "Volver a la página principal",
"index": {},
"explorer": {
"returnText": "Volver a la página principal",
"pageJumperText": "Ingrese el número de página y presione Enter para saltar",
"prePage" : "Página anterior",
"prePage": "Página anterior",
"nextPage": "Página siguiente"
},
"MDomItem" : {
"MDomItem": {
"emptyTip": "{text} no puede estar vacío",
"emailTip":"Ingrese un correo electrónico con formato válido",
"urlTip":"Ingrese una URL válida",
"phoneNumberTip" :"Ingrese un número de teléfono móvil válido",
"dateTip":"Ingrese una fecha válida",
"dateISOTip":"Ingrese una fecha válida.",
"numberTip":"Ingrese un valor numérico válido",
"digitsTip":"Solo se permiten números enteros",
"maxlengthTip":"La longitud no puede ser mayor a {n}",
"minlengthTip":"La longitud no puede ser menor a {n}",
"rangelengthTip":"La longitud debe estar entre {n0} y {n1}",
"rangeTip":"Ingrese un valor entre {n0} y {n1}",
"minTip":"Ingrese un valor mínimo de {n}",
"maxTip":"Ingrese un valor máximo de {n}",
"extensionTip":"Por favor, cargue un archivo de {text}",
"defaultTip" :"Ingrese un valor válido para {text}",
"emailTip": "Ingrese un correo electrónico con formato válido",
"urlTip": "Ingrese una URL válida",
"phoneNumberTip": "Ingrese un número de teléfono móvil válido",
"dateTip": "Ingrese una fecha válida",
"dateISOTip": "Ingrese una fecha válida.",
"numberTip": "Ingrese un valor numérico válido",
"digitsTip": "Solo se permiten números enteros",
"maxlengthTip": "La longitud no puede ser mayor a {n}",
"minlengthTip": "La longitud no puede ser menor a {n}",
"rangelengthTip": "La longitud debe estar entre {n0} y {n1}",
"rangeTip": "Ingrese un valor entre {n0} y {n1}",
"minTip": "Ingrese un valor mínimo de {n}",
"maxTip": "Ingrese un valor máximo de {n}",
"extensionTip": "Por favor, cargue un archivo de {text}",
"defaultTip": "Ingrese un valor válido para {text}",
"selectTip": "Seleccione primero {text}",
"defaultOption": "Seleccione una opción",
"setPicture": "Establecer imagen",
"uploadPictureNotice" : "Cargue primero una imagen",
"uploadPictureNotice": "Cargue primero una imagen",
"selectCoundPicture": "Seleccionar imagen de archivos en la nube"
},
"MGrid" : {
"sequence" : "Secuencia",
"MGrid": {
"sequence": "Secuencia",
"add": "Agregar",
"delete": "Eliminar",
"addMaxLimitText": "Solo se pueden agregar hasta {count} elementos"
},
"MPopupForm" : {
"MPopupForm": {
"close": "Cerrar",
"max": "Maximizar",
"restore": "Restaurar"
}
};
\ No newline at end of file
}
MWF.xApplication.Template["lp."+o2.language] = MWF.xApplication.Template.LP
\ No newline at end of file
......@@ -26,19 +26,6 @@ MWF.xApplication.Template.utils.ExcelUtils = new Class({
}
}
},
_loadResource : function( callback ){
if( !window.XLSX || !window.xlsxUtils ){
var uri = "../x_component_Template/framework/xlsx/xlsx.full.js";
var uri2 = "../x_component_Template/framework/xlsx/xlsxUtils.js";
COMMON.AjaxModule.load(uri, function(){
COMMON.AjaxModule.load(uri2, function(){
callback();
}.bind(this))
}.bind(this))
}else{
callback();
}
},
_openDownloadDialog: function(url, saveName, callback){
/**
* 通用的打开下载对话框方法,没有测试过具体兼容性
......@@ -115,102 +102,184 @@ MWF.xApplication.Template.utils.ExcelUtils = new Class({
var fileNode = uploadFileAreaNode.getFirst();
fileNode.click();
},
_loadExportResource : function( callback ){
if( !window.ExcelJS ){
var uri = "../o2_lib/exceljs/babel-polyfill-6.2.js";
var uri2 = "../o2_lib/exceljs/exceljs.min.js";
COMMON.AjaxModule.load(uri, function(){
COMMON.AjaxModule.load(uri2, function(){
callback();
}.bind(this))
}.bind(this))
}else{
callback();
}
},
exportToExcel : function(array, fileName, colWidthArr, dateIndexArray, numberIndexArray, callback){
debugger;
// var array = [["姓名","性别","学历","专业","出生日期","毕业日期"]];
// array.push([ "张三","男","大学本科","计算机","2001-1-2","2019-9-2" ]);
// array.push([ "李四","男","大学专科","数学","1998-1-2","2018-9-2" ]);
// this.exportToExcel(array, "导出数据"+(new Date).format("db"));
this._loadResource( function(){
var data = window.xlsxUtils.format2Sheet(array, 0, 0, null);//偏移3行按keyMap顺序转换
var wb = window.xlsxUtils.format2WB(data, "sheet1", undefined);
var wopts = { bookType: 'xlsx', bookSST: false, type: 'binary' };
debugger;
var dataInfo = wb.Sheets[wb.SheetNames[0]];
this._loadExportResource(function (){
var workbook = new ExcelJS.Workbook();
var sheet = workbook.addWorksheet('sheet1');
//sheet.properties.defaultRowHeight = 25;
var widthArray = [];
array[0].each( function( v, i ){ //设置标题行样式
this.appendDataToSheet(sheet, array, colWidthArr, dateIndexArray, numberIndexArray);
if( !colWidthArr )widthArray.push( {wpx: 100} );
// var at = String.fromCharCode(97 + i).toUpperCase();
var at = this.index2ColName(i);
var di = dataInfo[at+"1"];
// di.v = v;
// di.t = "s";
di.s = { //设置副标题样式
font: {
//name: '宋体',
sz: 12,
color: {rgb: "#FFFF0000"},
bold: true,
italic: false,
underline: false
},
alignment: {
horizontal: "center" ,
vertical: "center"
}
};
workbook.xlsx.writeBuffer().then(function(buffer){
var blob = new Blob([buffer]);
this._openDownloadDialog(blob, fileName + ".xlsx", callback);
}.bind(this));
if( dateIndexArray && dateIndexArray.length ){
dateIndexArray.each( function( value, index ){
dateIndexArray[ index ] = this.index2ColName(value);
}.bind(this))
}
if( numberIndexArray && numberIndexArray.length ){
numberIndexArray.each( function( value, index ){
numberIndexArray[ index ] = this.index2ColName(value);
}.bind(this))
}.bind(this))
},
appendDataToSheet: function (sheet, array, colWidthArr, dateIndexArray, numberIndexArray){
var titleRow = sheet.getRow(1);
var titleArray = array.shift();
titleArray.each( function( title, i ){
var value, options;
if( o2.typeOf(title) === 'object' ){
value = title.text;
options = title.options;
}else{
value = title;
}
sheet.getColumn(i+1).width = colWidthArr[i] ? (colWidthArr[i] / 10) : 20;
var cell = titleRow.getCell(i+1);
cell.value = value;
cell.font = { name: '宋体', family: 4, size: 12, bold: true };
// cell.fill = {
// type: 'pattern',
// pattern:'solid',
// fgColor:{argb:'FFFFFF'}
// };
cell.alignment = { vertical: 'middle', horizontal: 'center', wrapText: true };
});
var typeFlag = ( dateIndexArray && dateIndexArray.length ) || ( numberIndexArray && numberIndexArray.length );
for( var key in dataInfo ){
//设置所有样式,wrapText=true 后 /n会被换行
if( key.substr(0, 1) !== "!" ){
var di = dataInfo[key];
if( !di.s )di.s = {};
if( !di.s.alignment )di.s.alignment = {};
di.s.alignment.wrapText = true;
if( typeFlag ){
var colName = key.replace(/\d+/g,''); //清除数字
var rowNum = key.replace( colName, '');
if( rowNum > 1 ){
if( dateIndexArray && dateIndexArray.length && dateIndexArray.contains( colName ) ){
//di.s.numFmt = "yyyy-mm-dd HH:MM:SS"; //日期列 两种方式都可以
di.z = 'yyyy-mm-dd HH:MM:SS'; //日期列
}
if( numberIndexArray && numberIndexArray.length && numberIndexArray.contains( colName ) ){
di.s.alignment.wrapText = false;
di.t = 'n'; //数字类型
}
}
}
array.each(function( contentArray, i ){
var contentRow = sheet.getRow(i+2);
contentArray.each(function( content, j ){
var cell = contentRow.getCell(j+1);
cell.value = content;
cell.font = { name: '宋体', family: 4, size: 12, bold: false };
if( (dateIndexArray || []).contains( j ) ){
cell.numFmt = 'yyyy-mm-dd HH:MM:SS';
}
var isNumber = ( numberIndexArray||[] ).contains( j );
cell.alignment = { vertical: 'middle', horizontal: 'center', wrapText: !isNumber };
});
});
},
// exportToExcel2: function(array, fileName, colWidthArr, dateIndexArray, numberIndexArray, callback){
// // var array = [["姓名","性别","学历","专业","出生日期","毕业日期"]];
// // array.push([ "张三","男","大学本科","计算机","2001-1-2","2019-9-2" ]);
// // array.push([ "李四","男","大学专科","数学","1998-1-2","2018-9-2" ]);
// // this.exportToExcel(array, "导出数据"+(new Date).format("db"));
// this._loadExportResource( function(){
// var data = window.xlsxUtils.format2Sheet(array, 0, 0, null);//偏移3行按keyMap顺序转换
// var wb = window.xlsxUtils.format2WB(data, "sheet1", undefined);
// var wopts = { bookType: 'xlsx', bookSST: false, type: 'binary' };
// debugger;
// var dataInfo = wb.Sheets[wb.SheetNames[0]];
//
// var widthArray = [];
// array[0].each( function( v, i ){ //设置标题行样式
//
// if( !colWidthArr )widthArray.push( {wpx: 100} );
//
// // var at = String.fromCharCode(97 + i).toUpperCase();
// var at = this.index2ColName(i);
// var di = dataInfo[at+"1"];
// // di.v = v;
// // di.t = "s";
// di.s = { //设置副标题样式
// font: {
// //name: '宋体',
// sz: 12,
// color: {rgb: "#FFFF0000"},
// bold: true,
// italic: false,
// underline: false
// },
// alignment: {
// horizontal: "center" ,
// vertical: "center"
// }
// };
// }.bind(this));
//
// if( dateIndexArray && dateIndexArray.length ){
// dateIndexArray.each( function( value, index ){
// dateIndexArray[ index ] = this.index2ColName(value);
// }.bind(this))
// }
//
// if( numberIndexArray && numberIndexArray.length ){
// numberIndexArray.each( function( value, index ){
// numberIndexArray[ index ] = this.index2ColName(value);
// }.bind(this))
// }
//
// var typeFlag = ( dateIndexArray && dateIndexArray.length ) || ( numberIndexArray && numberIndexArray.length );
//
// for( var key in dataInfo ){
// //设置所有样式,wrapText=true 后 /n会被换行
// if( key.substr(0, 1) !== "!" ){
// var di = dataInfo[key];
// if( !di.s )di.s = {};
// if( !di.s.alignment )di.s.alignment = {};
// di.s.alignment.wrapText = true;
//
// if( typeFlag ){
//
// var colName = key.replace(/\d+/g,''); //清除数字
// var rowNum = key.replace( colName, '');
//
// if( rowNum > 1 ){
// if( dateIndexArray && dateIndexArray.length && dateIndexArray.contains( colName ) ){
// //di.s.numFmt = "yyyy-mm-dd HH:MM:SS"; //日期列 两种方式都可以
// di.z = 'yyyy-mm-dd HH:MM:SS'; //日期列
// }
// if( numberIndexArray && numberIndexArray.length && numberIndexArray.contains( colName ) ){
// di.s.alignment.wrapText = false;
// di.t = 'n'; //数字类型
// }
// }
//
// }
// }
//
// }
//
// if( colWidthArr ){
// colWidthArr.each( function (w) {
// widthArray.push( {wpx: w} );
// })
// }
// dataInfo['!cols'] = widthArray; //列宽度
//
// this._openDownloadDialog(window.xlsxUtils.format2Blob(wb), fileName +".xlsx", callback);
// }.bind(this))
// },
}
if( colWidthArr ){
colWidthArr.each( function (w) {
widthArray.push( {wpx: w} );
})
}
dataInfo['!cols'] = widthArray; //列宽度
this._openDownloadDialog(window.xlsxUtils.format2Blob(wb), fileName +".xlsx", callback);
}.bind(this))
_loadImportResource : function( callback ){
if( !window.XLSX || !window.xlsxUtils ){
var uri = "../x_component_Template/framework/xlsx/xlsx.full.js";
var uri2 = "../x_component_Template/framework/xlsx/xlsxUtils.js";
COMMON.AjaxModule.load(uri, function(){
COMMON.AjaxModule.load(uri2, function(){
callback();
}.bind(this))
}.bind(this))
}else{
callback();
}
},
importFromExcel : function( file, callback, dateColArray ){
debugger;
var _self = this;
this._loadResource( function(){
this._loadImportResource( function(){
var reader = new FileReader();
var workbook, data;
reader.onload = function (e) {
......
......@@ -137,6 +137,8 @@
</div>
</div>
<div style="background-color: #EEE; height:24px; line-height: 24px; text-align: center; font-weight: bold">{{$.lp.excelSelectedOption}}</div>
<div class="MWFFormulaArea" name="optionScript" title="{{$.lp.selectedOptionScript}}"></div>
<!-- <div style="display:text{($.vtype=='process')?'block':'none'}" id="text{$.pid}processFieldProperty" class="text{$.vid}processFieldProperty">-->
<!-- <div style="background-color: #EEE; height:24px; line-height: 24px; text-align: center; font-weight: bold">{{$.lp.workProperty}}</div>-->
<!-- <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">-->
......
......@@ -133,7 +133,9 @@ MWF.xApplication.query.ImporterDesigner.LP={
"valueScriptDocumentNote": "If you import a CMS document, the document data generated by the system",
"valueScriptWorkNote": "If importing process Work, the system generated work data",
"selectField": "Select Column/Field",
"idPathNote": "When importing self created table data, a field path of 'id' indicates updating the original record."
"idPathNote": "When importing self created table data, a field path of 'id' indicates updating the original record.",
"excelSelectedOption": "excel column options ",
"selectedOptionScript": "Optional script"
},
"formToolbar": {
"save": "Save",
......
......@@ -133,7 +133,11 @@ MWF.xApplication.query.ImporterDesigner.LP={
"valueScriptDataNote": "Datos empresariales generados por el sistema según la configuración",
"valueScriptDocumentNote": "Si importa documentos CMS, se generarán los datos del documento por el sistema",
"valueScriptWorkNote": "Si importa trabajos de proceso, se generarán los datos de trabajo por el sistema",
"idPathNote": "Al importar los datos de la tabla autoconstruida, la ruta de campo 'id' significa actualizar el registro original."
"idPathNote": "Al importar los datos de la tabla autoconstruida, la ruta de campo 'id' significa actualizar el registro original.",
"excelSelectedOption ": " columna excel opcional ",
"selectedOptionScript ": " script opcional",
"excelSelectedOption": "La columna Excel es opcional",
"selectedOptionScript": "Guión opcional"
},
"formToolbar": {
"save": "Guardar",
......
......@@ -153,7 +153,9 @@ MWF.xApplication.query.ImporterDesigner.LP = {
"valueScriptDataNote": "系统根据配置生成的业务数据",
"valueScriptDocumentNote": "如果导入CMS文档,系统生成的文档数据",
"valueScriptWorkNote": "如果导入流程work,系统生成的工作数据",
"idPathNote": "当导入自建表数据时,字段路径为'id'表示更新原有记录。"
"idPathNote": "当导入自建表数据时,字段路径为'id'表示更新原有记录。",
"excelSelectedOption": "excel列可选项",
"selectedOptionScript": "可选项脚本"
},
"formToolbar":{
"save": "保存",
......
......@@ -805,11 +805,15 @@ MWF.xApplication.query.Query.Importer = MWF.QImporter = new Class(
return title;
},
getTitleArray: function(){
var titleArray = [];
this.json.data.columnList.each( function (columnJson, i) {
titleArray.push( columnJson.displayName );
return this.json.data.columnList.map( function (columnJson, i) {
var obj = {
text: columnJson.displayName
};
if( columnJson.optionScript ){
obj.options = this.Macro.exec(columnJson.optionScript, this);
}
return obj;
}.bind(this));
return titleArray;
},
getColWidthArray : function(){
var colWidthArr = [];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册