Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners write the result into excelsheet
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


manasmita swain
write the result into excelsheet
0 Answer(s)      a year and 9 months ago
Posted in : Java Beginners


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.


Advertisement
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.*; class filedata extends
result after compilation
result after compilation  public class MainCls { public static void main(String argv) { System.out.println("My text
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
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
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, 
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
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
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... Result is given below page.jsp <%@ taglib prefix="s" uri="
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
Dispatcher Result Example
Dispatcher Result Example The Dispatcher Result forwarded the action... dispatcher in result you need to do the following mapping. <action name="dispatcherAction" class="....."> <result name="
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
Hibernate Criteria Setfirst Result
Hibernate Criteria SetFirstResult Result The setFirstResult of hibernate criteria API is used for setting no of records to be fetched from the table criteria.setFirstResult(1); An example of set first is given below
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 program
write a program  write a program add 2 no.s without use arithmetic,unary operaters in java
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
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 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
java.sql.SQLExceptioan: Before start of result set - JDBC
java.sql.SQLExceptioan: Before start of result set   java.sql.SQLException: Before start of result set?what do i do?   Hi Friend... accessing the result like the following: while(resultSet.next()){ String st
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. To understand how to display the result
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
Advertisements
 

 

 

DMCA.com