数据库的数量较大,但是想创建一个经理管理了多少人的一个excel文件,会有多个,跪求各位大神给点意见,研究了一天了,不知道怎么实现

解决方案 »

  1.   

    /**
     * jxl导出excel方法
     * @author 巩浩 2016-7-7 下午2:17:47
     * @param fileName 文件名
     * @param heads 字段名称(例:{姓名,年龄})
     * @param headsStr 字段(例:{name,age})
     * @param dataList 数据列表
     */
    @SuppressWarnings("rawtypes")
    public static void excelExport(String fileName,String[] heads,String[] headsStr,List dataList) throws Exception {
    WritableWorkbook book=null ;
    OutputStream os = null;
    try{
    HttpServletResponse response = ServletActionContext.getResponse();
    os = response.getOutputStream();
    response.reset();
    response.setHeader("Content-disposition", "attachment; filename=\""
    +  URLEncoder.encode(fileName,"UTF-8")+ "_"+System.currentTimeMillis() + ".xls\"");
    response.setContentType("application/msexcel; charset=utf-8");

    if (dataList != null && dataList.size() > 0) {
    book = JxlUtil.createWorkBookWithStyle(os, dataList, heads, headsStr);
    } else {
    book = Workbook.createWorkbook(os);
    WritableSheet sheet = book.createSheet("日志信息", 0);
    // 指定单元格位置(如:第一列第一行(0, 0))以及单元格内容为(如:小明)
    for (int i = 0; i < heads.length; i++) {
    Label cell = new Label(i, 0, heads[i]);
    // 将定义好的单元格添加到工作表中
    sheet.addCell(cell);
    }
    }
    book.write();
    }catch(Exception e){
    e.printStackTrace();
    }finally{
    if(book!=null){
    book.close();
    }
    if(os!=null){
    os.close();
    }
    }

    }
    /**
     * 根据数据列表及参数输出工作薄
     * 本方法多加了一些excel表格的样式
     * @author 巩浩 2016-7-7 下午2:32:38
     * @param os 输出流
     * @param dataList 数据列表
     * @param heads 字段名称
     * @param headsStr 字段
     * @return
     * @throws IOException 
     * @throws WriteException 
     * @throws RowsExceededException 
     * @throws NoSuchMethodException 
     * @throws InvocationTargetException 
     * @throws IllegalAccessException 
     */
    @SuppressWarnings("rawtypes")
    public static WritableWorkbook createWorkBookWithStyle(OutputStream os, List dataList, String[] heads, String[] headsStr) throws IOException, RowsExceededException, WriteException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    //根据数据大小具体分n个sheet页,默认一页存储1000条数据
    int sizeLoop = dataList.size();//数据大小
    int size = dataList.size();
    if(sizeLoop < 1000){
    sizeLoop = 1000;
    }
    int sheetSize = 1000;
    int loopSize = sizeLoop/sheetSize;
    if(sizeLoop%sheetSize!=0){
    loopSize+=1;
    }

    //设置样式 
            WritableFont wf_head = new WritableFont(WritableFont.ARIAL, 11, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.RED); // 定义格式 字体 下划线 斜体 粗体 颜色  
            WritableFont wf_table = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK); // 定义格式 字体 下划线 斜体 粗体 颜色  
         
            WritableCellFormat wcf_head = new WritableCellFormat(wf_head);  // 单元格定义   
            wcf_head.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式    
          
            WritableCellFormat wcf_table = new WritableCellFormat(wf_table);   

    //创建一个工作薄
    WritableWorkbook ws = Workbook.createWorkbook(os);

    //分别往每个sheet页写数据
    for(int l = 0;l<loopSize;l++){
    WritableSheet sheet = ws.createSheet("第"+(l+1)+"页", l);

    for(int i=0;i<heads.length;i++){
    Label cell = new Label(i,0, heads[i],wcf_head);
    sheet.addCell(cell );
    }
            
    //循环读取数据列表
    int n = 1;
    for(int i=l*sheetSize;i<(l+1)*sheetSize && i<=size-1;i++){
    Object vrd = dataList.get(i);
    for(int j = 0;j<headsStr.length;j++){

    Object value = PropertyUtils.getProperty(vrd, headsStr[j]);
    if(ObjectUtil.isAllObjectsNotNull(value)){
    sheet.setColumnView(j, value.toString().length()+10);
    sheet.addCell(new Label(j,n,value.toString(),wcf_table));
    }
    }
    n++;
    }
    }
    return ws;
    }
      

  2.   

    别用jxl了,不支持office2007,用poi吧
      

  3.   

    查查在线处理文档的插件吧,网上不少呢,可以查查PageOffice插件
      

  4.   

    做过一个简单的例子
    http://blog.csdn.net/qq_30831935/article/details/52778656