WritableWorkbook 生成excel

package com;
import java.io.File;
import java.io.IOException;

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 Test 
{
	public static void main(String args[]) throws IOException, RowsExceededException, WriteException
	{
		File f = new File("D:\\內部通訊錄.xls");

		f.createNewFile();
					

		WritableWorkbook wwb = null;
		wwb = Workbook.createWorkbook(f);   


		//創建Excel工作表 
		WritableSheet ws = wwb.createSheet("通訊錄", 0);//創建sheet
		
		ws.mergeCells(0, 0, 5, 1);//合併單元格(左列,左行,右列,右行)從第1行第1列到第2行第3列
		Label header = new Label(0, 0, "內部通訊錄"); 
		ws.addCell(header);//寫入頭
		Label l = new Label(0, 2, "姓名");//第3行
		ws.addCell(l);
		l = new Label(1, 2, "單位");
		ws.addCell(l);
		l = new Label(2, 2, "手機");
		ws.addCell(l);
		l = new Label(3, 2, "電話");
		ws.addCell(l);
		l = new Label(4, 2, "QQ");
		ws.addCell(l);
		l = new Label(5, 2, "郵箱");
		ws.addCell(l); 
		
		l = new Label(0, 3, "Realname");
		ws.addCell(l);
		l = new Label(1, 3, "UserDepart");
		ws.addCell(l);
		l = new Label(2, 3, "Hand_tel");
		ws.addCell(l);
		l = new Label(3, 3, "Telephone");
		ws.addCell(l);
		l = new Label(4, 3, "QQnumber");
		ws.addCell(l);
		l = new Label(5, 3, "E_mail");
		ws.addCell(l);
			 
				
				
		wwb.write();


		wwb.close();	
	}
				
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章