All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.excel.tools.setter.LocalDateTimeValueSetter Maven / Gradle / Ivy

The newest version!
package me.excel.tools.setter;

import me.excel.tools.importer.ExcelImportException;
import me.excel.tools.model.excel.ExcelCell;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static me.excel.tools.FieldUtils.detectRealField;

/**
 * local date time field value setter
 * 

* Created by hanwen on 5/3/16. */ public class LocalDateTimeValueSetter extends FieldValueSetterAdapter { private static final Logger LOGGER = LoggerFactory.getLogger(LocalDateTimeValueSetter.class); private String pattern; public LocalDateTimeValueSetter(String matchField, String pattern) { super(matchField); this.pattern = pattern; } @Override public void set(Object data, ExcelCell excelCell) { try { DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(pattern); String value = excelCell.getValue(); PropertyUtils.setProperty(data, detectRealField(excelCell.getField()), value == null ? null : dateTimeFormatter.parseLocalDateTime(value)); } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); throw new ExcelImportException(e); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy