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

📄 differetstudenttable.java

📁 一个KTV管理系统
💻 JAVA
字号:
package view.mainframe.guestconsumed.guestcheckoutframe;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
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;

public class DifferetStudentTable {

	public static void main(String[] args) {

	}

	public void writeExcelOfFile(String fileName, Vector vectorData,
			Vector vectorTitle) {
		WritableWorkbook excelModel = null; // Excle文件写出操作对象

		try {
			// 创建Excel文件写出操作对象
			File file = new File(fileName);
			excelModel = Workbook.createWorkbook(file);

			// 调用生成Excel列表方法设置并生成Excel
			this.writeExcelFile(excelModel, vectorData);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				excelModel.close(); // 必须关闭创建Excel文档的对象
			} catch (WriteException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}

	/**
	 * 写出Excel文件
	 * 
	 * @param excelModel
	 * @param argTableVO
	 * @throws WriteOutExcelException
	 */
	private void writeExcelFile(WritableWorkbook excelModel,
			Vector argVectorData) throws Exception {
		try {
			/* 设置标题 */
			String title = "顾客明细消费表";

			// 设置页面Sheet
			WritableSheet ws = excelModel.createSheet(title, 0);

			// 设置头
			this.buildExlHead(ws, title);

			// 每一个单元个的样式
			WritableCellFormat callFormat = new WritableCellFormat();
			callFormat.setAlignment(Alignment.CENTRE);
			callFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
			callFormat.setBorder(Border.ALL, BorderLineStyle.THIN);

			Iterator columnIterator = argVectorData.iterator(); // 列的叠带器
			Vector rowVector = null; // 行的向量对象
			int rowNum = 3; // 值起始行号
			for (; columnIterator.hasNext();) {
				rowVector = (Vector) columnIterator.next();
				for (int i = 0, n = rowVector.size(); i < n; i++) {
					ws.addCell(new Label(i, rowNum, rowVector.elementAt(i)
							.toString(), callFormat));
				}
				rowNum++;
			}

			// 写出Excel文件
			excelModel.write(); // 必须调用写文件的方法

		} catch (FileNotFoundException fne) {
			fne.printStackTrace();
		} catch (IOException ex) {
			ex.printStackTrace();
		} catch (WriteException wex) {
			wex.printStackTrace();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	/**
	 * 设置Excel报表标题
	 * 
	 * @param sheet
	 *            Excel操作对象的Sheet
	 * @param argTitle
	 *            标题名称
	 * @param colunmUnite
	 *            合并列数
	 * @param rowUnite
	 *            合并行数
	 * @return WritableSheet
	 * @throws WriteException
	 */
	protected WritableSheet setExcelTitle(WritableSheet sheet, String argTitle,
			int colunmUnite, int rowUnite) throws WriteException {
		// 设置合并标题栏的格式
		sheet.mergeCells(0, 0, colunmUnite, rowUnite);

		// 定义标题字体等信息
		WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 20,
				WritableFont.NO_BOLD);
		WritableCellFormat titleFormat = new WritableCellFormat(titleFont);
		titleFormat.setAlignment(Alignment.CENTRE);
		titleFormat.setVerticalAlignment(VerticalAlignment.CENTRE);

		Label title = new Label(0, 0, argTitle// 设置的标题
				, titleFormat);
		sheet.addCell(title);
		return sheet;
	}

	/**
	 * 生成销售对帐单Excel报表的报表头部
	 * 
	 * @param sheet
	 *            WritableSheet
	 * @return WritableSheet
	 * @throws WriteException
	 */
	public WritableSheet buildExlHead(WritableSheet sheet, String argTitle)
			throws Exception {
		try {
			setExcelTitle(sheet, argTitle, 25, 0);

			// 设置列表头信息
			WritableFont headFont = new WritableFont(WritableFont.ARIAL, 12,
					WritableFont.NO_BOLD);
			WritableCellFormat headFormat = new WritableCellFormat(headFont);
			headFormat.setAlignment(Alignment.CENTRE);
			headFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
			headFormat.setBorder(Border.ALL, BorderLineStyle.THIN);

			// 设置院系列的样式
			sheet.mergeCells(0, 1, 0, 5); // 0 列的起始数 1 行的起始数
			Label dateCol = new Label(0, 1, "院系", headFormat);
			sheet.addCell(dateCol);

			// 设置院九九级的样式
			sheet.mergeCells(1, 1, 5, 1);
			Label gread99 = new Label(1, 1, "九九级", headFormat);
			sheet.addCell(gread99);

			// 设置院二OO级的样式
			sheet.mergeCells(6, 1, 10, 1);
			Label gread200 = new Label(6, 1, "二OO级", headFormat);
			sheet.addCell(gread200);

			// 设置院二OO一级的样式
			sheet.mergeCells(11, 1, 15, 1);
			Label gread2001 = new Label(11, 1, "二OO一级", headFormat);
			sheet.addCell(gread2001);

			// 设置院二OO二级的样式
			sheet.mergeCells(16, 1, 20, 1);
			Label gread2002 = new Label(16, 1, "二OO二级", headFormat);
			sheet.addCell(gread2002);

			// 设置院二OO三级的样式
			sheet.mergeCells(21, 1, 25, 1);
			Label gread2003 = new Label(21, 1, "二OO三级", headFormat);
			sheet.addCell(gread2003);

			for (int i = 1; i < 26;) {
				// 设置**级总人数的样式
				sheet.mergeCells(i, 2, i, 5);
				Label pepoleNumber = new Label(i++, 2, "总人数", headFormat);
				sheet.addCell(pepoleNumber);

				// 设置**级困难学生人数的样式
				sheet.mergeCells(i, 2, i, 5);
				Label difficultyNumber = new Label(i++, 2, "困难生", headFormat);
				sheet.addCell(difficultyNumber);

				// 设置**级困难学生人数比例的样式
				sheet.mergeCells(i, 2, i, 5);
				Label difficultyRatio = new Label(i++, 2, "比例%", headFormat);
				sheet.addCell(difficultyRatio);

				// 设置**级特困生人数的样式
				sheet.mergeCells(i, 2, i, 5);
				Label especiallyDifficultyNumber = new Label(i++, 2, "特困生",
						headFormat);
				sheet.addCell(especiallyDifficultyNumber);

				// 设置**级特困生人数比例的样式
				sheet.mergeCells(i, 2, i, 5);
				Label especiallyDifficultyRatio = new Label(i++, 2, "比例%",
						headFormat);
				sheet.addCell(especiallyDifficultyRatio);
			}

			return sheet;
		} catch (WriteException ex) {
			ex.printStackTrace();
		}
		return sheet;
	}

	static public Vector getVectorData() {
		Vector veData = new Vector();

		/** 九九级 */
		Vector vd = new Vector();
		vd.add("化学系");

		// 九九级总人数
		vd.add("1000");
		// 九九级困难生人数
		vd.add("120");
		// 九九级困难生比例
		vd.add("12%");
		// 九九级特困生人数
		vd.add("10");
		// 九九级特困生人数比例
		vd.add("1%");

		/** 二OO 级 */
		// 二OO级总人数
		vd.add("1000");
		// 二OO级困难生人数
		vd.add("140");
		// 二OO级困难生比例
		vd.add("14%");
		// 二OO级特困生人数
		vd.add("10");
		// 二OO级困难生比例
		vd.add("1%");

		/** 二OO一 级 */
		// 二OO一 级总人数
		vd.add("1000");
		// 二OO一 级困难生人数
		vd.add("90");
		// 二OO一 级困难生比例
		vd.add("9%");
		// 二OO一 级特困生人数
		vd.add("1");
		// 二OO一 级困难生比例
		vd.add("0.1%");

		/** 二OO二 级 */
		// 二OO二 级总人数
		vd.add("1000");
		// 二OO二 级困难生人数
		vd.add("19");
		// 二OO二 级困难生比例
		vd.add("1.9%");
		// 二OO二 级特困生人数
		vd.add("1");
		// 二OO二 级困难生比例
		vd.add("0.1%");

		/** 二OO三 级 */
		// 二OO三 级总人数
		vd.add("1000");
		// 二OO三 级困难生人数
		vd.add("1");
		// 二OO三 级困难生比例
		vd.add("0.1%");
		// 二OO三 级特困生人数
		vd.add("0");
		// 二OO三 级困难生比例
		vd.add("0.0%");

		veData.add(vd);

		return veData;
	}
}

⌨️ 快捷键说明

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