Results 1 to 3 of 3

Thread: Java and Excel

  1. #1
    Maro is offline Member
    Join Date
    Aug 2009
    Posts
    1
    Rep Power
    0

    Default Java and Excel

    I've managed to write Data into Excel using output stream from a Text File. but i'd like to keep the header and format of the existing Excel sheet the same and import the data from the text file to replace the rest of the data, can someone help please?!

    Following is part of my code:

    public void actionPerformed(ActionEvent e){

    try{
    File fset = new File("Settings.txt");
    File f = new File(txtlstDrp.getSelectedValue().toString());
    File fxcl = new File(xcllstDrp.getSelectedValue().toString());
    FileInputStream fin = new FileInputStream(f);
    DataInputStream din = new DataInputStream(fin);
    FileInputStream finxcl = new FileInputStream(fxcl);
    DataInputStream dinxcl = new DataInputStream(finxcl);
    FileOutputStream fout = new FileOutputStream(fxcl);
    DataOutputStream dout = new DataOutputStream(fout);
    FileInputStream finset = new FileInputStream(fset);
    DataInputStream dinset = new DataInputStream(finset);
    boolean fnfound = false;
    String Targfile=null;
    String improw = null;
    while (finset.available()!=0){
    String lnfnm =dinset.readLine();
    StringTokenizer tok = new StringTokenizer(lnfnm, ";");
    while (tok.hasMoreTokens()){
    String fnm = tok.nextToken();
    if(txtlstDrp.getSelectedValue().toString().contain s(fnm)){
    Targfile=tok.nextToken();
    improw=tok.nextToken();

    fnfound=true;
    break;
    }

    }
    if(fnfound){
    break;
    }
    }
    int lnnum = Integer.parseInt(improw);
    for(int i=0; i<lnnum ; i++){

    }

    while(fin.available()!=0){
    /*String line = din.readLine();
    StringTokenizer tok = new StringTokenizer(line,";");
    while (tok.hasMoreTokens()){
    //write into excel sheet
    String xclstr = tok.nextToken();

    dout.writeChars(xclstr+"\t");

    System.out.println(xclstr+"\t");
    }*/


    String line = din.readLine();
    dout.writeChars(line.replace(';', '\t'));
    //new row
    dout.writeChars("\n");
    }
    din.close();
    fin.close();
    fout.close();
    dout.close();
    }catch(IOException ex){
    JOptionPane.showMessageDialog(null, "Couldn't Open the Selected File!");
    }
    }

  2. #2
    vogella is offline Member
    Join Date
    Aug 2009
    Location
    Heidelberg
    Posts
    47
    Rep Power
    0

    Default

    You could use the library jxl.jar to read and write directly from and to Excel file format.

  3. #3
    vogella is offline Member
    Join Date
    Aug 2009
    Location
    Heidelberg
    Posts
    47
    Rep Power
    0

Similar Threads

  1. writing to a excel file from java program
    By priyankabhar in forum New To Java
    Replies: 15
    Last Post: 01-17-2014, 12:39 PM
  2. How to read Excel file with java
    By chetan-24 in forum New To Java
    Replies: 5
    Last Post: 04-22-2009, 05:11 PM
  3. Java results in Excel
    By puk284 in forum New To Java
    Replies: 1
    Last Post: 04-21-2009, 04:13 AM
  4. Importing excel sheets into java application
    By blizzard in forum New To Java
    Replies: 1
    Last Post: 04-02-2009, 09:59 PM
  5. Excel to database using java
    By Priyadharshini.s in forum Advanced Java
    Replies: 1
    Last Post: 03-08-2008, 06:12 PM

Posting Permissions

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