用pio解析excel的简单操作

1、从excel中读取数据

 

POIFSFileSystem fs = null; 
		HSSFWorkbook wb = null; 
		try { 
			
			fs = new POIFSFileSystem(new FileInputStream("d:\\test.xls")); 
		    wb = new HSSFWorkbook(fs); 
		    
		} catch (IOException e) { 
			
			e.printStackTrace(); 
		}
		HSSFSheet sheet = wb.getSheetAt(0); 
		HSSFRow row = sheet.getRow(0); 
		HSSFCell cell = row.getCell((short) 0); 
		String msg = cell.getStringCellValue();
		System.out.println(msg);

 2、向excel中写数据

 

		FileOutputStream fos = new FileOutputStream("d:\\test.xls"); 
		HSSFWorkbook wb = new HSSFWorkbook(); 
		HSSFSheet s = wb.createSheet(); 
		wb.setSheetName(0, "first sheet"); 
		HSSFRow row = s.createRow(0); 
		Short a =0;
		HSSFCell cell = row.createCell(a); 
		cell.setCellValue("Hello! This message is generated from POI."); 
		wb.write(fos); 
		fos.close(); 
 

 

你可能感兴趣的:(Excel)