當前位置: 首頁>>代碼示例>>Java>>正文


Java HSSFDateUtil.getJavaDate方法代碼示例

本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFDateUtil.getJavaDate方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFDateUtil.getJavaDate方法的具體用法?Java HSSFDateUtil.getJavaDate怎麽用?Java HSSFDateUtil.getJavaDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.poi.hssf.usermodel.HSSFDateUtil的用法示例。


在下文中一共展示了HSSFDateUtil.getJavaDate方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCellValue

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入方法依賴的package包/類
public String getCellValue(Cell cell) {
	if (cell == null)
		return ExcelODAConstants.EMPTY_STRING;

	if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
		return resolveFormula(cell);
	}

	if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
		if(	HSSFDateUtil.isCellDateFormatted(cell) ){		
			Date myjavadate =  HSSFDateUtil.getJavaDate(cell.getNumericCellValue());
			return sdf.format( myjavadate );
		}
		return ((Double) cell.getNumericCellValue()).toString();
	}

	return cell.toString();
}
 
開發者ID:eclipse,項目名稱:birt,代碼行數:19,代碼來源:ExcelFileReader.java

示例2: getCellValue

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入方法依賴的package包/類
/**
 * 獲取單元格值
 *
 * @param row    獲取的行
 * @param column 獲取單元格列號
 * @return 單元格值
 */
public Object getCellValue(Row row, int column) {
    Object val = "";
    try {
        Cell cell = row.getCell(column);
        if (cell != null) {
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                // val = cell.getNumericCellValue();
                // 當excel 中的數據為數值或日期是需要特殊處理
                if (HSSFDateUtil.isCellDateFormatted(cell)) {
                    double d = cell.getNumericCellValue();
                    Date date = HSSFDateUtil.getJavaDate(d);
                    SimpleDateFormat dformat = new SimpleDateFormat(
                            "yyyy-MM-dd");
                    val = dformat.format(date);
                } else {
                    NumberFormat nf = NumberFormat.getInstance();
                    nf.setGroupingUsed(false);// true時的格式:1,234,567,890
                    val = nf.format(cell.getNumericCellValue());// 數值類型的數據為double,所以需要轉換一下
                }
            } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                val = cell.getStringCellValue();
            } else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
                val = cell.getCellFormula();
            } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
                val = cell.getBooleanCellValue();
            } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) {
                val = cell.getErrorCellValue();
            }
        }
    } catch (Exception e) {
        return val;
    }
    return val;
}
 
開發者ID:sombie007,項目名稱:ExcelHandle,代碼行數:42,代碼來源:ImportExcel.java

示例3: extractCell

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入方法依賴的package包/類
static protected Serializable extractCell(org.apache.poi.ss.usermodel.Cell cell) {
        int cellType = cell.getCellType();
        if (cellType == org.apache.poi.ss.usermodel.Cell.CELL_TYPE_FORMULA) {
            cellType = cell.getCachedFormulaResultType();
        }
        if (cellType == org.apache.poi.ss.usermodel.Cell.CELL_TYPE_ERROR ||
            cellType == org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK) {
            return null;
        }
        
        Serializable value = null;
        if (cellType == org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BOOLEAN) {
            value = cell.getBooleanCellValue();
        } else if (cellType == org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC) {
            double d = cell.getNumericCellValue();
            
            if (HSSFDateUtil.isCellDateFormatted(cell)) {
                value = HSSFDateUtil.getJavaDate(d);
                // TODO: If we had a time datatype, we could use something like the following
                // to distinguish times from dates (although Excel doesn't really make the distinction)
                // Another alternative would be to look for values < 0.60
//                String format = cell.getCellStyle().getDataFormatString();
//                if (!format.contains("d") && !format.contains("m") && !format.contains("y") ) {
//                    // It's just a time
//                }
            } else {
                value = d;
            }
        } else {
            String text = cell.getStringCellValue();
            if (text.length() > 0) {
                value = text;
            }
        }
        
        return value;
    }
 
開發者ID:dfci-cccb,項目名稱:mev,代碼行數:38,代碼來源:ExcelImporter.java

示例4: parseXLS

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入方法依賴的package包/類
public JSONObject parseXLS(String filename, int sheetNo) throws FileNotFoundException, IOException, JSONException{
            JSONObject jobj=new JSONObject();
                    POIFSFileSystem fs      =
            new POIFSFileSystem(new FileInputStream(filename));
            HSSFWorkbook wb = new HSSFWorkbook(fs);
            HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);
            HSSFSheet sheet = wb.getSheetAt(sheetNo);

            int startRow=0;
            int maxRow=sheet.getLastRowNum();
            int maxCol=0;
            int noOfRowsDisplayforSample = 20;
            if(noOfRowsDisplayforSample > sheet.getLastRowNum()){
                noOfRowsDisplayforSample = sheet.getLastRowNum();
            }

            JSONArray jArr=new JSONArray();
            try {
                for(int i=0;i <= noOfRowsDisplayforSample;i++) {
                    HSSFRow row = sheet.getRow(i);
                    JSONObject obj=new JSONObject();
                    JSONObject jtemp1 = new JSONObject();
                    if(row==null){
                        continue;
                    }
                    if(i==0) {
                        maxCol=row.getLastCellNum();
                    }
                    for(int cellcount=0; cellcount<maxCol; cellcount++){
                        HSSFCell cell = row.getCell(cellcount);
                        CellReference cref = new CellReference(i, cellcount);
                        String colHeader=cref.getCellRefParts()[2];
                        String val=null;
                        if(cell!=null){
                            switch(cell.getCellType()){
                                case HSSFCell.CELL_TYPE_NUMERIC: 
                                     if(HSSFDateUtil.isCellDateFormatted(cell)){
                                        val=Double.toString(cell.getNumericCellValue());
                                        java.util.Date date1 = HSSFDateUtil.getJavaDate(Double.parseDouble(val));
                                        DateFormat sdf = new SimpleDateFormat(df);
                                        val = sdf.format(date1);
                                     }else{
                                        val=dfmt.format(cell.getNumericCellValue());
                                     }
                                     break;
                                case HSSFCell.CELL_TYPE_STRING: val=cleanHTML(cell.getRichStringCellValue().getString()); break;
                            }
                        }
                        
                        if(i==0){ // List of Headers (Consider first row as Headers)
                            if(val!=null){
                                jtemp1 = new JSONObject();
                                jtemp1.put("header", val==null?"":val);
                                jtemp1.put("index", cellcount);
                                jobj.append("Header", jtemp1);
                            }
                        }
                        obj.put(colHeader,val);
                    }
//                    if(obj.length()>0){ //Don't show blank row in preview grid[SK]
                        jArr.put(obj);
//                    }
                }
            } catch(Exception ex) {
               Logger.getLogger(ImportHandler.class.getName()).log(Level.SEVERE, null, ex);
            }
            jobj.put("startrow", startRow);
            jobj.put("maxrow", maxRow);
            jobj.put("maxcol", maxCol);
            jobj.put("index", sheetNo);
            jobj.put("data", jArr);
            jobj.put("filename", filename);

            jobj.put("msg", "XLS has been successfully uploaded");
            jobj.put("lsuccess", true);
            jobj.put("valid", true);
            return jobj;
    }
 
開發者ID:mobilipia,項目名稱:Deskera-HRMS,代碼行數:79,代碼來源:ImportHandler.java

示例5: parseXLS1

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入方法依賴的package包/類
public JSONObject parseXLS1(String filename, int sheetNo,int startindex) throws FileNotFoundException, IOException, JSONException{
        JSONObject jobj=new JSONObject();
                POIFSFileSystem fs      =
        new POIFSFileSystem(new FileInputStream(filename));
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);
        HSSFSheet sheet = wb.getSheetAt(sheetNo);
        ArrayList<String> arr = new ArrayList<String>();
        int startRow=0;
        int maxRow=sheet.getLastRowNum();
        int maxCol=0;

        JSONArray jArr=new JSONArray();
        try {
            for(int i=startindex;i<=sheet.getLastRowNum();i++) {
                HSSFRow row = sheet.getRow(i);
                JSONObject obj=new JSONObject();
                JSONObject jtemp1 = new JSONObject();
                if(row==null){
                    continue;
                }
                if(i==startindex){
                    maxCol=row.getLastCellNum();
                }
                for(int j=0; j<maxCol; j++){
                    HSSFCell cell = row.getCell(j);
                    String val=null;
                    if(cell==null){
                           arr.add(val);
                           continue;
                    };
                    String colHeader=new CellReference(i, j).getCellRefParts()[2];
                    switch(cell.getCellType()){
                        case HSSFCell.CELL_TYPE_NUMERIC: 
                             if(HSSFDateUtil.isCellDateFormatted(cell)){
                                val=Double.toString(cell.getNumericCellValue());
                                java.util.Date date1 = HSSFDateUtil.getJavaDate(Double.parseDouble(val));
                                DateFormat sdf = new SimpleDateFormat(df);
                                val = sdf.format(date1);
                             }else{
                                val=dfmt.format(cell.getNumericCellValue());
                             }
                             break;
                        case HSSFCell.CELL_TYPE_STRING: val=cleanHTML(cell.getRichStringCellValue().getString()); break;
                    }
                    if(i==startindex){ // List of Headers (consider startindex row as a headers)
                        if(val!=null){
                        jtemp1 = new JSONObject();
                        jtemp1.put("header", val);
                        jtemp1.put("index", j);
                        jobj.append("Header", jtemp1);
                        obj.put(colHeader,val);
                        }
                        arr.add(val);
                    } else {
                        if(arr.get(j)!=null)
                            obj.put(arr.get(j),val);
                    }

                }
                if(obj.length()>0){
                jArr.put(obj);
            }

            }
        } catch(Exception ex) {
           Logger.getLogger(ImportHandler.class.getName()).log(Level.SEVERE, null, ex);
        }
        jobj.put("startrow", startRow);
        jobj.put("maxrow", maxRow);
        jobj.put("maxcol", maxCol);
        jobj.put("index", sheetNo);
        jobj.put("data", jArr);
        jobj.put("filename", filename);

        jobj.put("msg", "XLS has been successfully uploaded");
        jobj.put("lsuccess", true);
        jobj.put("valid", true);
        return jobj;
}
 
開發者ID:mobilipia,項目名稱:Deskera-HRMS,代碼行數:81,代碼來源:ImportHandler.java

示例6: readNext

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入方法依賴的package包/類
/**
 * @see fll.util.CellFileReader#readNext()
 */
@SuppressFBWarnings(value = "PZLA_PREFER_ZERO_LENGTH_ARRAYS", justification = "Return null rather than zero length array so that we know when we hit EFO")
public String[] readNext() throws IOException {
  if (lineNumber >= sheet.getLastRowNum()) {
    return null;
  }

  ++lineNumber;
  final Row row = sheet.getRow(lineNumber);
  if (null == row) {
    return new String[0];
  }

  final List<String> data = new LinkedList<String>();
  for (int cellIdx = 0; cellIdx < row.getLastCellNum(); ++cellIdx) {
    final Cell cell = row.getCell(cellIdx, Row.RETURN_NULL_AND_BLANK);
    if (null == cell) {
      data.add(null);
    } else {
      final String str;
      if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        final double d = cell.getNumericCellValue();
        // test if a date!
        if (HSSFDateUtil.isCellDateFormatted(cell)) {
          // make sure to format times like we expect them
          final Date date = HSSFDateUtil.getJavaDate(d);
          str = TournamentSchedule.DATE_FORMAT_AM_PM_SS.get().format(date);
        } else {
          // check for integer
          if (FP.equals(d, Math.round(d), 1e-10)) {
            str = String.valueOf((int) d);
          } else {
            str = formatter.formatCellValue(cell, formulaEvaluator);
          }
        }
      } else {
        str = formatter.formatCellValue(cell, formulaEvaluator);
      }
      data.add(str);
    }
  }
  return data.toArray(new String[data.size()]);
}
 
開發者ID:jpschewe,項目名稱:fll-sw,代碼行數:46,代碼來源:ExcelCellReader.java

示例7: toDate

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入方法依賴的package包/類
@Override
public Date toDate() {
	return value == null ? null : HSSFDateUtil.getJavaDate(toDouble());
}
 
開發者ID:yu-ki106f,項目名稱:PoiManager,代碼行數:5,代碼來源:PoiNumberConverter.java

示例8: getDateCellValue

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入方法依賴的package包/類
/**
 * Get the value of the cell as a date. For strings we throw an exception. For
 * blank cells we return a null.
 *
 * @return the value of the cell as a date
 * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is CELL_TYPE_STRING
 * @throws NumberFormatException if the cell value isn't a parsable <code>double</code>.
 */
@Override
public Date getDateCellValue() {
  if(getCellType() == CELL_TYPE_STRING){
    throw new IllegalStateException("Cell type cannot be CELL_TYPE_STRING");
  }
  return rawContents == null ? null : HSSFDateUtil.getJavaDate(getNumericCellValue(), use1904Dates);
}
 
開發者ID:monitorjbl,項目名稱:excel-streaming-reader,代碼行數:16,代碼來源:StreamingCell.java


注:本文中的org.apache.poi.hssf.usermodel.HSSFDateUtil.getJavaDate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。