⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teacherputoutexcel.java

📁 培训时做的学生管理系统.基于J2SE平台开发
💻 JAVA
字号:
package cn.com.studentsystem.excel;

import java.io.File;
import java.io.IOException;
import java.util.Vector;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

public class TeacherPutOutExcel {
	
	public TeacherPutOutExcel(){
		
	}
	
	public static WritableWorkbook buildWorkBook(String filename){
		
		File file = new  File(filename);
		WritableWorkbook excel = null;
		try {
			 excel = Workbook.createWorkbook(file);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return excel;
	}
	
	public static WritableSheet setExcel(WritableWorkbook excel,int row
			,Vector vector){
        WritableSheet sheet = excel.createSheet("中信软件29班教师基本信息表", 0);
		
		WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 20,
				WritableFont.NO_BOLD);
		WritableCellFormat titleFormat = new WritableCellFormat(titleFont);
		
		WritableFont headFont = new WritableFont(WritableFont.ARIAL, 12,
				WritableFont.NO_BOLD);
		WritableCellFormat headFormat = new WritableCellFormat(headFont);
		
		
		
		try {
			sheet.mergeCells(0, 0, 8, 1);
			titleFormat.setAlignment(Alignment.CENTRE);
			titleFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
			titleFormat.setBorder(Border.ALL, BorderLineStyle.THIN);
			Label title_name = new Label(0, 0, "中信软件29班教师基本信息表"// 设置的标题
					, titleFormat);
			sheet.addCell(title_name);
			
			headFormat.setAlignment(Alignment.CENTRE);
			headFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
			headFormat.setBorder(Border.ALL, BorderLineStyle.THIN);
			
			sheet.mergeCells(0, 2, 0, 2);
		    Label idCol = new Label(0, 2, "教师ID", headFormat);
			sheet.addCell(idCol);
			
			sheet.mergeCells(1, 2, 1, 2);
		    Label nameCol = new Label(1, 2, "教师姓名", headFormat);
			sheet.addCell(nameCol);
			
			sheet.mergeCells(2, 2, 2, 2);
		    Label sexCol = new Label(2, 2, "教师性别", headFormat);
			sheet.addCell(sexCol);
			
			sheet.mergeCells(3, 2, 3, 2);
		    Label ageCol = new Label(3, 2, "教师年龄", headFormat);
			sheet.addCell(ageCol);
			
			sheet.mergeCells(4, 2, 4, 2);
		    Label jobCol = new Label(4, 2, "教师职务", headFormat);
			sheet.addCell(jobCol);
			
			sheet.mergeCells(5, 2, 5, 2);
		    Label telCol = new Label(5, 2, "教师电话", headFormat);
			sheet.addCell(telCol);
			
			sheet.mergeCells(6, 2, 6, 2);
		    Label qqCol = new Label(6, 2, "教师QQ", headFormat);
			sheet.addCell(qqCol);
			
			sheet.mergeCells(7, 2, 8, 2);
		    Label emailCol = new Label(7, 2, "教师email", headFormat);
			sheet.addCell(emailCol);
			
			
			for(int i=3;i<row+3;i++){
				sheet.mergeCells(0, i, 0, i);
				sheet.mergeCells(1, i, 1, i);
				sheet.mergeCells(2, i, 2, i);
				sheet.mergeCells(3, i, 3, i);
				sheet.mergeCells(4, i, 4, i);
				sheet.mergeCells(5, i, 5, i);
				sheet.mergeCells(6, i, 6, i);
				sheet.mergeCells(7, i, 8, i);
			
			}
			
			for(int j=0;j<row;j++){
				
		        sheet.addCell(new Label(0,j+3,vector.elementAt(j*8+0).toString(),headFormat));
				sheet.addCell(new Label(1,j+3,vector.elementAt(j*8+1).toString(),headFormat));
				sheet.addCell(new Label(2,j+3,vector.elementAt(j*8+2).toString(),headFormat));
				sheet.addCell(new Label(3,j+3,vector.elementAt(j*8+3).toString(),headFormat));
				sheet.addCell(new Label(4,j+3,vector.elementAt(j*8+4).toString(),headFormat));
				sheet.addCell(new Label(5,j+3,vector.elementAt(j*8+5).toString(),headFormat));
				sheet.addCell(new Label(6,j+3,vector.elementAt(j*8+6).toString(),headFormat));
				sheet.addCell(new Label(7,j+3,vector.elementAt(j*8+7).toString(),headFormat));
				
				
	}
			
				excel.write();
				excel.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}catch (RowsExceededException e) {
			// TODO Auto-generated catch block
			    e.printStackTrace();
			}catch (WriteException e) {
			// TODO Auto-generated catch block
			    e.printStackTrace();
		}
		
		return sheet; 		
	
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -