首先引入jar包jxl.jarjava
public static void main(String args[]) throws IOException, RowsExceededException, WriteException{ //建立文件 File xlsFile= new File("vita.xls"); //建立工做簿 WritableWorkbook workbook = Workbook.createWorkbook(xlsFile); //建立工做表 WritableSheet sheet = workbook.createSheet("sheetTest", 0); //建立數據對象Label Label label= new Label(1,2,"cont"); //單元格添加數據 sheet.addCell(label); //寫入工做簿 workbook.write(); //關閉工做簿 workbook.close(); }
注意事項:.net
public static void main(String args[]) throws BiffException, IOException{ //建立文件 File xlsFile= new File("vita.xls"); //獲取工做簿 Workbook workbook = Workbook.getWorkbook(xlsFile); //獲取工做表 Sheet sheet = workbook.getSheet(0); //獲取工做表集 //Sheet[] sheets=workbook.getSheets(); //獲取工做表名 String name = sheet.getName(); //獲取工做錶行列數 int row = sheet.getRows(); int col = sheet.getColumns(); //獲取工做表內容 String cont = sheet.getCell(col-1, row-1).getContents(); System.out.println("SheetName"+name+"\n"+"Clo:"+col+" "+"Row:"+row+"\n"+col+"c"+row+"r:"+cont); //關閉工做簿 workbook.close(); }
注意事項:code