java web中的导出excel_java web 项目中做过导出excel!!!!!!!!!!!!

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

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;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值