jxl实现java读写excel

使用jxl对excel文件进行简单的读写操作。

//    读excel文件中的数据在控制台输出
public class readExcel {
	public static void main(String[] args) throws IOException, BiffException {
		// 1.获取工作簿
		File file = new File("C:\\\\Users\\\\Administrator\\\\Desktop\\\\practise.xls");
		Workbook wb = Workbook.getWorkbook(file);
		// 2.获取sheet页
		Sheet sheet = wb.getSheet("student");
		// 3.获取单元格数据
		Cell cell = null;
		// getRows获取行数    getColumns获取列数
		for (int i = 0; i < sheet.getRows(); i++) {
			for (int j = 0; j < sheet.getColumns(); j++) {
				cell = sheet.getCell(j, i);
				System.out.print(cell.getContents() + "\t");
			}
			System.out.println("");
		}
	}
}
//将数据写入excel文件中
public class writeExcel {
	public static void main(String[] args) throws IOException, BiffException, RowsExceededException, WriteException {
		//定位到user文件,不存在时创建一个
		File file = new File("C:\\\\Users\\\\Administrator\\\\Desktop\\\\user.xls");
		if (!file.exists()) {
			file.createNewFile();
		}
		// 1.创建工作簿
		WritableWorkbook wb = Workbook.createWorkbook(file);
		// 2.创建sheet页
		WritableSheet sheet = wb.createSheet("student", 0);
		// 3.创建单元格并写入
		Label label1 = new Label(0, 0, "id");
		Label label2 = new Label(1, 0, "name");
		Label label3 = new Label(2, 0, "score");
		sheet.addCell(label1);
		sheet.addCell(label2);
		sheet.addCell(label3);
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值