Results 1 to 3 of 3
  1. #1
    wdb07159 is offline Member
    Join Date
    Apr 2009
    Rep Power

    Default reading Excel Files

    Hi all

    I have just joined as I am new to Java and learning at the moment. I am using intellij #9779 with jdk 1.6.0_12.

    At present I have an excel file and I am trying to read it using Java code.

    What I want to do is be able to read the seperate column values out, and eventually be able to store them.

    For now I only want to try and read this file and display the values in it in system.out but have only been able to show the file contents successfully if it is converted to a .txt file.

    If the file is in .xls or .csv I get the newline little squares (and other strange characters) in each line between the text of the file.

    I have been looking at different examples of doing this and am finding it very difficult to work out how to read .xls files. I seem to be reading it ok but am getting the display problem as stated above.

    The code I have so far is this:

    Java Code:
    public class FileRead {
        public void file() {
            try {
                // Open the file that is the first
                // command line parameter
                FileInputStream fstream = new FileInputStream("C:/myFile.csv");
                // Get the object of DataInputStream
                DataInputStream in = new DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new           InputStreamReader(in));
                String strLine;
                //Read File Line By Line
                while ((strLine = br.readLine()) != null) {
                    // Print the content on the console
                //Close the input stream
            } catch (Exception e) {//Catch exception if any
                System.err.println("Error: " + e.getMessage());
    file method called from a main class.

    I have had conflicting information like using StringTokenizer or string.split but then find out StringTokeniser is not recommended to be used any more.

    Can anyone explain how to enhance the abve code so that I can read a .xls or .csv file successfully? At the moment I am not really sure whether to read .csv or .xls. Whichever method I find that is easiest to incorporate then I will use the appropriate file, however it wouyld be ideal if it could read .xls or easily convert a .xls to .csv and then read.



  2. #2
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Pennsylvania, USA
    Rep Power


    This question has come up before... If you search this forum, you should find what you are looking for...
    Who Cares... As Long As It Works...

  3. #3
    ron87 is offline Member
    Join Date
    Mar 2009
    Rep Power

Similar Threads

  1. Reading from EXCEL sheets
    By javaplus in forum Advanced Java
    Replies: 5
    Last Post: 07-13-2012, 04:46 AM
  2. Reading data from Micrsoft excel and writing to notepad
    By abhishek.jain in forum New To Java
    Replies: 4
    Last Post: 01-29-2009, 08:12 AM
  3. Reading data form Excel using Jdbc (example)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-13-2008, 11:23 AM
  4. Reading excel worksheet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-13-2008, 11:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts