leandroqbs 12 de set. de 2007
Pacato 28 de fev. de 2013
cara eu uso assim:
Pego o campo data do excel, formato ela e ainda verifico se o campo é vazio, por causa que eu uso em uma consulta no BD postgres onde para consultar uma data preciso por a condição IS NULL:
Eu pego os valores das células através de um ENUM, assim trato os dadoc om CASE
public enum TelecomCelulasEnum {
SIMCARD ( 0 ),
LINHA ( 1 ),
APN_UTILIZADA ( 2 ),
CONTA ( 3 ),
OPERADORA ( 4 ),
PLANO ( 5 ),
STATUS_SIM_CARD ( 6 ),
DATA_ATIVACAO ( 7 ),
FONTE ( 8 ),
STATUS_LINHA ( 9 ),
IMSI ( 10 ),
CONSUMO_DADOS ( 11 );
private int nuColuna ;
private TelecomCelulasEnum ( int nuColuna ) {
this . nuColuna = nuColuna ;
}
public static TelecomCelulasEnum obterCelulaTelecom ( int nuColuna ) {
TelecomCelulasEnum retorno = null ;
for ( TelecomCelulasEnum enumTelecom : TelecomCelulasEnum . values ()) {
if ( enumTelecom . getNuColuna () == nuColuna ) {
retorno = enumTelecom ;
}
}
return retorno ;
}
public int getNuColuna () {
return nuColuna ;
}
public void setNuColuna ( int nuColuna ) {
this . nuColuna = nuColuna ;
}
}
Aqui coloco na classe de verificar os dados…
public Date transformaData ( String data ) {
Date retorno = null ;
SimpleDateFormat formatador = new SimpleDateFormat ( "dd/MM/yyyy" );
try {
retorno = formatador . parse ( data );
} catch ( ParseException ex ) {
throw new RuntimeException ( ex );
}
return retorno ;
}
:
:
case DATA_ATIVACAO :
TimeZone gmtZone = TimeZone . getTimeZone ( "GMT" );
SimpleDateFormat format = new SimpleDateFormat ( "dd/MM/yyyy" );
format . setTimeZone ( gmtZone );
if ( celula . getContents () != null && celula . getContents () != "" ) {
DateCell dataCell = ( DateCell ) celula ;
String dataFormatada = format . format ( dataCell . getDate ());
linhaTelecom . setDtAtivacao ( transformaData ( dataFormatada ));
} else {
linhaTelecom . setDtAtivacao ( null );
}
break ;