我的导出模板

// 表头
String[] title = new String[] { "序号", "船名", "船检登记号", "船籍港", "总长", "垂线间长", "总吨位", "主机总功率", "航区", "海河船", "船型", "建造完工日期", "检验状态", "归属类别", "船级状态", "净吨位", "载重量", "船舶所有人", "船舶经营人",
		"船舶管理公司", "船舶制造厂" };
HSSFWorkbook book = new HSSFWorkbook();
HSSFSheet sheet = book.createSheet("船舶基本信息");

HSSFRow titleRow0 = sheet.createRow(0);// 第一行 实施部门
titleRow0.setHeightInPoints(20);// 第一行行高
// 字体
HSSFFont font = book.createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short) 10);// 字体大小
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗
// 风格
HSSFCellStyle style = book.createCellStyle();
style.setFont(font);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中

for (int i = 0; i < title.length; i++) {
	HSSFCell cell = titleRow0.createCell(i);
	// 设置列宽
	if (i > 16 || i == 1) {
		sheet.setColumnWidth(i, title[i].getBytes().length * 456 * 2);
	} else {
		sheet.setColumnWidth(i, title[i].getBytes().length * 456);
	}
	cell.setCellStyle(style);
	cell.setCellValue(title[i]);
}
HSSFCellStyle cellStringStyle = book.createCellStyle();
cellStringStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
cellStringStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
for (int i = 0; i < problems.size(); i++) {
	Object[] content = (Object[]) problems.get(i);
	HSSFRow titleRow = sheet.createRow(i + 1);
	for (int j = 0; j < content.length; j++) {
		HSSFCell cell = titleRow.createCell(j);
		String str = String.valueOf(content[j]);
		cell.setCellStyle(cellStringStyle);
		if (str != null && !"null".equals(str)) {
			cell.setCellValue(str);
		}
	}
}
response.setHeader("Content-Disposition", "attachment; filename=" + new String("船舶基本信息导出".getBytes("gb18030"), "iso-8859-1") + ".xls");
response.setContentType("application/vnd.ms-excel;charset=utf-8");
ServletOutputStream out = response.getOutputStream();
book.write(out);
out.flush();
out.close();


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值