Duvida - Jakarta Poi Retorno de um CEP

2 respostas
MarcoQuadros030810

Boa tarde.

Estou com o seguinte problema...
Tenho uma aplicação para pegar um excel e mandar para uma base na web.

porem tenho uma coluna nese arquivo XLS que´é um CEP.
mais ela nao tem pontos nem traços.

mais o poi so consegue pegar o valor se for com getNumericCellValue();

preciso guardar esses valores em uma String.

mais quando eu converto o double para a String ele me retorna algo assim

7.802842E7 sendo que preciso do formato como esta la 78028420
que é um CEP.

segue o codigo.

public static void main(String[] args) throws FileNotFoundException, IOException {
        
        FileInputStream f = new FileInputStream("c:/PADRAO.xls");
        
        HSSFWorkbook wb = new HSSFWorkbook(f);
        
        HSSFSheet sheet = wb.getSheet("512Kbps");
        
        String t = "";
        
        for (int j = 0; j < 3; j++) {
            
            HSSFRow row = sheet.getRow(j);
            
            for (int i = 0; i < 6; i++) {
                HSSFCell cell = row.getCell(i);
                
                if(cell.getCellType() == 3){
                    t = "\t";
                }else if(cell.getCellType() == 1){
                    t  = cell.getStringCellValue();
                }else if(cell.getCellType() == 0){
                    t = String.valueOf(cell.getNumericCellValue());
                }else{
                    t = cell.getDateCellValue().toString();
                }
                
                System.out.print(t + "\t");
            }
            System.out.print("\n");
        }
    }

ja fiz os testes de tipos de dados das celulas para poder saber o que pegar para nao dar exessão.

alguem sabe como posso resolver isso???

Att

Marco Quadros

2 Respostas

MarcoQuadros030810

Problema resolvido

public static void main(String[] args) throws FileNotFoundException, IOException {
        
        FileInputStream f = new FileInputStream("c:/PADRAO.xls");
        
        HSSFWorkbook wb = new HSSFWorkbook(f);
        
        HSSFSheet sheet = wb.getSheet("512Kbps");
        
        String t = "";
        
        NumberFormat nf = NumberFormat.getNumberInstance();  
        
        for (int j = 0; j < 3; j++) {
            
            HSSFRow row = sheet.getRow(j);
            
            for (int i = 0; i < 6; i++) {
                HSSFCell cell = row.getCell(i);
                
                if(cell.getCellType() == 3){
                    t = "\t";
                }else if(cell.getCellType() == 1){
                    t  = cell.getStringCellValue();
                }else if(cell.getCellType() == 0){
                    //formatar duble e remove os pontos
                    t = String.valueOf(nf.format(cell.getNumericCellValue())).replaceAll("\\.", "");
                }else{
                    t = cell.getDateCellValue().toString();
                }
                
                System.out.print(t + "\t");
            }
            System.out.print("\n");
        }
    }
gbvbahia01

Muito obrigado!!! Ajudou um cara que estava com problemas e estava com preguiça de ler documentação!!!
:lol: :idea:

Criado 21 de dezembro de 2011
Ultima resposta 4 de abr. de 2012
Respostas 2
Participantes 2