该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
for (int i = 0; i < list.size(); i++) {
rowCount++;
if(rowCount > exportMaxCount){ //判断是否工作簿数据超过最大条数
rowCount = 1;
sheetCount++;
sheet = workbook.createSheet("sheet" + sheetCount); //创建新的工作簿
sheet.setDefaultColumnWidth((short) 15);
CreateHeader(sheet,titleStyle);//调用生成表头方法
}
row = sheet.createRow(rowCount + x); // 创建数据行
index++;
for (int j = 0; j < list.get(i).length; j++) {
cell = row.createCell((short) j);
cell.setCellStyle(contentStyle);
Object value = list.get(i)[j];
// 判断值的类型后进行强制类型转换
String textValue = null;
if (value instanceof Boolean) {
boolean bValue = (Boolean) value;
textValue = "男";
if (!bValue) {
textValue = "女";
}
} else if (value instanceof Date) {
Date date = (Date) value;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
textValue = sdf.format(date);
}else if(value instanceof Integer) {
cell.setCellStyle(contentNumStyle);
cell.setCellValue((Integer)value);
}else if(value instanceof Long) {
cell.setCellStyle(contentNumStyle);
cell.setCellValue((Long)value);
} else if(value instanceof Double) {
cell.setCellStyle(contentNumStyle);
cell.setCellValue((Double)value);
// 格式化小数(2位)
DecimalFormat df = new DecimalFormat("#,##0.00");
textValue = df.format((Double)value);
} else if (value instanceof byte[]) {
// 有图片时,设置行高为60px;
row.setHeightInPoints(60);
// 设置图片所在列宽度为80px,注意这里单位的一个换算
sheet.setColumnWidth(i, (short) (35.7 * 80));
byte[] bsValue = (byte[]) value;
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0,
1023, 255, (short) 6, index, (short) 6, index);
anchor.setAnchorType(2);
patriarch.createPicture(anchor, workbook.addPicture(
bsValue, HSSFWorkbook.PICTURE_TYPE_JPEG));
} else {
// 其它数据类型都当作字符串简单处理
textValue = value.toString();
}
if(textValue!=null){
cell.setCellValue(textValue);
}
}
}
}
}
private String doExport(){
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1;
String month_ = new String("" + month);
if (month < 10) {
month_ = "0" + month;
}
int day = c.get(Calendar.DAY_OF_MONTH);
String day_ = new String("" + day);
if (day < 10) {
day_ = "0" + day;
}
return year + "-" + month_ + "-" + day_ + "";
}
public String xz() throws Exception {
return "success";
} public String getFileName() {
//ISO-8859-1
return fileName;
} public void setFileName(String fileName) {
this.fileName = fileName;
} public String[] getTitle() {
return title;
} public void setTitle(String[] title) {
this.title = title;
} public List getList() {
return list;
} public void setList(List list) {
this.list = list;
} public String[] getTitle1() {
return title1;
} public void setTitle1(String[] title1) {
this.title1 = title1;
}
}