java读取excle ,读取列名、读取第一行

1.读取整个excle列名字

try {
			//构建Workbook对象, 只读Workbook对象
			  //直接从本地文件创建Workbook
	        //从输入流创建Workbook
	        InputStream is = new FileInputStream(url);
	        Workbook rwb;
			rwb = Workbook.getWorkbook(is);
			 //获得工作薄(Workbook)中工作表(Sheet)的个数
	        int sheetNum = rwb.getNumberOfSheets();
	        //String sheetName = rwb.getSheet(0);.getName();
	                  
	        //获取第一张Sheet表
	        Sheet rs = rwb.getSheet(0);
	        //获取第一行,第一列的值
//	      Cell c00 = rs.getCell(0, 0); //getCell(列,行)
//	      String strc00 = c00.getContents();
	                     
	        System.out.println("工作薄中Sheet的个数: "+ sheetNum);
	                     
	        //输出sheet名
	        System.out.print("sheet :");
	        for(int i=0;i

 2.读取excle内容第一行

try {
			//构建Workbook对象, 只读Workbook对象
			  //直接从本地文件创建Workbook
	        //从输入流创建Workbook
	        InputStream is = new FileInputStream(url);
	        Workbook rwb;
			rwb = Workbook.getWorkbook(is);
			 //获得工作薄(Workbook)中工作表(Sheet)的个数
	        int sheetNum = rwb.getNumberOfSheets();
	        //String sheetName = rwb.getSheet(0);.getName();
	                  
	        //获取第一张Sheet表
	        Sheet rs = rwb.getSheet(0);
	        //获取第一行,第一列的值
//	      Cell c00 = rs.getCell(0, 0); //getCell(列,行)
//	      String strc00 = c00.getContents();
	                     
	        System.out.println("工作薄中Sheet的个数: "+ sheetNum);
	                     
	        //输出sheet名
	        System.out.print("sheet :");
	        for(int i=0;i

 

你可能感兴趣的:(java)