Packages that need to be imported: Jxl.jar
Copy Code code as follows:
public void Readto () {
Workbook WB = null;
Writableworkbook WWB = null;
try {
The file is = new file (System.getproperty ("User.dir") + "\\in.xls");
File OS = new file (System.getproperty ("User.dir") + "\\out.xls");
if (!os.isfile ())//If the specified file does not exist, create the new file
Os.createnewfile ();
WB = Workbook.getworkbook (IS);//Get Data source In.xls Workbook object
WWB = Workbook.createworkbook (OS, WB);//Append data to the original workbook Out.xls
WWB = Workbook.createworkbook (OS);//difference from the previous line of code, create a new write workbook
if (WB!= null && WWB!= null) {
Writablesheet sheet = wwb.getsheet (0);//Get Out.xls First sheet
Writablecell cell = Sheet.getwritablecell (2, 4);//Get Out.xls cell to write data
sheet[] sheets = wb.getsheets ()//Get data source In.xls sheets
Cell[] cells = sheets[0].getrow (1);//Get In.xls The second row of the first sheet
if (cell.gettype () = = Celltype.label) {
Label L = (label) cell;
L.setstring (Cells[1].getcontents ());//Writes the second cell to the fifth row of the third column of Out.xls
}
Wwb.write ();
System.out.println (Workbook writes data successful!) ");
}
Wwb.close ();//Close
catch (Exception e) {
E.printstacktrace ();
finally {
Wb.close ();
}
}