首页>代码>jsp+servlet+jdbc开发学生信息后台管理系统>/学生管理系统/Student/src/cla2sub/servlet/ExportCal_subServlet.java
package cla2sub.servlet;

import impl.Cla2SubImpl;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.Colour;
import jxl.format.VerticalAlignment;
import jxl.write.BorderLineStyle;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import entity.Cla2Sub;

public class ExportCal_subServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(req, resp);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		try {
			resp.setContentType("text/html");
			resp.setContentType("application/vnd.ms-excel");
			Cla2SubImpl cla2SubImpl = new Cla2SubImpl();
			String search_type = req.getParameter("search_type");
			String search_value = java.net.URLDecoder.decode(req
					.getParameter("value"), "UTF-8");
			List<Cla2Sub> list_cla2Sub = cla2SubImpl.query(search_type,
					search_value);
			String classes_name = list_cla2Sub.get(0).getClasses().getName();
			String fileName = classes_name + ".xls";
			resp.setHeader("Content-Disposition", "attachment;" + " filename="
					+ new String(fileName.getBytes(), "ISO-8859-1"));
			OutputStream os = resp.getOutputStream();
			WritableWorkbook wwb = Workbook.createWorkbook(os);
			WritableSheet ws = wwb.createSheet(classes_name + "课程表", 0);
			WritableFont title_big = new WritableFont(WritableFont.ARIAL, 16,
					WritableFont.BOLD);
			WritableFont title_little = new WritableFont(WritableFont.ARIAL,
					12, WritableFont.BOLD);
			WritableCellFormat f1 = new WritableCellFormat(title_big);
			f1.setAlignment(Alignment.CENTRE);
			f1.setVerticalAlignment(VerticalAlignment.CENTRE);
			f1.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
			WritableCellFormat f2 = new WritableCellFormat(title_little);
			f2.setAlignment(Alignment.CENTRE);
			f2.setVerticalAlignment(VerticalAlignment.CENTRE);
			f2.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
			WritableCellFormat f3 = new WritableCellFormat();
			f3.setAlignment(Alignment.CENTRE);
			f3.setVerticalAlignment(VerticalAlignment.CENTRE);
			f3.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
			ws.setRowView(0, 600);
			ws.setRowView(1, 500);
			ws.mergeCells(0, 0, 1, 0);
			Label label;
			label = new Label(0, 0, classes_name + "课程表  ", f1);
			ws.addCell(label);
			label = new Label(2, 0, "班主任:"
					+ list_cla2Sub.get(0).getClasses().getTecName(), f3);
			ws.addCell(label);
			String[] title = { "班级名", "科目名", "主讲教师名" };

			for (int i = 0; i < title.length; i++) {
				label = new Label(i, 1, title[i], f2);
				ws.addCell(label);
				ws.setColumnView(i, 15);
			}
			for (int i = 0; i < list_cla2Sub.size(); i++) {
				label = new Label(0, i + 2, list_cla2Sub.get(i).getClasses()
						.getName(), f3);
				ws.addCell(label);
				label = new Label(1, i + 2, list_cla2Sub.get(i).getSubject()
						.getName(), f3);
				ws.addCell(label);
				label = new Label(2, i + 2, list_cla2Sub.get(i).getTeacher()
						.getName(), f3);
				ws.addCell(label);
				ws.setRowView(i + 2, 400);
			}
			wwb.write();
			wwb.close();
			os.close();

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
最近下载更多
asddwh  LV12 2023年12月29日
微信网友_6797029372219392  LV2 2023年12月28日
ddzfgh  LV1 2023年12月25日
微信网友_6786215447367680  LV4 2023年12月23日
陈煌锐  LV1 2023年12月14日
hongdongdong  LV12 2023年6月27日
不想打代码的小林111  LV1 2023年6月14日
abcdef_wtx  LV1 2023年6月8日
www111111111  LV2 2023年5月23日
最近浏览更多
Nuyoah_L 1月3日
暂无贡献等级
微信网友_6797029372219392  LV2 2023年12月28日
smysmy 2023年12月28日
暂无贡献等级
lx123456000  LV3 2023年12月27日
磊哥哥哥哥  LV13 2023年12月26日
asddwh  LV12 2023年12月26日
ddzfgh  LV1 2023年12月25日
微信网友_6786215447367680  LV4 2023年12月20日
ziv5466123  LV7 2023年12月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友