/*
格式具体如下
1、类别为A的方在一个sheet 里并设置sheetName = "A";
2、同理B类和C类都为一个sheet表 
表都生成了
3、在就是怎么把A类的内容添加到sheetName 为A的sheet里面去  B都一样C
现在我生成的是把A类和B类的都生成在 C的sheet里面!
下面的应该怎么判断或者给个思路 谢了!
*/
table
td1   td2   td3    类别
 1     2     3      A
 1     2     1      A
 1     2     3      A
 1     1     3      B
 1     4     3      B
 1     2     4      B
 1     4     3      C
 1     4     1      C
 1     4     4      C
*/
    Map<String, Boolean> map = new HashMap<String, Boolean>();   
    for (TD td : listBody) {   
      if (td == null) {   
        row++;   
        col = 0;   
        continue;   
      }   
      while (map.get(col + "-" + row) != null) {           
        col++;   
      }   
      if (td.colspan > 1 || td.rowspan > 1) {   
        sheet.mergeCells(col, row, col + td.colspan - 1, row + td.rowspan - 1);   
        for (int i = col; i <= col + td.colspan - 1; i++) {   
          for (int j = row; j <= row + td.rowspan - 1; j++) {   
            map.put(i + "-" + j, true);   
          }   
        }   
      }   
  
   label = new Label(col, row, td.content);   
   sheet.addCell(label);     map.put(col + "-" + row, true);   
  col += td.colspan;   
   }

解决方案 »

  1.   

    你可以查询产生3个临时表,将a,b,c的内容分别存到临时表再去做处理;或者在程序中起3个数组来装这些内容。
      

  2.   

    嗯!
      我是用数组
      可能我没说明白
    这是我生成sheet表的代码 
    这是把类别为一样的放在一个sheet里面不知道1楼明白了没!
     
    private void export(String content, HttpServletResponse response,String chan[]) throws IOException, RowsExceededException, WriteException {   
        response.setContentType("application/ms-excel");   
        String sheetName =getCaption(content); 
        int s =chan.length;
        String str[] = chan;
      
        if(sheetName==null){
         sheetName="sheet1";
        }
        sheetName = sheetName.replaceAll(":", "").replaceAll("[)]", "").replaceAll("[(]", "");   
        response.addHeader("Content-Disposition", "attachment; filename=" + new String(sheetName.getBytes("GBK"), "ISO-8859-1")   
            + ".xls");   
      
        
        OutputStream os = response.getOutputStream();   
        wwb = Workbook.createWorkbook(os);   
        wwb.setProtected(true);  
       
        for (int i = 0; i < s; i++) { 
         sheet = wwb.createSheet(str[i], i); 
        }
        
        int row = 0;   
        int col = 0;   
        Label label = null;   
        for(int d=0;d<s;d++ ){
        if (sheetName.trim().length() > 30) {   
          label = new Label(col, row, str[d]);   
          sheet.addCell(label);   
          row++;   
        }
       }