解决方案 »

  1.   

     确实是  但是是单个excel的  多工作表 的大神  有例子吗
      

  2.   


    /*
    *自行引入Poi jar包
    */
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.ArrayList;
    import java.util.List;import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFCellStyle;
    import org.apache.poi.hssf.usermodel.HSSFFont;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.hssf.util.HSSFColor;
    import org.apache.poi.ss.usermodel.Font;
    public class T {
    public static void main(String[] args) throws IOException {

    List list=new ArrayList<String>();
    StringBuffer br=new StringBuffer("fjy");
    list.add("a1");list.add("a2");list.add("a3");list.add("a4");list.add("a5");list.add("a6");list.add("a7");
    list.add("b1");list.add("b2");list.add("b3");list.add("b4");list.add("b5");list.add("b6");list.add("b7");
    list.add("c1");list.add("c2");list.add("c3");list.add("c4");list.add("c5");list.add("c6");list.add("c7");
    list.add("d1");list.add("d2");list.add("d3");list.add("d4");list.add("d5");list.add("d6");list.add("d7");
    list.add("e1");list.add("e2");list.add("e3");list.add("e4");list.add("e5");list.add("e6");list.add("e7");
    String[] handers = {"小帅","香帅","帅宝","帅宝","香帅","小帅"};
    HSSFWorkbook wb = new HSSFWorkbook();//创建工作簿
    for(int sheetindex=0;sheetindex<3;sheetindex++){

     
    HSSFSheet sheet = wb.createSheet(br.toString()+sheetindex);//第一个sheet
    HSSFRow rowFirst = sheet.createRow(0);//第一个sheet第一行为标题
    rowFirst.setHeightInPoints(21.75f);
    //写标题了
    for (int i = 0; i < handers.length; i++) {
     
    HSSFCellStyle TABLE_TITLE_STYLE = null;  
      TABLE_TITLE_STYLE = wb.createCellStyle();  
            TABLE_TITLE_STYLE.setBorderTop(HSSFCellStyle.BORDER_THIN);  
            TABLE_TITLE_STYLE.setBorderBottom(HSSFCellStyle.BORDER_THIN);  
            TABLE_TITLE_STYLE.setBorderLeft(HSSFCellStyle.BORDER_THIN);  
            TABLE_TITLE_STYLE.setBorderRight(HSSFCellStyle.BORDER_THIN);  
            TABLE_TITLE_STYLE.setAlignment(HSSFCellStyle.ALIGN_CENTER);  
            TABLE_TITLE_STYLE.setFillForegroundColor(HSSFColor.LIGHT_ORANGE.index);  
            TABLE_TITLE_STYLE.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);  
            TABLE_TITLE_STYLE.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);           Font font = wb.createFont();
            font.setFontHeightInPoints((short)18); //字体大小
            
    sheet.setDefaultRowHeightInPoints(21.75f);
            font.setFontName("楷体");
            font.setBoldweight(Font.BOLDWEIGHT_BOLD); //粗体
            font.setColor(HSSFColor.GREEN.index);    //绿字- 字体颜色 
            TABLE_TITLE_STYLE.setFont(font);
        //获取第一行的每一个单元格
        HSSFCell cell = rowFirst.createCell(i);
        //往单元格里面写入值
        cell.setCellValue(handers[i]);
        cell.setCellStyle(TABLE_TITLE_STYLE); 
        }
    //写数据集
    //假定数据集是list集合
    for (int i = 0;i < list.size(); i++) {
        //获取list里面存在是数据集对象
        Object obj = list.get(i);
        //创建数据行
        HSSFRow row = sheet.createRow(i+1);
        //设置对应单元格的值
        row.createCell(0).setCellValue("obj 的属性0000000000000000");
        row.createCell(1).setCellValue("obj 的属性11111111111111111");
        row.createCell(2).setCellValue("obj 的属性222222222222222");
        row.createCell(3).setCellValue("obj 的属性333333333333333");
        row.createCell(4).setCellValue("obj 的属性44444444444");
        row.createCell(5).setCellValue("obj 的属性5");
    }
    sheet.autoSizeColumn((short)0); //调整第一列宽度
    sheet.autoSizeColumn((short)1); //调整第二列宽度
    sheet.autoSizeColumn((short)2); //调整第三列宽度
    sheet.autoSizeColumn((short)3); //调整第四列宽度
    sheet.autoSizeColumn((short)4); //调整第三列宽度
    sheet.autoSizeColumn((short)5); //调整第四列宽度


    }

    //写出文件(path为文件路径含文件名)
    OutputStream os=null;
    try {
    os = new FileOutputStream(new File("d:\\asdf.xls"));
    } catch (Exception e) {
    e.printStackTrace();
    }
    wb.write(os); 
    }
    }
      

  3.   

    知道了单个sheet导入,多个的就不难了,就是加个循环,多次读取每个sheet就行了
      

  4.   

    poi可以实现啊,自己下来看看api,分分钟就会了