2013-03-16 2 views
0

아파치 POI에 익숙하며 형식의 셀 열을 사용하고 있습니다. 이미 스프레드 시트를 값으로 생성했습니다. 형식을 mm에서 변경하는 것입니다. ss.0 ~ HH : MM : SS.Apache POI : 셀 열 서식을 지정하는 방법은 무엇입니까?

누군가이 코드를 포함하여 약간의 통찰력을 줄 수 있다면 매우 고맙겠습니다.

모든 도움을 환영합니다.

감사합니다.

답변

2

org.apache.poi.ss.usermodel.DateUtil

convertTime(java.lang.String timeStr) 
      Converts a string of format "HH:MM" or "HH:MM:SS" to its (Excel) numeric equivalent 

귀하의 요구 사항을 해결해야한다. 자세한 내용은 공부하십시오 - http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/DateUtil.html 또한

이 다음 프로그램이 당신에게 통찰력을 제공 여부를 확인하실 수 있습니다 -

+0

귀하의 빠른 응답 주셔서 감사합니다

import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; public class ExcelExample { public static void main(String[] args) { InputStream inp; try { inp = new FileInputStream("workbook.xls"); Workbook wb = new HSSFWorkbook(inp); CreationHelper createHelper = wb.getCreationHelper(); Sheet sheet = wb.getSheetAt(0); for (Row row : sheet) { Cell cell = row.getCell(1); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("hh:mm:ss")); cell.setCellStyle(cellStyle); } // Write the output to a file FileOutputStream fileOut = new FileOutputStream("workbook.xls"); wb.write(fileOut); fileOut.close(); System.out.println("Done..."); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } 

감사합니다, 나는 세포의 열을 대상으로 얼마나 형식을 적용할까요? 열이 "A"이고 전체 열에 형식을 적용하려고한다고 가정 해 보겠습니다. –

+0

내 대답을 편집했습니다 ... 당신은 그것을 확인할 수 있습니다 ... –

+0

고맙습니다!, 나는 올바른 것으로 표시했습니다. –

관련 문제