HSSFWorkbook的excel表格的导出

HSSFWorkbook的excel表格的导出

导入jar包

jar包下载    链接:https://pan.baidu.com/s/1LcaOhETqJTGTTc5O2EaFUA 
提取码:bux1 
复制这段内容后打开百度网盘手机App,操作更方便哦

 

jsp页面设置 (jdbc很简单数据库连接我就不写了,只写导出页面吧)

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.jspsmart.upload.*" %>
<%@ page import="org.apache.poi.hssf.usermodel.*" %>
<%@ page import="java.io.*" %>



<%
String path = request.getContextPath();
%>



  
	
	
	    
	
	
  
  
   
      <% 
      
            List jiaoshiList=new ArrayList();
            
			String sql="select * from t_jiaoshi where del='no'";
			Object[] params={};
			DB mydb=new DB();
			try
			{
				mydb.doPstm(sql, params);
				ResultSet rs=mydb.getRs();
				while(rs.next())
				{
					TJiaoshi jiaoshi=new TJiaoshi();
					
					jiaoshi.setId(rs.getInt("id"));
					jiaoshi.setGonghao(rs.getString("gonghao"));
					jiaoshi.setXingming(rs.getString("xingming"));
					jiaoshi.setXingbie(rs.getString("xingbie"));
					jiaoshi.setNianling(rs.getString("nianling"));
					jiaoshi.setShengri(rs.getString("shengri"));
					jiaoshi.setGongzuo(rs.getString("gongzuo"));
					jiaoshi.setZhuanye(rs.getString("zhuanye"));
					jiaoshi.setZhaopian(rs.getString("zhaopian"));
					jiaoshi.setBeizhu(rs.getString("beizhu"));
					
					jiaoshiList.add(jiaoshi);
			    }
				rs.close();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
			mydb.closed();
      
            
      
            HSSFWorkbook wb = new HSSFWorkbook();
			HSSFSheet sheet = wb.createSheet("new sheet");
			
			HSSFRow row = sheet.createRow(0);
			HSSFCell cell=row.createCell((short)0);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue("教师号");
					
			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("备注");
			
			
			for(int i=0;i 

      
  

效果图

HSSFWorkbook的excel表格的导出_第1张图片

HSSFWorkbook的excel表格的导出_第2张图片

你可能感兴趣的:(javaweb)