前提 引入excel.min.js文件
1 代码
var sheet1 = data.listexamscore
sheet1 = myExcel.filterExportData(sheet1,[
'username',
'planname',
'examname',
'examtype',
'passscore',
'score',
'ispass'
])
sheet1.unshift({username:"用户名",planname:"计划名",examname:"考试名称",examtype:"考试类型",passscore:"及格分",score:"分数",ispass:"是否及格"})
//设置sheet的开头名
sheet1.unshift({username:examTypeName+'-'+planNameTemp+'-'+'成绩统计'})
var sheet2 = data.listpie
sheet2 = myExcel.filterExportData(sheet2,[
'count',
'ispasscount',
'isnotpasscount',
'ispassrate',
'isnotpassrate'
])
sheet2.unshift({count:"总数",ispasscount:"及格人数",isnotpasscount:"不及格人数",ispassrate:"及格率",isnotpassrate:"不及格率"})
sheet2.unshift({count:examTypeName+'-'+planNameTemp+'-'+'及格占比'})
var sheet3 = data.listhistogram
sheet3 = myExcel.filterExportData(sheet3,[
'totalcount',
'lowscorecount',
'middlescorecount',
'goodscorecount',
'highscorecount',
'excellentscorecount'
])
sheet3.unshift({totalcount:"总人数",lowscorecount:"60以下",middlescorecount:"60-70",goodscorecount:"71-80",highscorecount:"81-90",excellentscorecount:"91-100"})
sheet3.unshift({totalcount:examTypeName+'-'+planNameTemp+'-'+'分数分布'})
var sheet4 = data.listray
sheet4 = myExcel.filterExportData(sheet4,[
'maxscore',
'minscore',
'avgscore'
])
sheet4.unshift({maxscore:"最高分",minscore:"最低分",avgscore:"平均分"})
sheet4.unshift({maxscore:examTypeName+'-'+planNameTemp+'-'+'最值分析'})
//设置合并sheet页的第一行的A到D列
var mergeConf = myExcel.makeMergeConfig([
['A1','D1']
])
//设置sheet页的页名
myExcel.exportExcel({
'成绩统计': sheet1,
'及格占比': sheet2,
'分数分布': sheet3,
'最值分析': sheet4
//设置导出的文件名,文件类型
},examTypeName+'-'+planNameTemp+'-'+'统计信息.xlsx','xlsx',{
//合并列
extend:{
'成绩统计': {
'!merges': mergeConf
},
'及格占比': {
'!merges': mergeConf
},
'分数分布': {
'!merges': mergeConf
},
'最值分析': {
'!merges': mergeConf
}
}
})