日期:2014-05-19  浏览次数:20664 次

怎么实现通过excel模板里面的名字给excel赋值
下面的是我通过行与列赋值代码.太麻烦.
Java code

    String templeFile = path + "/common/example/staffresume.xls";  
      
           String outputPath = path + "/common";  
           // テンポレトを取得  
           // 新規Workbook  
           HSSFWorkbook hb = null;  
           try {  
               POIFSFileSystem pfs = new POIFSFileSystem(new FileInputStream(templeFile));   
               hb = new HSSFWorkbook(pfs);  
           } catch (FileNotFoundException e1) {  
               e1.printStackTrace();  
               System.out.println("THE FileNotFoundException ERROR,156 lines in the StaffResumeAction");  
           } catch (IOException e1) {  
               System.out.println("THE IOException ERROR,159 lines in the system");  
               e1.printStackTrace();  
           }  
           HSSFSheet sheet = hb.getSheetAt(0);  
           HSSFRow row = null;  
           HSSFCell cell = null;  
     /** 姓 名 **/  
           row = sheet.getRow(4);  
           cell = row.getCell(7);  
           if (staff.getStaffName() == null) {  
               cell.setCellValue(new HSSFRichTextString(""));  
           } else {  
               cell.setCellValue(new HSSFRichTextString(staff.getStaffName()));  
           }  
     response.getOutputStream();  
           // 新規ファイルの輸出流、輸入流  
           File file = new File(path);  
           // 指定パースがない場合 生成パス  
           if (!file.exists()) {  
               file.mkdirs();  
           }  
           FileOutputStream fos = null;  
           try {   
               // 生成するファイルパス  
               fos = new FileOutputStream(outputPath + "/" + fileName + ".xls");  
               hb.write(fos);  
               // 指定パースに新excelファイルを生成  
               fos.flush();  
           } catch (IOException ie) {  
               ie.printStackTrace();  
               System.out.println("the IOException error,1081 lines in the system");  
           } finally {  
               if (fos != null) {  
                   //  ファイルの輸出流を閉める  
                   fos.close();  
                   fos = null;  
               }  
               // 以前生成した lzh圧縮ファイルを削除  
               // deleteFile(outputPath, "lzh", dateString);  
               // lzh圧縮ファイル生成  
               // getZipFile(outputPath, fileName + ".xls", outputPath, fileName+ ".lzh");  
               // 生成した excelファイルを削除  
               // deleteFile(outputPath, "xls", dateString);  
           }  
           //  lzh圧縮ファイル名  
           /* 
            * fileName = fileName+".lzh"; // lzh圧縮ファイルパス String filepath = outputPath; // response設定とダウンロード保存のファイル名 
            * response.reset(); 
            */  
      
           // Excelファイル名  
           fileName = fileName + ".xls";  
      
           StringBuffer sb = new StringBuffer();  
           sb.append("attachment; filename=\"");  
           sb.append(new String(fileName.getBytes("SJIS"), "UTF-8"));  
           sb.append("\"");  
           response.reset();  
           response.setContentType("text/html;charset=UTF-8");  
           response.setContentType("application/x-msdownload");  
           response.setHeader("Content-Disposition", sb.toString());  
      
           // ファイルの輸出流、輸入流  
           OutputStream output = null;  
           FileInputStream fis = null;  
           try {  
               File f = new File(outputPath + File.separator + fileName);