Export screen data to excel

Asked

Viewed 4,124 times

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 to save these two data at the end of the execution, because soon after the system started a new register creation.

I don’t know how to do this in Java, can anyone help me? I tried with Jsoup, but I couldn’t.

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

1 answer

2


You can use the Apache POI to create files xls.

//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);

    }
       }
   }
  • thanks for the help, but this giving some errors, Hssfrow and Hssfworkbook and Hssfsheet cannot be resolved to a type

  • You downloaded the JAR file?????

  • 1

    I downloaded yes and it worked, after I erase the copied code and write manually, will understand né rsrsrsrs Anyway thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.