write the result into excelsheet

Ads
 

write the result into excelsheet

package reader;

import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Vector;

import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.usermodel.Cell; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver;

public class ReadExcel { static String homeurl="http://192.168.5.19:79/Home.aspx";

public static void main( String [] args ) throws InterruptedException, IOException {

    String fileName="E:\\excellogin.xls";;
    //Read an Excel File and Store in a Vector
    Vector dataHolder=readExcelFile(fileName);
    //Print the data read
    printToConsole(dataHolder);

  //  writeDataToExcelFile(fileName);   
}
public static Vector readExcelFile(String fileName)

{

    /** --Define a Vector
        --Holds Vectors Of Cells
     */
    Vector cellVectorHolder = new Vector();
    List cellDataList = new ArrayList();

    try{
    /** Creating Input Stream**/
    //InputStream myInput= ReadExcelFile.class.getResourceAsStream( fileName );
    FileInputStream myInput = new FileInputStream(fileName);

    /** Create a POIFSFileSystem object**/
    POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);

    /** Create a workbook using the File System**/
     HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);

     /** Get the first sheet from workbook**/
    HSSFSheet mySheet = myWorkBook.getSheetAt(0);

    /** We now need something to iterate through the cells.**/
      Iterator rowIter = mySheet.rowIterator();


      while(rowIter.hasNext()){
          HSSFRow myRow = (HSSFRow) rowIter.next();
          Iterator cellIter = myRow.cellIterator();
          Vector cellStoreVector=new Vector();
          while(cellIter.hasNext()){
              HSSFCell myCell = (HSSFCell) cellIter.next();
              cellStoreVector.addElement(myCell);
          }
          cellVectorHolder.addElement(cellStoreVector);
      }

    }catch (Exception e){e.printStackTrace(); }

    return cellVectorHolder;
}

private static void printToConsole(List cellDataList) throws InterruptedException, IOException

{

for (int i = 1; i < cellDataList.size()+1; i++)

{

List cellTempList = (List) cellDataList.get(i);

//System.out.print(cellTempList + "\t");
final String sUrl = "http://192.168.5.19:79/ExATLogin.aspx?";
 WebDriver d1 = new InternetExplorerDriver();
 d1.get(sUrl);
HSSFCell hssfCell1 = (HSSFCell) cellTempList.get(0);
String stringCellValue1 = hssfCell1.toString();
System.out.print("UserName:" + stringCellValue1 + "\t");

d1.findElement(By.id("txt_UserName")).clear();
d1.findElement(By.id("txt_UserName")).sendKeys(stringCellValue1);

HSSFCell hssfCell = (HSSFCell) cellTempList.get(1);
String stringCellValue = hssfCell.toString();
System.out.print("Password:" + stringCellValue + "\t");
d1.findElement(By.id("txt_Password")).clear();
 d1.findElement(By.id("txt_Password")).sendKeys(stringCellValue);
 Thread.sleep(3000);
 d1.findElement(By.name("btn_Login")).click();  


 String  curUrl=d1.getCurrentUrl();
 System.out.println("\n");
       System.out.println(curUrl);

    if(homeurl.equals(curUrl)){
   System.out.println("Login successful");

       }
   else
          System.out.println("Login not successful");

    Thread.sleep(3000); 

}

}

private static void write1() throws IOException{

  FileInputStream file = new FileInputStream(new File("E:\\excellogin.xls"));

    HSSFWorkbook workbook = new HSSFWorkbook(file);
    HSSFSheet sheet = workbook.getSheetAt(0);
    Cell cell = null;
    Cell cell1 = null;
    Cell cell2 = null;
   int row=1;
   for(;row<5;row++){
       cell=sheet.getRow(row).getCell(0);
       cell1=sheet.getRow(row).getCell(1);
       if(cell.equals("superadmin") && cell1.equals("Exdion")){
            cell2 = sheet.getRow(row).getCell(2);
            cell2.setCellValue(cell.getStringCellValue().concat("pass"));
           }
       else{
            cell2 = sheet.getRow(row).getCell(2);
            cell2.setCellValue(cell.getStringCellValue().concat("fail"));  
       }
       }


    file.close();

    FileOutputStream outFile =new FileOutputStream(new File("E:\\excellogin.xls"));
    workbook.write(outFile);
    outFile.close();

}

}

my question is i want to wite the result in to the same excel file....... please help me. if username is superadmin and password is Exdion. then the status is pass othewise fail.

View Answers

Ads









Related Tutorials/Questions & Answers:
write the result into excelsheet
write the result into excelsheet  package reader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import... the result in to the same excel file....... please help me. if username is superadmin
Write a C/C++ program to show the result of a stored procedure
Write a C/C++ program to show the result of a stored procedure   how to write this?? Write a C/C++ program to show the result of a stored procedure "PROCRESETMAIL" on database "USER_NOTIFY
Advertisements
How to save database data into excelsheet using hibernate
How to save database data into excelsheet using hibernate  How to save database data into excelsheet using hibernate
how to upload a student time table excelsheet
how to upload a student time table excelsheet   Hi good morning iam beginer iam doing project using struts frame work backend as 10g xe front end as java .in my student module i have time table so how to upload excelsheet
display result
display result  i want a code that takes input from user through dropdown box and display the result into table.all the values regarding the user input must be displayed. i am using mysql database   hi i want study
ModuleNotFoundError: No module named 'result'
ModuleNotFoundError: No module named 'result'  Hi, My Python... 'result' How to remove the ModuleNotFoundError: No module named 'result'... to install padas library. You can install result python with following command
result after compilation
result after compilation  public class MainCls { public static void main(String argv) { System.out.println("My text
write spreadsheet
write spreadsheet  what is the java code to write a spreadsheet to database
write spreadsheet
write spreadsheet  what is the java code to write a spreadsheet to database
write a program
write a program  write a program add 2 no.s without use arithmetic,unary operaters in java
result analysis issue
result analysis issue  i have given 100 users in my thread group for http sampler.some threads r getting response and some threads r getting error response.the error response shown in view results tree listener is as shown below
Sort Result set
Sort Result set   I build a connect for my page with the database and then read all rows and show it in a table, I want to change the view of my data to be sorted uppon a specific column when click on the column name, so what
hide and show result in jsp
hide and show result in jsp  what codes do i have to change to make my result display if only i enter the correct value? suppose if i click search,then the result will be display at the bottom.. if not.. only the header
WRITE AND TEST
WRITE AND TEST   WRITE AND TEST PROGRAM TO ACCEPT A STRING? 1).WHICH STARTS WITH 'S' OR 's' 2).ENDS WITH "nd" 3) THE LENGTH OF THE STRING SHOULD BE 10 OR LESS
ModuleNotFoundError: No module named 'cdumay-result'
ModuleNotFoundError: No module named 'cdumay-result'  Hi, My... 'cdumay-result' How to remove the ModuleNotFoundError: No module named 'cdumay-result' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'cdumay-result'
ModuleNotFoundError: No module named 'cdumay-result'  Hi, My... 'cdumay-result' How to remove the ModuleNotFoundError: No module named 'cdumay-result' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'deferred-result'
ModuleNotFoundError: No module named 'deferred-result'  Hi, My... named 'deferred-result' How to remove the ModuleNotFoundError: No module named 'deferred-result' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'grep-result'
ModuleNotFoundError: No module named 'grep-result'  Hi, My Python... 'grep-result' How to remove the ModuleNotFoundError: No module named 'grep-result' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'result_py'
ModuleNotFoundError: No module named 'result_py'  Hi, My Python... 'result_py' How to remove the ModuleNotFoundError: No module named 'result... have to install padas library. You can install result_py python with following
ModuleNotFoundError: No module named 'result-quality'
ModuleNotFoundError: No module named 'result-quality'  Hi, My... named 'result-quality' How to remove the ModuleNotFoundError: No module named 'result-quality' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'thumbor_no_result'
ModuleNotFoundError: No module named 'thumbor_no_result'  Hi, My... named 'thumbor_no_result' How to remove the ModuleNotFoundError: No module named 'thumbor_no_result' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'typed-result'
ModuleNotFoundError: No module named 'typed-result'  Hi, My Python... 'typed-result' How to remove the ModuleNotFoundError: No module named 'typed-result' error? Thanks   Hi, In your python
how to export the query result in SQL Server to .csv file?
how to export the query result in SQL Server to .csv file?  how to write table data into CSV file using SQL SERVER 2008
Write to PDF
Write to PDF  Hi, Fairly new to this. I want to create a PDF file as a server call, with text/images sent to the app. Seeing that this will have to be a plugin, how do I go about making it a valid plugin for the server
Result interface in Struts 2.2.1
Result interface in Struts 2.2.1 Struts Result interface is a public interface of package com.opensymphony.xwork2. It extends Serializable interface. All the known classes such as PlainTextResult, ServletRedirectResult, 
Read Write
Read Write  Hi; How can I read certain line of say 10 text files and write to one text file   Java Read Multiple Files and store the data into another text file The given code reads all the text files of the directory
Write a program in java...
Write a program in java...  Hi, friends Please, can you help me? Q1: Write a program in java to simulate a calculator. Your program should take two... as a user wishes. Print the result up to two places of decimal. Q2: Ask the user
select result from three tables using sql.
select result from three tables using sql.  I want to get a result from three tables. i dont how to write the sql query. Please help me. "I want to display Name,Username and Product_Name where Id=007" table "register" Name
Ajax Write
Ajax Write       ajaxWrite is a web-based word processor that can read and write Microsoft Word and other standard document formats Read full Description
select Query result display problem
select Query result display problem  Hi, String SQL_QUERY ="from Cc"; Query query = session.createQuery(SQL_QUERY); for(Iterator it=query.iterate();it.hasNext();){ Object[] row = (Object[]) it.next
Php Sql Result
Php Sql Result This example illustrates how to display result on the browser and how to use the result in the php application. In this example we create a select query by using mysql_query method and stored it in the result variable

Ads