码迷,mamicode.com
首页 > 编程语言 > 详细

【自动化__持续集成】___java___excel__jxl写

时间:2017-09-07 22:54:41      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:str   ble   source   stack   rac   except   file   add   new   

一、代码如下

package com.wujianbo.five;

import java.io.File;
import java.io.IOException;

import org.apache.poi.ddf.EscherColorRef.SysIndexSource;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

public class Demo06 {
	public static void main(String[] args) {
		Demo06 demo06= new Demo06();
		demo06.writeExlByJxl();
	}
	
	private void writeExlByJxl() {
		// TODO Auto-generated method stub
		WritableWorkbook book= null;
		String[] info= {"序号", "学号", "姓名", "性别", "年龄", "学历", "学校"};
		String fileName= System.getProperty("user.dir") + "\\data\\newStudents.xls";
		try {
			book= Workbook.createWorkbook(new File(fileName));
			WritableSheet sheet= book.createSheet("NewStudents.xls", 0);
			
			for(int i=0; i<7; i++) {//添加表头
				Label lable= new Label(i, 0, info[i]);
				sheet.addCell(lable);
			}
			
			sheet.addCell(new Label(0, 1, "1"));
			sheet.addCell(new Label(1, 1, "WNC115"));
			sheet.addCell(new Label(2, 1, "吴建波"));
			sheet.addCell(new Label(3, 1, "男"));
			sheet.addCell(new Label(4, 1, "28"));
			sheet.addCell(new Label(5, 1, "本科"));
			sheet.addCell(new Label(6, 1, "四川理工学院"));
			
			book.write();
			book.close();
		} catch (RowsExceededException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (WriteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}
}

 

【自动化__持续集成】___java___excel__jxl写

标签:str   ble   source   stack   rac   except   file   add   new   

原文地址:http://www.cnblogs.com/wujianbo123/p/7492188.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!