java学习(二)--excel导出

public static String writeFile(String fileName, String[][] content) {
		WritableWorkbook wwb = null;		
		String filePath = fileName+".xls";
		try {
			wwb = Workbook.createWorkbook(new File(filePath));
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (wwb != null) {
			WritableSheet ws = wwb.createSheet(fileName, 1);
			for (int row = 0; row < content.length; row++) {
				for (int j = 0; j < content[row].length; j++) {
					Label labelC = new Label(j, row, content[row][j]);
					try {
						ws.addCell(labelC);					
					} catch (RowsExceededException e) {
						e.printStackTrace();
					} catch (WriteException e) {
						e.printStackTrace();
					}
				}
				System.out.println(row);
			}
			try {
				wwb.write();
				wwb.close();
				return filePath;
			} catch (IOException e) {
				e.printStackTrace();
			} catch (WriteException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

 

posted @ 2014-07-07 10:20  RY一步一个脚印  阅读(285)  评论(0编辑  收藏  举报