1. 程式人生 > >POI讀寫資料 相容HSSF和XSSF

POI讀寫資料 相容HSSF和XSSF

	//poi資料型別處理
		try {//WorkbookFactory相容HSSF(2003)和XSSF(2007)
			Workbook wb = WorkbookFactory.create(new FileInputStream(new File("D:\\測試.xlsx")));
			Sheet sheet = wb.getSheetAt(0);
			Row row = sheet.getRow(0);
			Cell cell = row.getCell(0);
			cell.setCellType(Cell.CELL_TYPE_STRING);
			String phone = cell.getStringCellValue();
			Cell cell2=row.getCell(1);
			cell2.setCellType(Cell.CELL_TYPE_NUMERIC);
			Double d = cell2.getNumericCellValue();
			d = d*100; 
			System.out.println("double*:"+d.toString());
			BigDecimal b = new BigDecimal(d);
			b = b.multiply(new BigDecimal(100));
			System.out.println("bigDecimal*:"+b.toString());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}