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 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









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
result problem
result problem  sir,i have written program given below but that program is not giving proper output.pls help me import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*;ADS_TO_REPLACE_1 class
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=Set - Java Beginners
Result=Set  Hi Friend, Can u tell how to get the count of records. in a select operation like sqlstmt="SELECT * FROM search_log_tab WHERE... result set, first move the pointer from first record to last record and get
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
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
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
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
getting result in table dynamically - Struts
getting result in table dynamically  How do i get result in tabular format dynamically using our own tags
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 '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
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
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
how to write in xml? - XML
how to write in xml?  can anybody give the code how to write in xml file. i wan to write inside the tag, so what i have to do? Thanks...  ...) tFormer.setOutputProperty(OutputKeys.METHOD, "text"); // Write the document to a file
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
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
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, 
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
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 ADS_TO_REPLACE_1
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
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
Result Set one to many mapping
Result Set one to many mapping  Suppose there are 5 tables in database named A,B,C,D and E. A has one to many relationship with B,C,D and D has one... Suppose result contains single entry of One record for A, Two records for B
A Java Program That Prints Out Result Via Printer
A Java Program That Prints Out Result Via Printer  A Java Program That Prints Out Result Through Printer Depending upon paper size , and print the calculated result on printer and save result as text file
write a java program
write a java program  write a program to print '*' in a circular form
write data to plist
write data to plist  How to write data to plist file in XCode
JSP - Problem of displaying result at webpage
JSP - Problem of displaying result at webpage  Can anyone please help to solve my problem below. My webpage has problem in displaying result position. The result should be display below my title. How do i solve it? Thank you so
how can i display a editable result of form?
how can i display a editable result of form?  how can i display a editable result of form? i know how to display form result but the result... to display form result in same page i have alredy created a hidden div which
How to write a program count total prices
How to write a program count total prices  Hi. all I've got a assignment to write a program that count total prices of 8 costumers. class PriceCalculator{ public void method(double quantity) { double result
How to write Java Program
How to write Java Program  how to write a program to find average of 5 student marks
Write String in Word document
Write String in Word document  How to read and write strings in word document
Write data in doc file
Write data in doc file  How to write data or string in word file
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java. Please suggest and give example of this program. thanks
Stream Result example
Stream Result example Stream Result is very important for allowing users to downloading contents. It is a custom result type for sending raw data via... file name. An Example of Stream Result is given below page.jspADS_TO_REPLACE_3
ModuleNotFoundError: No module named 'colcon-lcov-result'
ModuleNotFoundError: No module named 'colcon-lcov-result'  Hi, My... named 'colcon-lcov-result' How to remove the ModuleNotFoundError: No module named 'colcon-lcov-result' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'colcon-lcov-result'
ModuleNotFoundError: No module named 'colcon-lcov-result'  Hi, My... named 'colcon-lcov-result' How to remove the ModuleNotFoundError: No module named 'colcon-lcov-result' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'colcon-lcov-result'
ModuleNotFoundError: No module named 'colcon-lcov-result'  Hi, My... named 'colcon-lcov-result' How to remove the ModuleNotFoundError: No module named 'colcon-lcov-result' error? Thanks   Hi, In your

Ads