Package com.jExcelApi.test;
Import Java.io.File;
Import java.io.IOException; Import JXL.
workbook;
Import jxl.read.biff.BiffException;
Import Jxl.write.Label;
Import Jxl.write.Number;
Import Jxl.write.WritableSheet;
Import Jxl.write.WritableWorkbook;
Import jxl.write.WriteException; /** * Jexcelapi Modify the contents of Excel * @author Kanjingcai * Note: Must add JEXCELAPI jar execution/public class Updateexcel {public stat IC void Main (String args[]) {try {//Get create Myfile.xls File Workbook Workbook =workbook.getworkbook (new file ("D:\\m
Yfile.xls "));
Copy a copy and assign to the original file Writableworkbook copy1 =workbook.createworkbook (New file ("D:\\myfile.xls"), workbook);
Copy a Output.xls//Writableworkbook copy2 =workbook.createworkbook (New File ("D:\\output.xls"), workbook);
or directly modify the D:\\myfile.xls file Writablesheet Sheet1 = copy1.getsheet (0);
New Excel file, copy first page worksheet to Output.xls file, (0) on behalf of the first page//writablesheet Sheet2 =copy2.getsheet (0); Get row No. 0, second column data (0,2)// Writablecell cell1 =sheet1.getwritablecell (0,2);
New Excel file, get row No. 0, second column data (0,2)//Writablecell cell2 =sheet2.getwritablecell (0,2);
Label label =new label (0,2, "new Record");
Sheet1.addcell (label);
Number number =new number (3,4,3.141591);
Sheet1.addcell (number);
Modify to get the contents of row No. 0, second column data (0,2)//Get cell type//if (Cell1.gettype () ==celltype.label) {label L = (LABEL) cell1;
Modified content l.setstring ("Modify myfile Data Cell");
*///modify data, must close file Copy1.write ();
Copy1.close ();
Copy2.write ();
Copy2.close ();
}catch (biffexception e) {//TODO auto-generated catch block E.printstacktrace ();
}catch (IOException e) {//TODO auto-generated catch block E.printstacktrace ();
}catch (WriteException e) {//TODO auto-generated catch block E.printstacktrace (); }
}
}