提交 2911cb67 编写于 作者: NoSubject's avatar NoSubject

Merge branch 'cherry-pick-50223aa3' into 'master'

修复导入模型下载模板样式的问题,并增加下载模板的数据有效性校验

See merge request o2oa/o2oa!2603
......@@ -62,6 +62,12 @@ MWF.xApplication.Template.LP={
"close": "Close",
"max": "Maximize",
"restore": "Restore"
},
"excelUtils": {
"promptTitle": "Input prompt",
"prompt": "Please select a value from the dropdown list",
"errorTitle": "Input error",
"error": "The value you entered is not in the list"
}
}
MWF.xApplication.Template["lp."+o2.language] = MWF.xApplication.Template.LP
\ No newline at end of file
......@@ -62,6 +62,12 @@ MWF.xApplication.Template.LP={
"close": "Cerrar",
"max": "Maximizar",
"restore": "Restaurar"
},
"excelUtils": {
"promptTitle": "Consejos de entrada",
"prompt": "Por favor, seleccione un valor de la lista desplegable",
"errorTitle": "Error de entrada",
"error": "El valor que ingresaste no está en la lista"
}
}
MWF.xApplication.Template["lp."+o2.language] = MWF.xApplication.Template.LP
\ No newline at end of file
......@@ -72,5 +72,12 @@ o2.xApplication.Template.LP = {
"close": "关闭",
"max": "最大化",
"restore": "还原"
},
"excelUtils": {
"promptTitle": '输入提示',
"prompt": '请从下拉列表中选择一个值',
"errorTitle": '输入错误',
"error": '你输入的值不在列表中'
}
};
\ No newline at end of file
......@@ -121,39 +121,53 @@ MWF.xApplication.Template.utils.ExcelUtils = new Class({
// array.push([ "张三","男","大学本科","计算机","2001-1-2","2019-9-2" ]);
// array.push([ "李四","男","大学专科","数学","1998-1-2","2018-9-2" ]);
// this.exportToExcel(array, "导出数据"+(new Date).format("db"));
if( !MWF.xApplication.Template.LP ){
MWF.xDesktop.requireApp("Template", "lp." + MWF.language, null, false);
}
this._loadExportResource(function (){
var workbook = new ExcelJS.Workbook();
var sheet = workbook.addWorksheet('sheet1');
var sheet = workbook.addWorksheet('Sheet1');
//sheet.properties.defaultRowHeight = 25;
var titleArray = array[0];
this.appendDataToSheet(sheet, array, colWidthArr, dateIndexArray, numberIndexArray);
workbook.xlsx.writeBuffer().then(function(buffer){
var blob = new Blob([buffer]);
this._openDownloadDialog(blob, fileName + ".xlsx", callback);
}.bind(this));
}.bind(this))
var hasValidation = false;
var ps = titleArray.map(function( title ){
if( o2.typeOf(title) === 'object' && title.options ){
hasValidation = true;
return title.options;
}
return null;
});
if(hasValidation){
Promise.all(ps).then(function(args){
for( var i=0; i<args.length; i++ ){
if(args[i])titleArray[i].optionsValue = args[i];
}
this.setDataValidation(workbook, sheet, titleArray);
this.downloadExcel(workbook, fileName, callback);
}.bind(this));
}else{
this.downloadExcel(workbook, fileName, callback);
}
}.bind(this));
},
downloadExcel: function(workbook, fileName, callback){
workbook.xlsx.writeBuffer().then(function(buffer){
var blob = new Blob([buffer]);
this._openDownloadDialog(blob, fileName + ".xlsx", callback);
}.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.value = o2.typeOf(title) === 'object' ? title.text : title;
cell.font = { name: '宋体', family: 4, size: 12, bold: true };
// cell.fill = {
// type: 'pattern',
// pattern:'solid',
// fgColor:{argb:'FFFFFF'}
// };
// cell.fill = { type: 'pattern', pattern:'solid', fgColor:{argb:'FFFFFF'} };
cell.alignment = { vertical: 'middle', horizontal: 'center', wrapText: true };
});
......@@ -171,6 +185,42 @@ MWF.xApplication.Template.utils.ExcelUtils = new Class({
});
});
},
setDataValidation: function (workbook, dataSheet, titleArray){
var validationSheet = workbook.addWorksheet('Validation');
validationSheet.state = 'hidden'; //hidden 隐藏 veryHidden 从“隐藏/取消隐藏”对话框中隐藏工作表
var colIndex = 0;
titleArray.each(function(title, i){
var optionsValue = o2.typeOf(title) === 'object' && title.optionsValue;
if( !optionsValue )return;
colIndex++;
var optionsArray = o2.typeOf(optionsValue) === "array" ? optionsValue : [optionsValue];
validationSheet.getColumn(colIndex).values = optionsArray;
var colName = this.index2ColName(colIndex-1);
var dataValidation = {
type: 'list',
allowBlank: true,
showErrorMessage: true,
showInputMessage: false,
formulae: ['=Validation!$'+colName+'$1:$'+colName+'$'+optionsArray.length], // 这里引用Validation Sheet的内容 '=Validation!A1:A3'
//formulae: ['"'+optionsArray.join(",")+'"'],
promptTitle: MWF.xApplication.Template.LP.excelUtils.promptTitle,
prompt: MWF.xApplication.Template.LP.excelUtils.prompt,
errorTitle: MWF.xApplication.Template.LP.excelUtils.errorTitle,
error: MWF.xApplication.Template.LP.excelUtils.error
};
var dataColName = this.index2ColName(i);
for (var rowIndex = 2; rowIndex <= 3000; rowIndex++) {
const cell = dataSheet.getCell(dataColName+rowIndex);
cell.dataValidation = dataValidation;
}
}.bind(this));
},
// exportToExcel2: function(array, fileName, colWidthArr, dateIndexArray, numberIndexArray, callback){
// // var array = [["姓名","性别","学历","专业","出生日期","毕业日期"]];
// // array.push([ "张三","男","大学本科","计算机","2001-1-2","2019-9-2" ]);
......
......@@ -155,7 +155,7 @@ MWF.xApplication.query.ImporterDesigner.LP = {
"valueScriptWorkNote": "如果导入流程work,系统生成的工作数据",
"idPathNote": "当导入自建表数据时,字段路径为'id'表示更新原有记录。",
"excelSelectedOption": "excel列可选项",
"selectedOptionScript": "可选项脚本"
"selectedOptionScript": "可选项脚本,返回数组"
},
"formToolbar":{
"save": "保存",
......
......@@ -762,13 +762,22 @@ MWF.xApplication.query.Query.Importer = MWF.QImporter = new Class(
if( !this.importerJson ){
this.getImporterJSON( function () {
exportTo();
}.bind(this))
}.bind(this));
}else{
exportTo();
}
},
downloadTemplate: function(fileName, callback){
if( this.Macro ){
this._downloadTemplate(fileName, callback);
}else{
this.loadMacro(function (){
this._downloadTemplate(fileName, callback);
}.bind(this));
}
},
_downloadTemplate: function(fileName, callback){
if( !this.excelUtils ){
this.excelUtils = new MWF.xApplication.query.Query.Importer.ExcelUtils( this );
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册