How can i extract email ids from xls/xlsx file in java?

How can i extract email ids from xls/xlsx file in java?

that's the code..... i tried to extract email id;s from xls file........... but it doesn;t gives the proper output?

table is like this: bhavik [email protected] magan [email protected]

Output::: [email protected] [email protected]

please give me some hints to solve this program correctly..........

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

import java.util.regex.Pattern; 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;

public class excelread123 {

File fout = new File("data1.txt");

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

            String fileName = "bv1.xls";
            Vector dataHolder = ReadCSV(fileName);
            printCellDataToConsole(dataHolder);
    }

    public static Vector ReadCSV(String fileName) {

            Vector cellVectorHolder = new Vector();

            try {
                    FileInputStream myInput = new FileInputStream(fileName);

                    POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);

                    HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);





                    HSSFSheet mySheet = myWorkBook.getSheetAt(0);

                    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 printCellDataToConsole(Vector dataHolder) throws FileNotFoundException, IOException {

        int n,c;
        String str = null;
        Pattern p = Pattern.compile("([\\w+|\\.?]+)\\w+@([\\w+|\\.?]+)\\.(\\w{2,8}\\w?)");
        File fout = new File("data1.txt");
        FileOutputStream f = new FileOutputStream(fout);
            for (int i = 0; i < dataHolder.size(); i++) {
                    Vector cellStoreVector = (Vector) dataHolder.elementAt(i);
                    for (int j = 0; j < cellStoreVector.size(); j++) {
                            HSSFCell myCell = (HSSFCell) cellStoreVector.elementAt(j);
                            String stringCellValue = myCell.toString();
                            for(int k=0;k<stringCellValue.length();k++)
                            {
                                n = stringCellValue.charAt(k);
                                f.write(n);
                            }


                    }

            }
            FileInputStream fis1 = new FileInputStream(fout);

Scanner s = new Scanner(fout); while ( (str = s.findWithinHorizon(p, 0)) != null ) while((str = s.(p)) != null) { System.out.println(str); }

  fis1.close();
    }

}

View Answers









Related Tutorials/Questions & Answers:
How can i extract email ids from xls/xlsx file in java?
How can i read a file from nth line onwards in java
Advertisements
Extract frames from Video File
How to extract a specific line from a text file? - IoC
Java code for converting between .xls to .xlsx and vice versa - Java Beginners
How to Extract SQL schema into .xsl file
how can i display a pdf file in a jtextarea
Javah -  Header File Generator
How can we extract string 'roseindia.net ' from a string http://deepak@roseindia. net using regular expression of php?
how can i export a .jar file include .mbd file?
How do I read a variable from a file in shell script
Java code for conversion between .xls and .xlsx or vice versa - Development process
How to extract details from XML? - JSP-Servlet
How can I get specific data from JSON
how can i run ASP.Net Server from netbeans IDE?
How can i pass the valus from a JSP to the action class???
difference between java5 and java6 - Java Beginners
Java2
How I can filling pdf file that crated by livecycle using itext
How Can I get ArrayList of Data from jsp with ajax request
how can i open pdf file in assest folder in android application?
How can I start learning machine learning from scratch?
How can I learn Data Science from scratch?
How can i Dispose Dialog box From LWUIT Component >
How can i download these java related materials from rose india
Want to learn java - How i can learn Java from scratch?
How can I get specific data from JSON
How to extract name,surname, doamin name from mailid
about java1
How to extract a zip file to a folder in Linux?
How to extract values from SOAP Response message and insert in database
extract data from HTML
How to extract the entire line with specific data from a Text in java?
Javah
Write a program that replaces a, e, i, o, u in Java2
Extract Jar File
extract content from javamail - JavaMail
how can i send a mail to a particular user from a many user dropdown list in jsp
How can I open my Java desktop app by clicking on its file?
how can i display the dates of one week by selecting the date randomly from the calendar?
how to send html email from dreamweaver
how can i define only one method from the interface. - Java Beginners
How to extract HTML elements from a page?
How to extract HTML elements from a page?
javaa swings - IDE Questions
how to send email in php and attech with any file
About Java2
How can I POST form data from a C#/ASP.NET to a remote website?
Java to extract info from .iCalendar files
how to resolve the problem like when i extract the struts-blank-1.3.10.war it shows java .io.filenotfound

Ads