jxl.write.DateFormat Java Examples

The following examples show how to use jxl.write.DateFormat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JExcelXLSDataFormatter.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Prepares cell format depending on field format and locale
 * 
 * @param field
 * @return
 */
@SuppressWarnings("deprecation")
private static WritableCellFormat getCellFormat(DataFieldMetadata field){
	if (!(field.getDataType().isNumeric() || field.getDataType() == DataFieldType.DATE || field.getDataType() == DataFieldType.DATETIME)){
		return null;
	}
	String format = field.getFormat();
	if (field.getDataType().isNumeric()) {
		return format != null ? new WritableCellFormat(new NumberFormat(format)) : null;
	}
	//DateDataField
	if (format != null) {
		return new WritableCellFormat(new DateFormat(format));
	}
	//format is null
	if (field.getLocaleStr() != null) {
		format = ((SimpleDateFormat) java.text.DateFormat.getDateInstance(java.text.DateFormat.DEFAULT,
						MiscUtils.createLocale(field.getLocaleStr()))).toPattern();
	}else{
		format = new SimpleDateFormat().toPattern();
	}
	return new WritableCellFormat(new DateFormat(format));
}