我们做的应用需要用户在页面填写表单,提交后,
服务器端后台把表单数据拿出来填写在一个word文件里,
而且各个数据的位置是有要求的,形成一个word文件,
保存在服务器,用户通过页面的超链接拿到,用于打印,
各位大虾有过类似经验吗,尽量详细告诉小弟,先谢了!

解决方案 »

  1.   

    我用过一个APACHE的插件叫POI可以进行Office的操作。
    不过我只用过对Excel的处理
      

  2.   

    因为ms word和excel的文档都支持html文本格式,因此可以先用word或excel做好模版,另存为Web页,然后将该html改成jsp,将数据部分动态填入即可,不用很辛苦的调整格式
     
    word页面只要在jsp头设置如下指令:
    @page contentType="application/msword;charset=GBK" %>
     
    excel如下:
    @page contentType="application/vnd.ms-excel;charset=GBK" %>
    
    使用这种方式客户端必须安装有office软件,用户访问时将在ie中直接用word或excel打开该页面。
      

  3.   

    /**
       * 給料統計Excelファイル書く
       * @param fileName folderName+fileName
       * @param value List
       * @throws IOException
       */
      public static void writeSalaryExcelFile(String fileName, List value, String data, String deptName) throws
       IOException{
       PayRecordForm countResultForm = null;
       InputStream inputFile = null;
       FileOutputStream fOut = null;
       HSSFWorkbook wb = null;
       try {
     
            inputFile = new FileInputStream(fileName);
            //workbook作成
            wb = new HSSFWorkbook(inputFile);
            
            //sheet作成
            HSSFSheet sheet = wb.getSheetAt(0);
            //wb.setSheetName(0, "DataCount");
            HSSFRow row = null;
            HSSFCell cell = null;
            //準備完了
     
            SalaryPropertyRead prop = new SalaryPropertyRead();
            short rowStart = OutBean.formatShort(prop.getProperty("start"));
            short spanRow = OutBean.formatShort(prop.getProperty("rows"));
            String str = "";
            String[] postion = null;
            
            HSSFRow tempRow = null;
            //表数据
            int size = value.size();
            int currentRow = rowStart;
            for (int mIndex = 0; mIndex < size ; mIndex++) {
             countResultForm = (PayRecordForm)value.get(mIndex);
             currentRow = rowStart+spanRow*mIndex;
             row = sheet.getRow(currentRow);  
             if(row == null){
             row = sheet.createRow(currentRow);
             }
            
             //名前
             setSalaryRow(sheet,row,prop.getProperty("employeeName"),currentRow,countResultForm.getEmployeeName());
             str = prop.getProperty("employeeName");
                                  
                //日数 
             setSalaryRow(sheet,row,prop.getProperty("workDays"),currentRow,countResultForm.getWorkDays());
                         
                //出勤日数
             setSalaryRow(sheet,row,prop.getProperty("currentDays"),currentRow,countResultForm.getCurrentDays());
                         
                //缺勤日数
             setSalaryRow(sheet,row,prop.getProperty("noWorkDays"),currentRow,countResultForm.getNoWorkDays());
                         
                //遅刻回数
             setSalaryRow(sheet,row,prop.getProperty("lateDays"),currentRow,countResultForm.getLateDays());
                         
                //早退回数
             setSalaryRow(sheet,row,prop.getProperty("exitEarlyDays"),currentRow,countResultForm.getExitEarlyDays());
                     
                //残業週末時間    
             setSalaryRow(sheet,row,prop.getProperty("weekDays"),currentRow,countResultForm.getWeekDays());
                         
                //有給休暇日数   
             setSalaryRow(sheet,row,prop.getProperty("payAppDays"),currentRow,countResultForm.getPayAppDays());
                       
                //まきの休暇を取る日数がない  
             setSalaryRow(sheet,row,prop.getProperty("noPayAppDays"),currentRow,countResultForm.getNoPayAppDays());
                            
                //基本給料  
             setSalaryRow(sheet,row,prop.getProperty("base"),currentRow,countResultForm.getBase());
                           
                //全勤給料 
             setSalaryRow(sheet,row,prop.getProperty("allPay"),currentRow,countResultForm.getAllPay());
                            
                //保険金額            
                setSalaryRow(sheet,row,prop.getProperty("insurance"),currentRow,countResultForm.getInsurance());
            
            }      
            //入力完了        //新規出力文件流
            fOut = new FileOutputStream(fileName);
            // 保存する。
            wb.write(fOut);
            fOut.flush();
            //作成完了、ファイルを閉じる。       
            System.out.println("ファイル作成完了!");      }
          catch (Exception e) {
           e.printStackTrace();
            System.out.println(" xlCreate() : " + e);
          } finally {
           try{
           wb = null;
           if(fOut != null){
           fOut.close();
           }
           if(inputFile != null){
           inputFile.close();
           }
           } catch (Exception e){      
           }
          }
      } 
      

  4.   

    对Excel的处理代码,不知道对你是否有用亚