日期:2014-05-19  浏览次数:20679 次

求解释。
public HashMap<String, Object> outEmployee(InvokeContext ctx){
String result = "";
HashMap<String, Object> resultMap = new HashMap<String, Object>();
//创建一个空白的WorkBook
HSSFWorkbook wb = new HSSFWorkbook();
//基于上面的wb创建属于WorkBook的Sheet
HSSFSheet st = wb.createSheet("职工信息");
//基于上面的st创建Sheet的Row
HSSFRow row = st.createRow(0);//从数据库中查询一共有多少条职工信息
//基于上面的Row创建Row的Cell
HSSFCell cell = row.createCell(0);
//为Cell填充值

HSSFCellStyle style = wb.createCellStyle();
Font font = wb.createFont();
//font.setFontHeightInPoints((short)24); //字体大小
//font.setFontName("楷体");
font.setBoldweight(Font.BOLDWEIGHT_BOLD); //粗体
font.setColor(HSSFColor.RED.index); //红色字体
style.setFont(font);

cell.setCellValue("序号");
HSSFCell cell1 = row.createCell(1);
cell1.setCellType(HSSFCell.CELL_TYPE_STRING);
cell1.setCellValue("职工编号");
cell1.setCellStyle(style);
HSSFCell cell2 = row.createCell(2);
cell2.setCellValue("职工姓名");
cell2.setCellStyle(style);
HSSFCell cell3 = row.createCell(3);
cell3.setCellValue("性别");
cell3.setCellStyle(style);
HSSFCell cell4 = row.createCell(4);
cell4.setCellValue("单位名称");
cell4.setCellStyle(style);
HSSFCell cell5 = row.createCell(5);
cell5.setCellValue("email");
HSSFCell cell6 = row.createCell(6);
cell6.setCellType(HSSFCell.CELL_TYPE_STRING);
cell6.setCellValue("电话");
try {
List<Employee> list = this.daofac.getEmployeeDao().getAllEmployees();
for (int i = 1; i <= list.size(); i++) {
Employee emp = list.get(i-1);
HSSFRow rowi = st.createRow(i);
for (int j = 0; j < 7; j++) {
if(j==0){
HSSFCell cellj = rowi.createCell(j);
cellj.setCellValue(i);
}
if(j==1){
HSSFCell cellj = rowi.createCell(j);
cellj.setCellValue(emp.getEmpId());
}
if(j==2){
HSSFCell cellj = rowi.createCell(j);
cellj.setCellValue(emp.getEmpName());
}
if(j==3){
HSSFCell cellj = rowi.createCell(j);
if(emp.getSex()=="1" || emp.getSex().equals("1"))
cellj.setCellValue("男");
else
cellj.setCellValue("女");
}
if(j==4){
HSSFCell cellj = rowi.createCell(j);
cellj.setCellValue(emp.getDeptId());
}
if(j==5){
HSSFCell cellj = rowi.createCell(j);
cellj.setCellValue(emp.getEmail());
}
if(j==6){
HSSFCell cellj = rowi.createCell(j);
cellj.setCellType(HSSFCell.CELL_TYPE_STRING);
cellj.setCellValue(emp.getTelephone());
}
}

}
//创建一个文件输出流,指定输出到C盘根目录下 
FileOutputStream fos = new FileOutputStream("c:/upload/temp/employeeInfoTemp.xls");
//把WorkBook写到流里
wb.write(fos);
//刷新
fos.flush();
//手动关闭流
fos.close();



//获取文件
File file = new File("c:/upload/temp/employeeInfoTemp.xls");
//下载文件
//定义文件输入流对象
FileInputStream