- public void printExcels(List<Emp> emp ,OutputStream os){
- try {
- //创建一个工作簿
- WritableWorkbook book = Workbook.createWorkbook(os);
- //创建一个工作表
- WritableSheet sheet = book.createSheet("员工信息表", 0);
- //定义一个标题数组
- String [] title ={"编号","姓名","薪水","工作"};
- //创建 单元格
- for (int i = 0; i <title.length; i++) {
- //创建 单元格
- Label lable = new Label(i,0,title[i]);
- //把定义好的单元格加到工作表里
- sheet.addCell(lable);
- }
- for (int i = 0; i < emp.size(); i++) {
- Emp e = emp.get(i);
- String [] coms ={e.getEmpno().toString(),e.getEname(),e.getJob(),e.getSal().toString()};
- for (int j = 0; j <coms.length; j++) {
- //创建 单元格
- Label lable = new Label(j,i+1,coms[j]);
- //把定义好的单元格加到工作表里
- sheet.addCell(lable);
- }
- }
- //保存并关闭
- book.write();
- book.close();
- } catch (Exception e) {
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/120820135098.html
来源: http://www.codesnippet.cn/detail/120820135098.html