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

📄 ordinaryputoutexcel.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 OrdinaryPutOutExcel {

	public OrdinaryPutOutExcel(){
		
	}
	
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("平时成绩统计表", 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, 3, 1);
			titleFormat.setAlignment(Alignment.CENTRE);
			titleFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
			titleFormat.setBorder(Border.ALL, BorderLineStyle.THIN);
			Label title_name = new Label(0, 0, "平时成绩统计表"// 设置的标题
					, 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 noCol = new Label(0, 2, "学号", headFormat);
			sheet.addCell(noCol);
			
			sheet.mergeCells(1, 2, 1, 2);
		    Label rownumCol = new Label(1, 2, "组号", headFormat);
			sheet.addCell(rownumCol);
			
			sheet.mergeCells(2, 2, 2, 2);
		    Label nameCol = new Label(2, 2, "学生姓名", headFormat);
			sheet.addCell(nameCol);
			
			sheet.mergeCells(3, 2, 3, 2);
		    Label classnoCol = new Label(3, 2, "学生成绩", headFormat);
			sheet.addCell(classnoCol);
			
			
			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);
			
			}
			
			for(int j=0;j<row;j++){
				
		        sheet.addCell(new Label(0,j+3,vector.elementAt(j*4+0).toString(),headFormat));
				sheet.addCell(new Label(1,j+3,vector.elementAt(j*4+1).toString(),headFormat));
				sheet.addCell(new Label(2,j+3,vector.elementAt(j*4+2).toString(),headFormat));
				sheet.addCell(new Label(3,j+3,vector.elementAt(j*4+3).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 + -