java导入导出excel操作(jxl)

关键字: java excel jxl.jar

jxl.jar 包
下载地址:

真实下载地址:


网站上对它的特征有如下描述:
● 支持Excel 95-2000的所有版本
● 生成Excel 2000标准格式
● 支持字体、数字、日期操作
● 能够修饰单元格属性
● 支持图像和图表
应该说以上功能已经能够大致满足我们的需要。最关键的是这套API是纯Java的,并不依赖Windows系统,即使运行在Linux下,它同样能够正确的处理Excel文件。另外需要说明的是,这套API对图形和图表的支持很有限,而且仅仅识别PNG格式。
搭建环境
将下载后的文件解包,得到jxl.jar,放入classpath,安装就完成了。

基本操作

一、创建文件
拟生成一个名为“测试数据.xls”的Excel文件,其中第一个工作表被命名为“第一页”,大致效果如下:
Java代码

  1. /*
  2. * Created on Dec 30, 2007
  3. *
  4. * To change the template for this generated file go to
  5. * Window>Preferences>Java>Code Generation>Code and Comments
  6. */
  7. package JExcelTest.standard;
  8. import java.io.*;
  9. import jxl.*;
  10. import jxl.write.*;
  11. /**
  12. * @author Ken
  13. *
  14. * To change the template for this generated type comment go to
  15. * Window>Preferences>Java>Code Generation>Code and Comments
  16. */
  17. public class CreateXLS {
  18. public static void main(String[] args) {
  19. try {
  20. //open file.
  21. WritableWorkbook book = Workbook.createWorkbook(new File("d:/Test.xls"));
  22. //create Sheet named "Sheet_1". 0 means this is 1st page.
  23. WritableSheet sheet = book.createSheet("Sheet_1", 0);
  24. //define cell column and row in Label Constructor, and cell content write "test".
  25. //cell is 1st-Column,1st-Row. value is "test".
  26. Label label = new Label(0, 0, "test");
  27. //add defined cell above to sheet instance.
  28. sheet.addCell(label);
  29. //create cell using add numeric. WARN:necessarily use integrated package-path, otherwise will be throws path-error.
  30. //cell is 2nd-Column, 1st-Row. value is 789.123.
  31. jxl.write.Number number = new jxl.write.Number(1, 0, 789.123);
  32. //add defined cell above to sheet instance.
  33. sheet.addCell(number);
  34. //add defined all cell above to case.
  35. book.write();
  36. //close file case.
  37. book.close();
  38. } catch (Exception e) {
  39. e.printStackTrace();
  40. }
  41. }
  42. }
/*

 * Created on Dec 30, 2007

 *

 * To change the template for this generated file go to

 * Window>Preferences>Java>Code Generation>Code and Comments

 */

package JExcelTest.standard;



import java.io.*; 

import jxl.*; 

import jxl.write.*; 



/**

 * @author Ken

 *

 * To change the template for this generated type comment go to

 * Window>Preferences>Java>Code Generation>Code and Comments

 */

public class CreateXLS {



	public static void main(String[] args) {

		try {

			//open file.

			WritableWorkbook book =	Workbook.createWorkbook(new File("d:/Test.xls"));

			

			//create Sheet named "Sheet_1". 0 means this is 1st page.

			WritableSheet sheet = book.createSheet("Sheet_1", 0);

			

			//define cell column and row in Label Constructor, and cell content write "test".

			//cell is 1st-Column,1st-Row. value is "test".

			Label label = new Label(0, 0, "test");

			//add defined cell above to sheet instance.

			sheet.addCell(label);

			

			//create cell using add numeric. WARN:necessarily use integrated package-path, otherwise will be throws path-error.

			//cell is 2nd-Column, 1st-Row. value is 789.123.

			jxl.write.Number number = new jxl.write.Number(1, 0, 789.123);

			//add defined cell above to sheet instance.

			sheet.addCell(number);

			

			//add defined all cell above to case.

			book.write();

			//close file case.

			book.close();

		} catch (Exception e) {

			e.printStackTrace();

		}

	}

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值