MACS01150RHandler.java类:
package com.ais.report;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import com.ais.bean.MACS01150RBean;
import com.ais.exceptions.LogicException;
import com.ais.ldap.Directory;
import com.ais.ldap.LDAPClientException;
import com.ais.util.StringUtil;
import com.ais.util.SystemUnit;
import com.ais.util.Utilities;
public class MACS01150RHandler extends ReportHandler {
private static MACS01150RHandler instance = new MACS01150RHandler();
public static MACS01150RHandler getInstance() {
return instance;
}
private static SimpleDateFormat df = new SimpleDateFormat(
SystemUnit.DATE_FORMAT);
private String rptName = "User Account Report (MACS01150R)";
private String[] heading = { "Selection Criteria", "System",
"CNA", "Name", "Role", "Discipline",
"Programme Board", "Campus", "Department", "Active?"
};
public XSSFWorkbook generateXls(Map params , String cna , List list) throws LogicException {
XSSFWorkbook wb = new XSSFWorkbook();
buildTable(wb, true, params , cna , list);
return wb;
}
public void buildTable(XSSFWorkbook wb, boolean isShowDetail,
Map params , String cna ,List list) throws LogicException {
XSSFRow row = null;
XSSFCell cell = null;
XSSFFont font = null;
int rowNum = 0;
int colNum = 0;
XSSFSheet sheet = wb.createSheet("User Account Report");
// title style
XSSFFont font1 = wb.createFont();
font1.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
XSSFCellStyle st1 = wb.createCellStyle();
st1.setFont(font1);
font1.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
XSSFCellStyle st = wb.createCellStyle();
st.setFont(font1);
st.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
// HEADING
rowNum = 0;
row = sheet.createRow(rowNum);
cell = row.createCell((short) (colNum));
cell.setCellStyle(st);
cell.setCellValue(rptName);
String[] keys = { "system", "cna", "name", "role", "discipline",
"programeBoard", "campus", "department",
"active" };
rowNum = 2;
for (int i = 0; i < heading.length; i++) {
String label = heading[i] + ":";
row = sheet.createRow(rowNum);
colNum = 0;
cell = row.createCell((short) (colNum));
cell.setCellStyle(st);
cell.setCellValue(label);
colNum++;
cell = row.createCell((short) (colNum));
if (i > 0){
String key = keys[i-1];
String value = params.get(key) == null ? null
: (String) params.get(key);
/*switch(i){
case 7:
value = showSelectedCampusDisplays(value);
break;
default:
;
}*/
if (i == heading.length - 1) {
if ("true".equals(value) ) {
value = "Y";
} else {
value = "N";
}
cell.setCellValue(value);
colNum++;
// cell = row.createCell((short) (colNum));
// cell.setCellValue(cna);
} else {
cell.setCellValue(value);
}
} else {
try{
CellRangeAddress cellRangeAddress=new CellRangeAddress(rowNum, rowNum, (short)(colNum-1), (short) (colNum));
sheet.addMergedRegion(cellRangeAddress);
}catch(Exception e){
e.printStackTrace();
}
}
rowNum++;
}
rowNum++;
row = sheet.createRow(rowNum);
cell = row.createCell((short) 0);
cell.setCellStyle(st);
cell.setCellValue("Generated as at " + StringUtil.formatTimeSec(new Date()));
this.createDataRow(wb, sheet, rowNum, params ,list);
sheet.autoSizeColumn(0);
}
private void createDataRow(XSSFWorkbook wb, XSSFSheet sheet, int rowNum,
Map param ,List list ) throws LogicException {
XSSFCell cell = null;
short var1, /*var2,*/ fontSize;
// Criteria row
fontSize = 10;
// title style
XSSFFont font1 = wb.createFont();
font1.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
XSSFCellStyle st1 = wb.createCellStyle();
st1.setFont(font1);
XSSFCellStyle title = wb.createCellStyle();
title.setAlignment(XSSFCellStyle.ALIGN_CENTER);
XSSFFont font2 = wb.createFont();
font2.setFontName(XSSFFont.DEFAULT_FONT_NAME);
font2.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
font2.setFontHeightInPoints(fontSize);
title.setFont(font2);
title.setBorderLeft(XSSFCellStyle.BORDER_THIN);
title.setBorderRight(XSSFCellStyle.BORDER_THIN);
title.setBorderBottom(XSSFCellStyle.BORDER_THIN);
title.setBorderTop(XSSFCellStyle.BORDER_THIN);
title.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
byte[] rgb = new byte[] {(byte)180, (byte)180, (byte)180};
XSSFColor myColor = new XSSFColor(rgb);
title.setFillForegroundColor(myColor);
title.setWrapText(true);
// font
XSSFFont font = wb.createFont();
font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
font.setFontName("Arial");
font.setUnderline(font.U_SINGLE);
font.setFontHeightInPoints(fontSize);
// align center
XSSFCellStyle alignCenterStyle = wb.createCellStyle();
alignCenterStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
alignCenterStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
//alignCenterStyle.setBottomBorderColor(XSSFColor.BLACK.index);
alignCenterStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
//alignCenterStyle.setLeftBorderColor(XSSFColor.BLACK.index);
alignCenterStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
//alignCenterStyle.setRightBorderColor(XSSFColor.BLACK.index);
alignCenterStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
//alignCenterStyle.setTopBorderColor(XSSFColor.BLACK.index);
alignCenterStyle.setWrapText(true);
// align left
XSSFCellStyle style1 = wb.createCellStyle();
style1.setAlignment(XSSFCellStyle.ALIGN_LEFT);
style1.setBorderBottom(XSSFCellStyle.BORDER_THIN);
//style1.setBottomBorderColor(XSSFColor.BLACK.index);
style1.setBorderLeft(XSSFCellStyle.BORDER_THIN);
//style1.setLeftBorderColor(XSSFColor.BLACK.index);
style1.setBorderRight(XSSFCellStyle.BORDER_THIN);
//style1.setRightBorderColor(XSSFColor.BLACK.index);
style1.setBorderTop(XSSFCellStyle.BORDER_THIN);
//style1.setTopBorderColor(XSSFColor.BLACK.index);
style1.setWrapText(true);
// align right
XSSFCellStyle style3 = wb.createCellStyle();
style3.setAlignment(XSSFCellStyle.ALIGN_RIGHT);
style3.setBorderBottom(XSSFCellStyle.BORDER_THIN);
//style3.setBottomBorderColor(XSSFColor.BLACK.index);
style3.setBorderLeft(XSSFCellStyle.BORDER_THIN);
//style3.setLeftBorderColor(XSSFColor.BLACK.index);
style3.setBorderRight(XSSFCellStyle.BORDER_THIN);
//style3.setRightBorderColor(XSSFColor.BLACK.index);
style3.setBorderTop(XSSFCellStyle.BORDER_THIN);
//style3.setTopBorderColor(XSSFColor.BLACK.index);
style3.setWrapText(true);
sheet.setColumnWidth((short) 0, (short) 4000);// a
sheet.setColumnWidth((short) 1, (short) 4000);// b
sheet.setColumnWidth((short) 2, (short) 4000);
sheet.setColumnWidth((short) 3, (short) 4000);// b
sheet.setColumnWidth((short) 4, (short) 4000);
sheet.setColumnWidth((short) 5, (short) 5500);
sheet.setColumnWidth((short) 6, (short) 4000);// e
sheet.setColumnWidth((short) 7, (short) 4000);
sheet.setColumnWidth((short) 8, (short) 4000);
sheet.setColumnWidth((short) 9, (short) 2800);
sheet.setColumnWidth((short) 10, (short) 3000);
sheet.setColumnWidth((short) 11, (short) 3000);
//new
sheet.setColumnWidth((short) 12, (short) 3000);
sheet.setColumnWidth((short) 13, (short) 5000);
sheet.setColumnWidth((short) 14, (short) 3000);
//end new
sheet.setColumnWidth((short) 15, (short) 3000);
sheet.setColumnWidth((short) 16, (short) 3000);
sheet.setColumnWidth((short) 17, (short) 3500);
sheet.setColumnWidth((short) 18, (short) 5000);// GAR MRP
sheet.setColumnWidth((short) 19, (short) 7500);
sheet.setColumnWidth((short) 20, (short) 9000);
sheet.setColumnWidth((short) 21, (short) 4500);
sheet.setColumnWidth((short) 22, (short) 4500);
sheet.setColumnWidth((short) 23, (short) 4000);
//end new
createTitle(sheet, title , wb );
// Group List
XSSFRow row = null;
rowNum = 17;
short cellCol ;
MACS01150RBean bean = null;
for (int i =0 ; i < list.size() ; i++){
cellCol = 0;
bean = (MACS01150RBean)list.get(i);
row = sheet.createRow(rowNum);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getUserCode());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(vtcSiteValueChange(bean.getUserName()));
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(departmentValueChange(bean.getUserName()));
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getUserName());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getChineseName());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getAdminSystemCode());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getAppCode());
cell.setCellStyle(style1);
String active = "N";
if (bean.getActive()!=null && "A".equals(bean.getActive().trim())){
active = "Y";
}
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(active);
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getValidityFrom());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getValidityTo());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getRoleCode());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getUserType());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getDispiline());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getProgBoard());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue( bean.getCampus());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getDept());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getDrCreatedBy());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getDrLastUpdateTime());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getFunctionCode());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getGrantableRoleCode());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getAppName());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getApplicantGroup());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getCreatedBy());
cell.setCellStyle(style1);
cell = row.createCell(cellCol++);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cell.setCellValue(bean.getLastUpdateTime());
cell.setCellStyle(style1);
rowNum ++ ;
}
}
public String departmentValueChange(String cna) {
String department=null;
if (!Utilities.isNull(cna)) {
String idapCheck = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("Ldap-Login");
// get name from LDAP
if (idapCheck != null && "Y".equals(idapCheck)) {
Directory dir = new Directory();
try {
dir.loadProperty("ldap.properties");
dir.connect();
department=dir.getOuDept(cna);
dir.disConnect();
} catch (LDAPClientException e1) {
SystemUnit.addMessageError(e1.getMessage());
}
}
}
return department;
}
public String vtcSiteValueChange(String cna) {
String vtcSite = null;
if (!Utilities.isNull(cna)) {
String idapCheck = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("Ldap-Login");
// get name from LDAP
if (idapCheck != null && "Y".equals(idapCheck)) {
Directory dir = new Directory();
try {
dir.loadProperty("ldap.properties");
dir.connect();
vtcSite = dir.getSite(cna);
dir.disConnect();
} catch (LDAPClientException e1) {
SystemUnit.addMessageError(e1.getMessage());
}
}
}
return vtcSite;
}
private void createTitle(XSSFSheet sheet, XSSFCellStyle titleStyle ,XSSFWorkbook wb) {
short cellIndex = 0;
XSSFRow row = null;
XSSFCell cell = null;
XSSFCell nextCell = null;
short index = (short)15;
row = sheet.createRow(index++);
row.setHeight((short)450);
XSSFRow nexRow = sheet.createRow(index);
nexRow.setHeight((short)550);
cell = row.createCell((short) cellIndex++);
cell.setCellValue("CNA");
cell.setCellStyle(titleStyle);
nextCell = nexRow.createCell((short) cellIndex);
nextCell.setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)) );
cell = row.createCell((short) cellIndex++);
cell.setCellValue("Site");
cell.setCellStyle(titleStyle);
nextCell = nexRow.createCell((short) cellIndex);
nextCell.setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)));
cell = row.createCell((short) cellIndex++);
cell.setCellValue("OU/Dept");
cell.setCellStyle(titleStyle);
nextCell = nexRow.createCell((short) cellIndex);
nextCell.setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)));
cell = row.createCell((short) cellIndex++);
cell.setCellValue("Name");
cell.setCellStyle(titleStyle);
nextCell = nexRow.createCell((short) cellIndex);
nextCell.setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)));
cell = row.createCell((short) cellIndex++);
cell.setCellValue("Chinese Name");
cell.setCellStyle(titleStyle);
nextCell = nexRow.createCell((short) cellIndex);
nextCell.setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)));
cell = row.createCell((short) cellIndex++);
cell.setCellValue("Administer System\n(for Administrator only)");
cell.setCellStyle(titleStyle);
nextCell = nexRow.createCell((short) cellIndex);
nextCell.setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)));
cell = row.createCell((short) cellIndex++);
cell.setCellValue("System");
cell.setCellStyle(titleStyle);
nextCell = nexRow.createCell((short) cellIndex);
nextCell.setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)));
// the fisr mergardRegion
//sheet.addMergedRegion(new Region((short)15, (short)0, (short)16, (short) 6));
cell = row.createCell((short) cellIndex++);
cell.setCellValue("Active Indicator (Y/N)");
cell.setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)));
XSSFCellStyle centerStyle = this.createAlignCenterStyle(wb);
cell = row.createCell((short) cellIndex);
cell.setCellStyle(centerStyle);
cell.setCellValue("Validity Period");
cell = row.createCell((short) (cellIndex +1));
cell.setCellStyle(centerStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, (short)index-1, (short)cellIndex, (short) (cellIndex +1)));
/*XSSFCell*/ nextCell = nexRow.createCell(cellIndex++);
nextCell.setCellStyle(titleStyle);
nextCell.setCellValue("From");
nextCell = nexRow.createCell(cellIndex++);
nextCell.setCellStyle(titleStyle);
nextCell.setCellValue("To");
cell = row.createCell((short) cellIndex++);
cell.setCellStyle(titleStyle);
cell.setCellValue("Role");
nextCell = nexRow.createCell((short) cellIndex);
nextCell.setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)));
cell = row.createCell((short) cellIndex++);
cell.setCellStyle(titleStyle);
cell.setCellValue("User Type");
nextCell = nexRow.createCell((short) cellIndex);
nextCell.setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)));
cell = row.createCell((short) cellIndex);
cell.setCellStyle(centerStyle);
cell.setCellValue("Data Access Right");
cell = row.createCell( cellIndex + 1);
cell.setCellStyle(centerStyle);
cell = row.createCell( cellIndex + 2);
cell.setCellStyle(centerStyle);
cell = row.createCell( cellIndex + 3);
cell.setCellStyle(centerStyle);
cell = row.createCell( cellIndex + 4);
cell.setCellStyle(centerStyle);
cell = row.createCell( cellIndex + 5);
cell.setCellStyle(centerStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index-1, (short)(cellIndex) , (short) (cellIndex +5)));
nextCell = nexRow.createCell(cellIndex);
nextCell.setCellStyle(titleStyle);
nextCell.setCellValue("Discipline");
nextCell = nexRow.createCell(cellIndex+1);
nextCell.setCellStyle(titleStyle);
nextCell.setCellValue("Programme Board / Module Board");
nextCell = nexRow.createCell(cellIndex+2);
nextCell.setCellStyle(titleStyle);
nextCell.setCellValue("Campus");
nextCell = nexRow.createCell(cellIndex+3);
nextCell.setCellStyle(titleStyle);
nextCell.setCellValue("Department");
nextCell = nexRow.createCell(cellIndex+4);
nextCell.setCellStyle(titleStyle);
nextCell.setCellValue("Last Updated By");
nextCell = nexRow.createCell(cellIndex+5);
nextCell.setCellStyle(titleStyle);
nextCell.setCellValue("Last Updated Date");
/*cellIndex++;
cellIndex++;
cellIndex++;*/
int temp = cellIndex+6;
cellIndex = (short)temp;
cell = row.createCell((short) cellIndex++);
cell.setCellStyle(titleStyle);
cell.setCellValue("Additional Function(if any)");
nextCell = nexRow.createCell((short) cellIndex);
nextCell.setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)));
cell = row.createCell((short) (cellIndex++));
cell.setCellStyle(titleStyle);
cell.setCellValue("Grantable Role(For local Admin Only)");
nextCell = nexRow.createCell((short) cellIndex);
nextCell.setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)));
cell = row.createCell((short) cellIndex);
cell.setCellStyle(centerStyle);
cell.setCellValue("Applicant Group (Applicable to SAS only)");
cell = row.createCell(cellIndex+1);
cell.setCellStyle(centerStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index-1, (short)(cellIndex) , (short) (cellIndex +1)));
nextCell = nexRow.createCell(cellIndex++);
nextCell.setCellStyle(titleStyle);
nextCell.setCellValue("System");
nextCell = nexRow.createCell(cellIndex++);
nextCell.setCellStyle(titleStyle);
nextCell.setCellValue("Applicant Group");
cell = row.createCell((short) (cellIndex++));
cell.setCellStyle(titleStyle);
cell.setCellValue("User Account\nCreated By");
nextCell = nexRow.createCell((short) cellIndex);
nextCell.setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)));
cell = row.createCell((short) (cellIndex++));
cell.setCellStyle(titleStyle);
/*nextCell = nexRow.createCell((short) cellIndex);
nextCell.setCellStyle(titleStyle);*/
cell.setCellValue("User Account\nLast Updated Date");
sheet.addMergedRegion(new CellRangeAddress(index-1, index, (short)(cellIndex-1), (short) (cellIndex-1)));
}
public static String generateFileName() {
return getDateStr(getReportName());
}
// set report name;
public static String getReportName() {
return SystemUnit.getString("reportName");
}
private XSSFCellStyle createAlignCenterStyle(XSSFWorkbook wb){
XSSFCellStyle title = wb.createCellStyle();
title.setLocked(false);
title.setAlignment(XSSFCellStyle.ALIGN_CENTER);
title.setWrapText(true);
XSSFFont font2 = wb.createFont();
font2.setFontName(XSSFFont.DEFAULT_FONT_NAME);
font2.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
short fontSize = 10;
font2.setFontHeightInPoints(fontSize);
title.setFont(font2);
title.setBorderLeft(XSSFCellStyle.BORDER_THIN);
title.setBorderRight(XSSFCellStyle.BORDER_THIN);
title.setBorderBottom(XSSFCellStyle.BORDER_THIN);
title.setBorderTop(XSSFCellStyle.BORDER_THIN);
title.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
byte[] rgb = new byte[] {(byte)180, (byte)180, (byte)180};
XSSFColor myColor = new XSSFColor(rgb);
title.setFillForegroundColor(myColor);
return title;
}
/*private String showSelectedCampusDisplays(String selectedValus)
throws LogicException {
String displays = null;
StringBuilder strBuilder = new StringBuilder();
if (selectedValus != null && !"".equals(selectedValus.trim())) {
Map<String, String> allCampus = MACS01150RLogic.instanceOf()
.getCampusDisplays(null);
String[] selectedCampuss = selectedValus.split(",");
for (int i = 0; i < selectedCampuss.length; i++) {
String str = selectedCampuss[i];
String campusDisplay = allCampus.get(str);
strBuilder.append(campusDisplay);
if (i != selectedCampuss.length - 1)
strBuilder.append(",");
}
allCampus.clear();
}
displays = strBuilder.toString();
return displays;
}
private String showDisplays(Map<String, String> allCampus, String campus)
throws LogicException {
String displays = "";
if ("*".equals(campus)) {
displays = "*";
} else if (campus != null && !"".equals(campus.trim())) {
displays = allCampus.get(campus);
}
return displays;
}
private Map<String, String> aLLCampusDisplay() throws LogicException {
Map<String, String> allCampus = MACS01150RLogic.instanceOf()
.getCampusDisplays(null);
return allCampus;
}
private String showSelectedDepts(String selectedValus)
throws LogicException {
String displays = null;
StringBuilder strBuilder = new StringBuilder();
if (selectedValus != null && !"".equals(selectedValus.trim())) {
Map<String, String> allDept = MACS01150RLogic.instanceOf()
.getDeptDisplays(null);
String[] selectedDepts = selectedValus.split(",");
for (int i = 0; i < selectedDepts.length; i++) {
String str = selectedDepts[i];
String campusDisplay = allDept.get(str);
strBuilder.append(campusDisplay);
if (i != selectedDepts.length - 1)
strBuilder.append(",");
}
allDept.clear();
}
displays = strBuilder.toString();
return displays;
}
private Map<String, String> aLLDeptDisplay() throws LogicException {
Map<String, String> allCampus = MACS01150RLogic.instanceOf()
.getDeptDisplays(null);
return allCampus;
}*/
}
ReportHandler.java类:
package com.ais.report;
import java.util.Calendar;
import com.ais.util.StringUtil;
public class ReportHandler {
public static String getDateStr(String typeName) {
StringBuffer sb = new StringBuffer();
Calendar date = Calendar.getInstance();
int second;
int month;
int dayOfMonth;
int hour;
int minute;
sb.append(typeName);
sb.append("_");
sb.append(date.get(Calendar.YEAR));
month = date.get(Calendar.MONTH) + 1;
if (month < 10) {
sb.append("0");
}
sb.append(month);
dayOfMonth = date.get(Calendar.DAY_OF_MONTH);
if (dayOfMonth < 10) {
sb.append("0");
}
sb.append(dayOfMonth);
sb.append("_");
hour = date.get(Calendar.HOUR_OF_DAY);
if (hour < 10) {
sb.append("0");
}
sb.append(hour);
minute = date.get(Calendar.MINUTE);
if (minute < 10) {
sb.append("0");
}
sb.append(minute);
second = date.get(Calendar.SECOND);
if (second < 10) {
sb.append("0");
}
sb.append(second);
sb.append("_");
String randomInt = StringUtil.getRandomNumber("R");
// if (randomInt < 100) {
// sb.append("00");
// } else if (randomInt < 1000) {
// sb.append("0");
// }
sb.append(randomInt);
sb.append(".xlsx");
return sb.toString();
}
}