最近做一个java导出Excel表功能,老是要设置IE安全级别才能实现,有不用设置IE安全级别就能实现的方法吗?请大师们赐教!

解决方案 »

  1.   

    怎么发两个地方,lz说具体点,你是用什么来操作excel的,javascipt?
      

  2.   


    try {
    OutputStream outf = new FileOutputStream(path);
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet(); HSSFCellStyle style = wb.createCellStyle(); HSSFFont font = wb.createFont();
    font.setFontName("宋体");
    font.setFontHeightInPoints((short) 12);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
    style.setFont(font);
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 设置单元格左右居中
    style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); wb.setSheetName(0, "***********",
    HSSFCell.ENCODING_UTF_16);
    sheet.setColumnWidth((short) 0, (short) 2000); // 设置单元格的长度
    sheet.setColumnWidth((short) 1, (short) 5000);
    sheet.setHorizontallyCenter(true); HSSFRow row0 = sheet.createRow(0);
    row0.setHeight((short) 500);
    HSSFCell cell0 = row0.createCell((short) 0);
    cell0.setEncoding(HSSFCell.ENCODING_UTF_16);// 设置编码
    cell0.setCellValue("********"); HSSFFont f = wb.createFont(); // HSSFFont用来设置字体
    f.setFontHeightInPoints((short) 12); // 设置字号
    f.setFontName("宋体");
    f.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);// 给字体加粗
    style.setFont(f);
    cell0.setCellStyle(style); Region region = new Region((short) 0, (short) 0, (short) 0,
    (short) 6);//合并单元格,最新的poi应该可以直接写成整形的不要强制转换了
    sheet.addMergedRegion(region); HSSFRow row1 = sheet.createRow(1); HSSFCell cell1 = row1.createCell((short) 0);
    cell1.setEncoding(HSSFCell.ENCODING_UTF_16);// 设置编码
    cell1.setCellValue("*********"); cell1 = row1.createCell((short) 1);
    cell1.setEncoding(HSSFCell.ENCODING_UTF_16);// 设置编码
    cell1.setCellValue("*****");

    for (int i = 0; i < list.size(); i++) {
    HSSFRow row = sheet.createRow(i + 2);
    Object obj = list.get(i); HSSFCell cell = row.createCell((short) 0);
    cell.setEncoding(HSSFCell.ENCODING_UTF_16);
    cell.setCellValue("*****************"); cell = row.createCell((short) 1);
    cell.setEncoding(HSSFCell.ENCODING_UTF_16);
    cell.setCellValue("*****************"); }
    wb.write(outf);
    outf.close();
    }catch(Exception e){
    e.printStackTrace();
    } }