2017-12-30 17 views
0

소수점 이하 다섯 자리가 포함 된 셀에 내용을 인쇄하려고하면 자동으로 숫자가 3d.p로 반올림됩니다. 셀 유형을 검사 한 후JXL API 문제 : 실제 숫자 대신 십진수를 반올림 한 표준 출력 표시

Cell cellNum = sheet1.getCell(col,row); 
      WritableCell cell = sheet1.getWritableCell(col, row); 
      if (cell.getType() == CellType.NUMBER){ 
       cellNum = sheet1.getCell(col,row); 
       NumberFormat fivedps = new NumberFormat("#.#####"); 
       WritableCellFormat cellFormat = new WritableCellFormat(fivedps); 
       cell.setCellFormat(cellFormat); 


       String cellContent = cellNum.getContents(); 
       System.out.print(cellContent + "\t"); 
      } 
      else{ 
       // Cell cellNum = sheet1.getCell(col,row); 

       String cellContent = cellNum.getContents(); 
       System.out.print(cellContent + "\t"); 

답변

0

을하고 유형 번호의 경우, 다음 값의 읽을 NumberCell에 셀 캐스트 : 이것은 내가 지금까지 가지고있는 것입니다. 당신이 공유 예를 들어, 결과는 아래와 같습니다 :

당신은 DateCell에 캐스팅으로 같은 날짜로 다른 값을 읽을 유사한 기술을 사용할 수 있습니다
if (cell.getType() == CellType.NUMBER){ 
    NumberCell cellNum = (NumberCell) sheet1.getCell(col,row); 
    System.out.println(cellNum.getValue()); //this will return a double value 
} 

. 희망이 도움이!

+0

정말 고마워요. 그것은 효과가있다! 표시된 값은 스프레드 시트의 값과 동일합니다. –