我将从数据库中查询到的记录放在一个List中,然后想将list中的数据导入到excel中,求这样一个方法???

解决方案 »

  1.   

    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFRichTextString;
    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.CellRangeAddress;/**
     * @author idle~`
     * @version 0.1
     * @date 2008-11-4
     */
    public class POITest {
    public static String outputFile="E:/TEMP/idleTest.xls";

    public static void main(String argv[]){
    try{
    HSSFWorkbook workbook = new HSSFWorkbook();
    // create sheet
    HSSFSheet sheet = workbook.createSheet("test");
    // create row at line 0
    HSSFRow row = sheet.createRow(0);
    // create cell at row 0
    HSSFCell cell = row.createCell(0);
    // set cell value type
    cell.setCellType(HSSFCell.CELL_TYPE_STRING);
    // set cell value
    cell.setCellValue(new HSSFRichTextString(""));
    cell.setCellStyle(POIStyleUtil.getTitleStyle(workbook));
    // merge row and column from row 0 to row 0,column 0 to column 7
    sheet.addMergedRegion(new CellRangeAddress(0,0,0,7));  
    for(int i = 1; i < 10; i++){
    HSSFRow rows = sheet.createRow(i);
    for(int j = 0; j < 8; j ++){
    HSSFCell cells = rows.createCell(j);
    cells.setCellType(HSSFCell.CELL_TYPE_STRING);
    cells.setCellValue(new HSSFRichTextString("" + i + " : " + j));
    cells.setCellStyle(POIStyleUtil.getColumnTitleStyle(workbook));
    }
    }
    FileOutputStream fOut = new FileOutputStream(outputFile);
    workbook.write(fOut);
    fOut.flush();
    fOut.close();
    System.out.println("");
    }catch(Exception e) {
    System.out.println("问题是" + e );
    }
    } }POI,很简单的
      

  2.   

    我的资源里有份 将数据库数据导入excel源代码,下载后即可使用
    楼主可以去看看
      

  3.   

    http://kingsui.javaeye.com/blog/154712
    参考一下这里的实现 
      

  4.   

    用POI吧, 这个最方便, 到Apache的主页上去找
      

  5.   

    支持POI的,刚实现过,不过在公司!