Export screen data to excel

0

I automated a customer registration test (performed on the web, internet explorer) and at the end it generates a protocol and another numeric code.

I need at the end of the execution to save these two data, because soon after the system started a new record creation.

I do not know how to do this in Java, can anyone help me? I tried with Jsoup, but I could not.

It can be in excel, txt, in any way that is simple to implement, recording in the same file or at each pass it generates a different file with the screen information, no problem ... I just can not lose these data at the end of the process.

    
asked by anonymous 07.05.2015 / 17:17

1 answer

2

You can use Apache POI to create xls files.

//Baixe o jar aqui "http://poi.apache.org/download.html"
    import  java.io.*;
    import  org.apache.poi.hssf.usermodel.HSSFSheet;
    import  org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import  org.apache.poi.hssf.usermodel.HSSFRow;
    import  org.apache.poi.hssf.usermodel.HSSFCell;

public class CreateExlFile{ // classe que gera o arquivo
     public static void main(String[]args){
         try{
            // local do arquivo
            String filename="C:/NewExcelFile.xls" ;
            HSSFWorkbook workbook=new HSSFWorkbook();
            HSSFSheet sheet =  workbook.createSheet("FirstSheet");  
            // criando as linhas
            HSSFRow rowhead=   sheet.createRow((short)0);
            rowhead.createCell(0).setCellValue("protocolo");
            rowhead.createCell(1).setCellValue("codigonumerico");
            // definindo seus valores
            // por exemplo protocolo.getProtocolo();
            HSSFRow row=   sheet.createRow((short)1);
            row.createCell(0).setCellValue(protocolo.getProtocolo());
            row.createCell(1).setCellValue(protocolo.getCodigoNumerico());

            FileOutputStream fileOut =  new FileOutputStream(filename);
            workbook.write(fileOut);
            fileOut.close();
            System.out.println("Seu arquivo excel foi gerado!");

    } catch ( Exception ex ) {
        System.out.println(ex);

    }
       }
   }
    
07.05.2015 / 17:27