用java jxl写入excel03文件,下面给出一个简单的方法
/**
*file 表示excel文件,在任意位置创建一个.xls文件
*list 表示需要写入excle文件的对象列表
private void writeFile(File file, List<ObjectVO> list) {
String sheetname = "反馈内容";
try {
WritableWorkbook exportWorkbook = Workbook.createWorkbook(file);
WritableSheet sheet = exportWorkbook.createSheet(sheetname, 0);
int outputRow = 0;
sheet.addCell(new Label(0, outputRow, "反馈内容"));
sheet.addCell(new Label(1, outputRow, "用户信息"));
sheet.addCell(new Label(2, outputRow, "类型"));
sheet.addCell(new Label(3, outputRow, "反馈日期"));
outputRow++;
sheet.setColumnView(0, 60); //0表示第一列,60表示宽度
sheet.setColumnView(1, 20);
sheet.setColumnView(2, 20);
sheet.setColumnView(3, 20);
for ( ObjectVO vo: list) {
sheet.addCell(new Label(0, outputRow, vo
.getContent()));
sheet.addCell(new Label(1, outputRow, vo
.getUserKey()));
sheet
.addCell(new Label(2, outputRow, vo
.getType()));
sheet
.addCell(new Label(3, outputRow, vo
.getTime()));
outputRow++;
}
exportWorkbook.write();
exportWorkbook.close();
} catch (IOException e) {
} catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
执行完该方法,到当前目录查看,发现文件内容已经写入