java多线程    Java入门    vsftp    ftp    linux配置    centos    FRP教程    HBase    Html5缓存    webp    zabbix    分布式    neo4j图数据库    

java采用jxl写入一个Excel文件

jxl写入一个excel文件。

读取方面请看下面相关链接,上一遍是关于读取excel的。

package com.javaer.file;

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

import jxl.Workbook;
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 ExcelWrite {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws WriteException 
	 * @throws RowsExceededException 
	 */
	public static void main(String[] args) throws IOException, RowsExceededException, WriteException {
		String fname = "/1.xls";

		File f = new File(fname);
		
		WritableWorkbook wb=Workbook.createWorkbook(f);
		WritableSheet wsheet=wb.createSheet("第一页",0);
		
		WritableFont font1= new WritableFont(WritableFont.ARIAL,10,WritableFont.BOLD); 
		WritableCellFormat format1=new WritableCellFormat(font1);
		
		wsheet.addCell(new Label(0,0, "名字",format1));
		wsheet.addCell(new Label(1,0, "外号",format1));
		wsheet.addCell(new Label(2,0, "排行",format1));//前面那个2是表示列,后面的0表示当前行
		
		wsheet.addCell(new Label(0,1, "张三疯",format1));
		wsheet.addCell(new Label(1,1, "老鬼",format1));
		//wsheet.addCell(new Label(2,1, "1",format1));//前面那个2是表示列,后面的1表示当前行
		jxl.write.Number number = new jxl.write.Number(2,1,1 );//写入一个数字格式的。
		wsheet.addCell(number);
		
		wb.write();
		wb.close();
		
	
	}

}


This entry was posted in JAVA and tagged , . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/java-jxl-write-excel/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力.

Leave a Reply