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

net.sf.jxls.reader.DateConverter Maven / Gradle / Ivy

Go to download

jXLS is a small and easy-to-use Java library for generating Excel files using XLS templates

There is a newer version: 1.0.6
Show newest version
package net.sf.jxls.reader;

import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
import org.apache.poi.ss.usermodel.DateUtil;

/**
 * @author Leonid Vysochyn
 * @version 1.0 Jul 29, 2007
 */
public class DateConverter implements Converter {
    public Object convert(Class type, Object value) {
        if( value == null ) {
            throw new ConversionException("No value specified");
        }
        double date;
        if( value instanceof Double ){
            date = ((Double)value).doubleValue();
        }else if( value instanceof Number){
            date = ((Number)value).doubleValue();
        }else if( value instanceof String ){
            try {
                date = Double.parseDouble( (String)value );
            } catch (NumberFormatException e) {
                throw new ConversionException(e);
            }
        }else if(value instanceof java.util.Date) {
            return value;
        }else{
            throw new ConversionException("No value specified");
        }
        return DateUtil.getJavaDate( date );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy