将jsp网页倒入到excel和world中?没听说过,只听说过jsp在网页使用excel和world

解决方案 »

  1.   

    用notepad打开一个jsp文件,然后Ctrl+A并快速的按下Ctrl+C。然后打开一个word或者excel,鼠标在空白处点一下,然后Ctrl+V。就行了!
      

  2.   

    package common;import java.io.*;
    import java.util.Vector;
    import org.apache.poi.hssf.usermodel.*;/**
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2003</p>
    * <p>Company: MRO</p>
    * @author Kevin zhou
    * @version 1.0
    */public class Excel {
    public void createExcelFile(ExcelIn excelIn) throws CommonException{
    Vector vtrData = excelIn.getData();HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Sheet1");setColumnWidth(sheet, excelIn.getWidth());HSSFFont font = wb.createFont();
    font.setFontName("宋体");HSSFCellStyle style = wb.createCellStyle();
    style.setFont(font);if(vtrData != null){
    Vector vtrTitle = excelIn.getTitle();
    HSSFRow rowTitle = sheet.createRow(0);
    for(int i=0;i<vtrTitle.size();i++){
    HSSFCell cell = rowTitle.createCell((short)i);
    cell.setEncoding(HSSFCell.ENCODING_UTF_16);
    cell.setCellValue((String)vtrTitle.get(i));
    cell.setCellStyle(style);
    }for(int i=0;i<vtrData.size();i++){
    HSSFRow row = sheet.createRow(i+1);
    Vector vtrRow = (Vector)vtrData.get(i);
    for(int j=0;j<vtrRow.size();j++){
    String strTemp = (String)vtrRow.get(j);
    if("&nbsp;".equals(strTemp)){
    strTemp = " ";
    }HSSFCell cell = row.createCell((short)j);
    cell.setEncoding(HSSFCell.ENCODING_UTF_16);
    cell.setCellValue(strTemp);
    cell.setCellStyle(style);
    }
    }
    }try{
    // Write the output to a file
    FileOutputStream fileOut =
    new FileOutputStream(excelIn.getPath());
    wb.write(fileOut);
    fileOut.close();
    }catch(Exception e){
    throw new CommonException("文件已经打开,请关闭后再生成");
    }
    }/**
    * Set Column Width
    */
    private void setColumnWidth(HSSFSheet sheet, int[] width){
    for(int i=0;i<width.length;i++){
    sheet.setColumnWidth((short)i, (short)(width[i]*256));
    }
    }
    }
    package common;import java.util.Vector;
    /**
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2003</p>
    * <p>Company: MRO</p>
    * @author Kouken
    * @version 1.0
    */public class ExcelIn {
    private String path = null;Vector vtrData = null; // vector->vector->String
    Vector vtrTitle = null; // vector->String
    int width[];public String getPath(){
    return this.path;
    }public void setPath(String path){
    this.path = path;
    }public Vector getData(){
    return this.vtrData;
    }public void setData(Vector vtrData){
    this.vtrData = vtrData;
    }public Vector getTitle(){
    return this.vtrTitle;
    }public void setTitle(Vector vtrTitle){
    this.vtrTitle = vtrTitle;
    }public int[] getWidth(){
    return this.width;
    }public void setWidth(int width[]){
    this.width = width;
    }}