Java 读写Excel文件

读Excel文件:

public void readExcel(){
		try {
			FileInputStream input = new FileInputStream("e://test.xls");
			HSSFWorkbook wb = new HSSFWorkbook(input);
			HSSFSheet sheet = wb.getSheetAt(0);
			HSSFRow row = sheet.getRow(0);
			HSSFCell cell = row.getCell(0);
			String value = cell.getStringCellValue();
			System.out.println("值是------------->"+value);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

 

写Excel文件

public void writeExcel(){
		try {
			FileOutputStream out = new FileOutputStream("e://test.xls");
			HSSFWorkbook wb = new HSSFWorkbook();
			HSSFSheet sheet = wb.createSheet();
			wb.setSheetName(0, "测试表格");
			HSSFRow row = sheet.createRow(0);
			HSSFCell cell = row.createCell(0);
			cell.setCellValue("我的第一个表格测试。");
			wb.write(out);
			out.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

 

 

 

 

 

你可能感兴趣的:(java,Excel)