birt合并单元格
设置rowspan和show字段
DisTime disTime = this.disTimeService.queryDisTime(schoolYearCode, semesterCode, campusCode);
List<ClassLessonVo> list = null;
if(disTime!=null){
list = this.classTimetableAdminService.saveAndQueryClassTimetableBirt(schoolYearCode, semesterCode, classIds, classNames, disTime, timeTableFormatSet,campusCode);
hideShowItem(list);
getPractice(list, schoolYearId, semesterid);
//声明合并标记列的数组--begin
int weekDay = 5;
weekDay = disTime.getStudyDays().split(Constants.SPLIT_COMMA).length;
int[] markArray = new int[weekDay];
int[] indexArray = new int[weekDay];
//声明合并标记列的数组--end
if (list != null && list.size() > 0) {
for (ClassLessonVo clv:list) {
//clv:每个table
if (clv.getCourseAmCells() != null && clv.getCourseAmCells().length > 0) {
for (int i = 0; i < clv.getCourseAmCells().length; i++) {
//每个row
for (int j = 0; j < clv.getCourseAmCells()[i].length; j++) {
//每个cell
CourseCellVo ccv = clv.getCourseAmCells()[i][j];
//初始化数组
if(i==0){
markArray[j]=0;
}
setCellCourseData(ccv,clv);
//比较并合并单元格
String cellInfoFord = getCellInfo(ccv);
String cellInfoBehind = "";
CourseCellVo ccvBehind = new CourseCellVo();
if(i+1<clv.getCourseAmCells().length&&cellInfoFord.length()>0){
ccvBehind = clv.getCourseAmCells()[i+1][j];
setCellCourseData(ccvBehind,clv);
cellInfoBehind = getCellInfo(ccvBehind);
}
if(cellInfoBehind.length()>0&&cellInfoBehind.equals(cellInfoFord)){
ccvBehind.setShow(0);
markArray[j]++;
}else if(!cellInfoFord.equals(cellInfoBehind)&&markArray[j]>0){
indexArray[j] = i-markArray[j];
CourseCellVo indexObj = clv.getCourseAmCells()[indexArray[j]][j];
indexObj.setRowspan(markArray[j]+1);
markArray[j] = 0;
ccv.setShow(0);
}
//比较并合并单元格--end
}
}
}
if (clv.getCoursePmCells() != null && clv.getCoursePmCells().length > 0) {
for (int i = 0; i < clv.getCoursePmCells().length; i++) {
for (int j = 0; j < clv.getCoursePmCells()[i].length; j++) {
CourseCellVo ccv = clv.getCoursePmCells()[i][j];
setCellCourseData(ccv,clv);
//比较并合并单元格
String cellInfoFord = getCellInfo(ccv);
String cellInfoBehind = "";
CourseCellVo ccvBehind = new CourseCellVo();
if(i+1<clv.getCoursePmCells().length&&cellInfoFord.length()>0){
ccvBehind = clv.getCoursePmCells()[i+1][j];
setCellCourseData(ccvBehind,clv);
cellInfoBehind = getCellInfo(ccvBehind);
}
if(cellInfoBehind.length()>0&&cellInfoBehind.equals(cellInfoFord)){
ccvBehind.setShow(0);
markArray[j]++;
}else if(!cellInfoFord.equals(cellInfoBehind)&&markArray[j]>0){
indexArray[j] = i-markArray[j];
CourseCellVo indexObj = clv.getCoursePmCells()[indexArray[j]][j];
indexObj.setRowspan(markArray[j]+1);
markArray[j] = 0;
ccv.setShow(0);
}
//比较并合并单元格--end
}
}
}
}
}
}
子方法
public void setCellCourseData(CourseCellVo ccv,ClassLessonVo clv ){
if (ccv != null && ccv.getCourses() != null && ccv.getCourses().size() > 0) {
for (CourseInfoVo civ:ccv.getCourses()) {
if (civ.getPlaceNames() == null || "".equals(civ.getPlaceNames())) {
EcClass ec = new EcClass();
ec.setName(clv.getName());
List<EcClass> ecList = classService.queryEnableClass(ec);
if (ecList != null && ecList.size() > 0) {
if (civ.getPlaceNames() == null || "".equals(civ.getPlaceNames())) {
civ.setPlaceNames(ecList.get(0).getClassroomNum().getClassRoomMode());
civ.setPlaceType(ecList.get(0).getClassroomNum().getRoomType().getName());
} else {
civ.setPlaceNames(civ.getPlaceNames() + "," + ecList.get(0).getClassroomNum().getClassRoomMode());
}
}
} else {
//System.out.println("" + i + "," + j + ":" + civ.getPlaceNames());
}
//System.out.println("" + i + "," + j + ":" + civ.getClassNames());
}
}
}
public String getCellInfo(CourseCellVo ccv){
String cellInfo = "";
if (ccv != null && ccv.getCourses() != null && ccv.getCourses().size() > 0) {
for (CourseInfoVo civ:ccv.getCourses()) {
//拼串--begin
if(cellInfo.length()>0) cellInfo+=";";
cellInfo+=(civ.getCourseCode()!=null)?civ.getCourseCode():"";
cellInfo+=(civ.getPrintCourseName()!=null)?civ.getPrintCourseName():"";
cellInfo+=(civ.getCourseCategory()!=null)?civ.getCourseCategory():"";
if(civ.getStartEndWeek()!=null||civ.getOddEvenWeek()!=null){
cellInfo+=(civ.getStartEndWeek()!=null)?(civ.getStartEndWeek()+"周"):"";
cellInfo+=(civ.getOddEvenWeek()!=null)?civ.getOddEvenWeek():"";
}
if(civ.getPlaceNames()!=null||civ.getPlaceType()!=null){
cellInfo+=(civ.getPlaceNames()!=null)?civ.getPlaceNames():"";
cellInfo+=(civ.getPlaceType()!=null)?civ.getPlaceType():"";
}
if(civ.getTeacherName1()!=null||civ.getTeacherName2()!=null||civ.getTeacherName3()!=null||civ.getTeacherName4()!=null){
cellInfo+=(civ.getTeacherName1()!=null)?civ.getTeacherName1():"";
cellInfo+=(civ.getTeacherName2()!=null)?civ.getTeacherName2():"";
cellInfo+=(civ.getTeacherName3()!=null)?civ.getTeacherName3():"";
cellInfo+=(civ.getTeacherName4()!=null)?civ.getTeacherName4():"";
}
if(civ.getTeacheTitle1()!=null||civ.getTeacheTitle2()!=null||civ.getTeacheTitle3()!=null||civ.getTeacheTitle4()!=null){
cellInfo+=(civ.getTeacheTitle1()!=null)?civ.getTeacheTitle1():"";
cellInfo+=(civ.getTeacheTitle2()!=null)?civ.getTeacheTitle2():"";
cellInfo+=(civ.getTeacheTitle3()!=null)?civ.getTeacheTitle3():"";
cellInfo+=(civ.getTeacheTitle4()!=null)?civ.getTeacheTitle4():"";
}
if(civ.getStudentNum()!=null){
cellInfo+=(civ.getStudentNum()!=null)?("学生人数:"+civ.getStudentNum()):"";
}
}
//拼串--end
}
return cellInfo;
}
页面
<#list am as amCell>
<#if amCell.show == 1>
<#if amCell.size != 0>
<#list amCell.courses as course>
<#assign idNo = idNo + 1>
<cell id="${idNo?c}">
<property name="width">${amCell.colspan*2*w_final}px</property>
<property name="colSpan">${amCell.colspan}</property>
<property name="rowSpan">${amCell.rowspan}</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1px</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1px</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1px</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1px</property>
<property name="verticalAlign">middle</property>
<#assign m_course_width = 2*w_final*amCell.colspan>
<#assign m_course_height = m_height>
<#assign n_pcnl = (course.printCourseName?length)>
<#assign n_cm = m_course_width*6/67>
<#assign idNo = idNo + 1>
<#assign cellCourseInfo = "">
<#if course.courseCode??>
<#assign cellCourseInfo = cellCourseInfo+course.courseCode>
</#if>
<#if course.printCourseName??>
<#assign cellCourseInfo = cellCourseInfo+course.printCourseName>
</#if>
<#if course.courseCategory??>
<#if cellCourseInfo?length gt 0><#assign cellCourseInfo =cellCourseInfo+ "\r\n"></#if>
<#assign cellCourseInfo = cellCourseInfo+course.courseCategory>
</#if>
<#if course.startEndWeek?? || course.oddEvenWeek??>
<#assign brFlag = 0>
<#if cellCourseInfo?length gt 0>
<#assign cellCourseInfo =cellCourseInfo+ "\r\n">
</#if>
<#if course.startEndWeek??>
<#assign cellCourseInfo = cellCourseInfo+course.startEndWeek+"周">
</#if>
<#if course.oddEvenWeek??>
<#assign cellCourseInfo = cellCourseInfo+course.oddEvenWeek>
</#if>
</#if>
<#if course.placeNames?? || course.placeType??>
<#if cellCourseInfo?length gt 0><#assign cellCourseInfo =cellCourseInfo+ "\r\n"></#if>
<#if course.placeNames??>
<#assign cellCourseInfo = cellCourseInfo+course.placeNames>
</#if>
<#if course.placeType??>
<#assign cellCourseInfo = cellCourseInfo+course.placeType>
</#if>
</#if>
<#if course.teacherName1?? || course.teacherName2?? || course.teacherName3?? || course.teacherName4??>
<#if cellCourseInfo?length gt 0><#assign cellCourseInfo =cellCourseInfo+ "\r\n"></#if>
<#if course.teacherName1??>
<#assign cellCourseInfo = cellCourseInfo+course.teacherName1>
</#if>
<#if course.teacherName2??>
<#assign cellCourseInfo = cellCourseInfo+course.teacherName2>
</#if>
<#if course.teacherName3??>
<#assign cellCourseInfo = cellCourseInfo+course.teacherName3>
</#if>
<#if course.teacherName4??>
<#assign cellCourseInfo = cellCourseInfo+course.teacherName4>
</#if>
</#if>
<#if course.teacheTitle1?? || course.teacheTitle2?? || course.teacheTitle3?? || course.teacheTitle4??>
<#if cellCourseInfo?length gt 0><#assign cellCourseInfo =cellCourseInfo+ "\r\n"></#if>
<#if course.teacheTitle1??>
<#assign cellCourseInfo = cellCourseInfo+course.teacheTitle1>
</#if>
<#if course.teacheTitle2??>
<#assign cellCourseInfo = cellCourseInfo+course.teacheTitle2>
</#if>
<#if course.teacheTitle3??>
<#assign cellCourseInfo = cellCourseInfo+course.teacheTitle3>
</#if>
<#if course.teacheTitle4??>
<#assign cellCourseInfo = cellCourseInfo+course.teacheTitle4>
</#if>
</#if>
<#if course.studentNum??>
<#if cellCourseInfo?length gt 0><#assign cellCourseInfo =cellCourseInfo+ "\r\n"></#if>
<#assign cellCourseInfo = cellCourseInfo+"学生人数:"+course.studentNum>
</#if>
<text id="${idNo?c}">
<#--property name="fontWeight">bold</property-->
<property name="backgroundColor">#FFFFFF</property>
<property name="contentType">auto</property>
<property name="layoutPreference">auto layout</property>
<property name="forceFit">true</property>
<text-property name="content"><![CDATA[${cellCourseInfo}]]></text-property>
</text>
<#--if course.courseCategory??>
<#assign m_class_height = m_height>
<#assign idNo = idNo + 1>
<#assign n_cm = m_course_width*6/67>
<#assign n_tn = (course.courseCategory?length)>
<text id="${idNo?c}">
<property name="textAlign">left</property>
<property name="backgroundColor">#FFFFFF</property>
<property name="contentType">auto</property>
<text-property name="content"><![CDATA[${course.courseCategory}]]></text-property>
</text>
</#if>
<#if course.startEndWeek?? || course.oddEvenWeek??>
<#assign idNo = idNo + 1>
<text id="${idNo?c}">
<property name="fontSize">10pt</property>
<property name="textAlign">left</property>
<property name="backgroundColor">#FFFFFF</property>
<property name="contentType">auto</property>
<text-property name="content"><![CDATA[<#if course.startEndWeek??>${course.startEndWeek}周 </#if><#if course.oddEvenWeek??>${course.oddEvenWeek}</#if>]]></text-property>
</text>
</#if>
<#if course.placeNames?? || course.placeType??>
<#assign idNo = idNo + 1>
<text id="${idNo?c}">
<property name="fontSize">10pt</property>
<property name="textAlign">left</property>
<property name="backgroundColor">#FFFFFF</property>
<property name="contentType">auto</property>
<text-property name="content"><![CDATA[<#if course.placeNames??>${course.placeNames} </#if><#if course.placeType??>${course.placeType} </#if>]]></text-property>
</text>
</#if>
<#if course.teacherName1?? || course.teacherName2?? || course.teacherName3?? || course.teacherName4??>
<#assign idNo = idNo + 1>
<text id="${idNo?c}">
<property name="textAlign">left</property>
<property name="backgroundColor">#FFFFFF</property>
<property name="contentType">auto</property>
<text-property name="content"><![CDATA[<#if course.teacherName1??>${course.teacherName1}</#if><#if course.teacherName2??>,${course.teacherName2}</#if><#if course.teacherName3??>,${course.teacherName3}</#if><#if course.teacherName4??>,${course.teacherName4}</#if>]]></text-property>
</text>
</#if>
<#if course.teacheTitle1?? || course.teacheTitle2?? || course.teacheTitle3?? || course.teacheTitle4??>
<#assign idNo = idNo + 1>
<text id="${idNo?c}">
<property name="textAlign">left</property>
<property name="backgroundColor">#FFFFFF</property>
<property name="contentType">auto</property>
<text-property name="content"><![CDATA[<#if course.teacheTitle1??>${course.teacheTitle1}</#if><#if course.teacheTitle2??>,${course.teacheTitle2}</#if><#if course.teacheTitle3??>,${course.teacheTitle3}</#if><#if course.teacheTitle4??>,${course.teacheTitle4}</#if>]]></text-property>
</text>
</#if>
<#if course.studentNum??>
<#assign n_cm = m_course_width*6/67>
<#assign n_pn = (course.studentNum?length)>
<#assign idNo = idNo + 1>
<text id="${idNo?c}">
<property name="fontSize">10pt</property>
<property name="textAlign">left</property>
<property name="backgroundColor">#FFFFFF</property>
<property name="contentType">auto</property>
<text-property name="content"><![CDATA[学生人数:${course.studentNum}]]></text-property>
</text>
</#if-->
</cell>
</#list>
<#else>
<#assign idNo = idNo + 1>
<cell id="${idNo?c}">
<property name="width">${amCell.colspan*2*w_final}px</property>
<property name="colSpan">${amCell.colspan}</property>
<property name="rowSpan">${amCell.rowspan}</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1px</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1px</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1px</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1px</property>
<#assign idNo = idNo + 1>
<text id="${idNo?c}">
<property name="backgroundColor">#FFFFFF</property>
<property name="contentType">auto</property>
<text-property name="content"><![CDATA[ ]]></text-property>
</text>
</cell>
</#if>
</#if>
</#list>
</row>
</#list>
整合成方法
public void setRowspan(CourseCellVo ccvFord,ClassLessonVo clv ,String ampmFlag,int row,int col,int markArray[],int indexArray[]){
//初始化数组
if(row==0){
markArray[col]=0;
System.out.println(row+","+col);
}
//比较并合并单元格
String cellInfoFord = getCellInfo(ccvFord);
String cellInfoBehind = "";
CourseCellVo[][] courseCells = null;
if(ampmFlag.equals("am")){
courseCells = clv.getCourseAmCells();
}else if(ampmFlag.equals("pm")){
courseCells = clv.getCoursePmCells();
}
CourseCellVo ccvBehind = new CourseCellVo();
if(row+1<courseCells.length&&cellInfoFord.length()>0){
ccvBehind = courseCells[row+1][col];
setCellCourseData(ccvBehind,clv);
cellInfoBehind = getCellInfo(ccvBehind);
}
if(cellInfoBehind.length()>0&&cellInfoBehind.equals(cellInfoFord)){
ccvBehind.setShow(0);
markArray[col]++;
}else if(!cellInfoFord.equals(cellInfoBehind)&&markArray[col]>0){
indexArray[col] = row-markArray[col];
System.out.println("row:"+row+",col:"+col+",markArray[col]:"+markArray[col]
+",indexArray[col]:"+indexArray[col]);
CourseCellVo indexObj = courseCells[indexArray[col]][col];
indexObj.setRowspan(markArray[col]+1);
markArray[col] = 0;
ccvFord.setShow(0);
}
//比较并合并单元格--end
}
每行固定高度,不论是否表格有内容,都固定高度
<row id="${idNo?c}">
<property name="height">${m_height }px</property>
每个row标签设置height即可
注意!!!!!!
1,<#--导出必须设置row的height,而打印时还必须设置cell的height,不然单元格内所有文字都加粗-->
<property name="height">${m_height }px</property>
2,
<#assign totalWidth = 763 * birtBrowser.widthRatio>
<#--每个单元格都有border=1px,所以获得单元格宽度后,需减掉3,才能保证table显示全部-->
<#assign w_final = totalWidth/((totalColumn + 1))-3>
3,把grid第一行的row删除,不然行号列会按照width=19显示,而不是按照正常的1列宽度显示
<#assign idNo = idNo + 1>
<grid id="${idNo?c}">
<property name="width">${763 * birtBrowser.widthRatio}px</property>
<#assign idNo = idNo + 1>
<row id="${idNo?c}">
<property name="height">${1* birtBrowser.heightRatio}px</property>
<property name="verticalAlign">middle</property>
<property name="whiteSpace">nowrap</property>
<property name="width">${763 * birtBrowser.widthRatio}px</property>
<#assign idNo = idNo + 1>
<cell id="${idNo?c}">
<property name="verticalAlign">middle</property>
<property name="textAlign">center</property>
<#assign idNo = idNo + 1>
<text id="${idNo?c}">
<property name="fontSize">${1* birtBrowser.heightRatio}px</property>
<property name="verticalAlign">middle</property>
<property name="textAlign">center</property>
<property name="contentType">auto</property>
<property name="fontWeight">bold</property>
<property name="whiteSpace">nowrap</property>
<text-property name="content"><![CDATA[]]></text-property>
</text>
</cell>
</row>
上一篇: MPAndroidChart,barchart柱形图颜色的设置
下一篇: 终端自定义颜色