Import Java.io.file;import Java.io.ioexception;import JXL. Workbook;import Jxl.write.label;import Jxl.write.writablesheet;import Jxl.write.writableworkbook;import Jxl.write.writeexception;import Jxl.write.biff.rowsexceededexception;import Org.apache.log4j.logger;public Class excelutils {static private Logger Logger = Logger.getlogger (excelutils.class); static public int SUCCESS = 0;static Public int ERROR = -1;/** * Create a single sheet Excel file, specify the path yourself, use a two-dimensional array to map the corresponding cell **/static public int createexcel (String filerootpath,string Filename,string sheetname,string[][] dataarr) {int result = Error;try {if (Filerootpath = = NULL | | "". Equals (Filerootpath) | | FileName = = NULL | | ". Equals (FileName)) {throw new Exception (" Create Excel File Error: Createexcel method parameter value is empty! ");} if (Dataarr = = NULL | | dataarr[0] = = null) {throw new Exception ("Input parameter Dataarr error!");} String FilePath = Filerootpath + fileName; File File = new file (Filerootpath), if (!file.exists ()) {file.mkdirs ();} Writableworkbook book = workbook.createworkbook (New filePath)); if (sheetname = = NULL | | "". Equals (SheetName)) {sheetname = "first page";} A worksheet named SheetName is generated, and the parameter 0 indicates that this is the first page writablesheet sheet = book.createsheet (sheetname, 0);//The name of the cell in the constructor of the label object is the first row ( 0,0)//And cell contents testfor (int i=0; i<dataarr.length;i++) {for (int j=0;j<dataarr[0].length;j++) {Label label = new Label (J, I, Dataarr[i][j]); Sheet.addcell (label);//Add a defined cell to the worksheet}}book.write (); Book.close (); result = SUCCESS;} catch (IOException e) {logger.error ("Excel File path Error!"); Logger.error (E.tostring ()); return result;} catch (Rowsexceededexception e) {logger.error ("When creating Excel, line exceeds!"); Logger.error (E.tostring ()); return result;} catch (WriteException e) {logger.error ("Write error when creating Excel!"); Logger.error (E.tostring ()); return result;} catch (Exception e) {logger.error (e.tostring ()); return result;} return result;} public static void Main (String args[]) {string[][] Myarr = new string[2][3];myarr[0][0]= "one"; myarr[0][1]= "n"; myarr[0][ "2]=", "myarr[1][0]=", "myarr[1][1]="; myarr[1][2]= "23"; Excelutils.createexcel ("d:/test/"," Test.xls "," Dealer Account List ", Myarr);}