Results 1 to 3 of 3
Thread: Java and Excel
- 08-03-2009, 12:35 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 1
- Rep Power
- 0
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!");
}
}
- 08-03-2009, 05:22 PM #2
Member
- Join Date
- Aug 2009
- Location
- Heidelberg
- Posts
- 47
- Rep Power
- 0
You could use the library jxl.jar to read and write directly from and to Excel file format.
- 08-03-2009, 05:32 PM #3
Member
- Join Date
- Aug 2009
- Location
- Heidelberg
- Posts
- 47
- Rep Power
- 0
This is a tutorial to learn how to read and write Excel with the jxl.jar library: Excel and Java - Read and Write Excel with Java
Similar Threads
-
writing to a excel file from java program
By priyankabhar in forum New To JavaReplies: 7Last Post: 06-04-2013, 01:00 PM -
How to read Excel file with java
By chetan-24 in forum New To JavaReplies: 5Last Post: 04-22-2009, 05:11 PM -
Java results in Excel
By puk284 in forum New To JavaReplies: 1Last Post: 04-21-2009, 04:13 AM -
Importing excel sheets into java application
By blizzard in forum New To JavaReplies: 1Last Post: 04-02-2009, 09:59 PM -
Excel to database using java
By Priyadharshini.s in forum Advanced JavaReplies: 1Last Post: 03-08-2008, 06:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks