
正文
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;
}






