ylx 7 years ago
parent
commit
4c7f56543b
1 changed files with 55 additions and 17 deletions
  1. 55 17
      ccb_fund_trusteeship/src/main/java/com/fuzamei/utils/ExcelUtil.java

+ 55 - 17
ccb_fund_trusteeship/src/main/java/com/fuzamei/utils/ExcelUtil.java

@@ -17,29 +17,34 @@ import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
+import com.mchange.util.AssertException;
+
 public class ExcelUtil {
+	private ExcelUtil(){
+		throw new AssertException("instaniation is not permitted");
+	}
 	
-	public static final boolean matchExcel(File file1,File file2){
+	public static final boolean matchExcel(File file1,File file2,Column...c){
 		boolean flag=false;
-		InputStream is=null;
+		InputStream is1=null;
 		InputStream is2=null;
-		Workbook wb=null;
+		Workbook wb1=null;
 		Workbook wb2=null;
 		try {
-			is = new FileInputStream(file1);
+			is1 = new FileInputStream(file1);
 			is2 = new FileInputStream(file2);
-		} catch (FileNotFoundException e2) {
+		} catch (FileNotFoundException e) {
 			throw new RuntimeException("未找到文件");
 		}
 		try {
-			wb=new XSSFWorkbook(is);
+			wb1=new XSSFWorkbook(is1);
 		} catch (IOException e) {
 			try {
-				wb=new HSSFWorkbook(is);
+				wb1=new HSSFWorkbook(is1);
 			} catch (IOException e1) {
 				throw new RuntimeException("非Excel文件");
 			}finally{
-				closeStream(wb,wb2,is,is2);
+				closeStream(wb1,wb2,is1,is2);
 			}
 		}
 		try {
@@ -50,25 +55,30 @@ public class ExcelUtil {
 			} catch (IOException e1) {
 				throw new RuntimeException("非Excel文件");
 			}finally{
-				
+				closeStream(wb2,is2);
 			}
 		}
-		Sheet sheet = wb.getSheet("Sheet1");
+		Sheet sheet1 = wb1.getSheet("Sheet1");
 		Sheet sheet2 = wb2.getSheet("Sheet1");
-		Row row = sheet.getRow(1);
+		Row row1 = sheet1.getRow(1);
 		Row row2 = sheet2.getRow(1);
-		Cell cell = row.getCell(0);
+		Cell cell1 = row1.getCell(0);
 		Cell cell2 = row2.getCell(0);
-		double numericCellValue = cell.getNumericCellValue();
+		double numericCellValue1 = cell1.getNumericCellValue();
 		double numericCellValue2 = cell2.getNumericCellValue();
-		flag = (numericCellValue==numericCellValue2);
+		flag = (numericCellValue1==numericCellValue2);
 		
-		closeStream(wb,wb2,is,is2);
+		closeStream(wb1,wb2,is1,is2);
 		
 		return flag;
 	}
 	
-	private static final void closeStream(Closeable...c){
+	//要改的
+	public static final boolean matchExcel(File file1,File file2){
+		return false;
+	}
+	
+	private static final void closeStream(Closeable...c){//关闭流的内部方法
 		for (Closeable closeable : c) {
 			if(closeable!=null){
 				try {
@@ -80,8 +90,36 @@ public class ExcelUtil {
 		}
 	}
 	
-	public static void main(String[] args) {
+	private class Column{
+		private Integer colPos;	//列的位数
+		private Integer fromRow;//从第几行开始
+		private Integer toRow;	//到第几行为止
+		public Column(int colPos,int fromRow,int toRow) {
+			this.colPos=colPos;
+			this.fromRow=fromRow;
+			this.toRow=toRow;
+		}
+		public Integer getColPos() {
+			return colPos;
+		}
+		public Integer getFromRow() {
+			return fromRow;
+		}
+		public Integer getToRow() {
+			return toRow;
+		}
+		
+	}
+	
+	public static void main(String[] args) throws Exception{
 		File file=new File("C:\\Users\\fuzamei\\Desktop\\估值核算表.xlsx");
+		FileInputStream fis = new FileInputStream(file);
+		Workbook wb=new XSSFWorkbook(fis);
+		Sheet sheet = wb.getSheetAt(0);
+		Row row = sheet.getRow(2);
+		Cell cell = row.getCell(5);
+//		System.out.println(cell.getStringCellValue());
+		System.out.println(cell.getRichStringCellValue());
 	}