package com.info.serviceimpl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import javax.imageio.stream.FileImageInputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.struts2.ServletActionContext;
import com.info.model.Base;
import com.info.model.Education;
import com.info.model.Job;
import com.info.model.Other;
import com.info.model.Remark;
import com.info.service.BaseService;
import com.info.service.EducationService;
import com.info.service.GenerateExcelService;
import com.info.service.JobService;
import com.info.service.OtherService;
import com.info.service.RemarkService;
import com.info.util.DateTimeUtil;
public class GenerateExcelServiceImpl implements GenerateExcelService {
private BaseService baseService;
private EducationService educationService;
private JobService jobService;
private OtherService otherService;
private RemarkService remarkService;
private Base base;
private Education education;
private Job job;
private Other other;
private Remark remark;
public void setBaseService(BaseService baseService) {
this.baseService = baseService;
}
public void setEducationService(EducationService educationService) {
this.educationService = educationService;
}
public void setJobService(JobService jobService) {
this.jobService = jobService;
}
public void setOtherService(OtherService otherService) {
this.otherService = otherService;
}
public void setRemarkService(RemarkService remarkService) {
this.remarkService = remarkService;
}
public static String toUtf8String(String s) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 0 && c <= 255) {
sb.append(c);
} else {
byte[] b;
try {
b = Character.toString(c).getBytes("utf-8");
} catch (Exception ex) {
System.out.println(ex);
b = new byte[0];
}
for (int j = 0; j < b.length; j++) {
int k = b[j];
if (k < 0)
k += 256;
sb.append("%" + Integer.toHexString(k).toUpperCase());
}
}
}
return sb.toString();
}
public InputStream getInputStream(int id) {
DateTimeUtil dtu = new DateTimeUtil();
base = baseService.findBase(id);
education = educationService.findEdu(id);
job = jobService.findJob(id);
other = otherService.findOther(id);
remark = remarkService.findRemark(id);
System.out.println("base:" + base);
System.out.println("education:" + education);
System.out.println("job:" + job);
System.out.println("other:" + other);
System.out.println("remark:" + remark);
String sex = null;
String marry = null;
String retire = null;
if (base.getSex() == null) {
sex = "保密";
} else {
if (base.getSex() == 0) {
sex = "男";
} else {
sex = "女";
}
}
if (base.getMarry() == null) {
marry = "未知";
} else {
if (base.getMarry() == 0) {
marry = "已婚";
} else {
marry = "未婚";
}
}
if (job.getRetire() == null) {
retire = "未知";
} else {
if (job.getRetire() == 0) {
retire = "是";
} else {
retire = "否";
}
}
HSSFWorkbook hw = new HSSFWorkbook();
HSSFSheet sheet = hw.createSheet("sheet1");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(this.toUtf8String("档案编号:"));
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("姓名:");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("曾用名:");
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("性别:");
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("婚否:");
cell = row.createCell((short) 5);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("出生日期:");
cell = row.createCell((short) 6);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("身份证号:");
cell = row.createCell((short) 7);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("民族:");
cell = row.createCell((short) 8);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("籍贯:");
cell = row.createCell((short) 9);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("现居地:");
cell = row.createCell((short) 10);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("加入组织时间:");
cell = row.createCell((short) 11);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("学历:");
cell = row.createCell((short) 12);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("毕业时间:");
cell = row.createCell((short) 13);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("毕业院校:");
cell = row.createCell((short) 14);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("学历:");
cell = row.createCell((short) 15);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("毕业时间:");
cell = row.createCell((short) 16);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("毕业院校:");
cell = row.createCell((short) 17);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("继续教育:");
cell = row.createCell((short) 18);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("退休");
cell = row.createCell((short) 19);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("编制:");
cell = row.createCell((short) 20);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("上岗时间:");
cell = row.createCell((short) 21);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("工龄:");
cell = row.createCell((short) 22);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("职称");
cell = row.createCell((short) 23);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("受职时间:");
cell = row.createCell((short) 24);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("奖励记录:");
cell = row.createCell((short) 25);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("发表论文:");
cell = row.createCell((short) 26);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("爱好");
cell = row.createCell((short) 27);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("备注:");
row = sheet.createRow(1);
cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(base.getArchiveId());
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(base.getName());
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(base.getOldname());
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(sex);
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(marry);
cell = row.createCell((short) 5);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(dtu.convertToStr(base.getBirth()));
cell = row.createCell((short) 6);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(base.getCardId());
cell = r