/ ** *テンプレートのダウンロード * 1.まず、テンプレートを取得し、段落情報テンプレートを読み込む; * 2.解析の段落情報、プロセスは、380名に(クエリの照会内容を確認して、プロセスID 500を通過するための情報クエリ固有のデータ) * 3段落タグ内のテンプレート情報を交換は、例えば$(A)は、1で置換されている; * 4テンプレートを交換由来; * * @paramのDTO * @return * @throws BLException * @throws UnsupportedEncodingException * / 公共IGOCRG01DTO downloadAttachmentAction(IGOCRG01DTO DTO)はBLExceptionは、IOException {スロー log.infoを( ">>テンプレートのダウンロード処理が開始さ..."); // 1が受け付けるパラメータ iGOCRG0101Form igocrg0101Form = dto.getForm(); 文字列attrKey = igocrg0101Form.getAttachmentKey(); 文字列igocrg0101Form.getOcrgDate_Start DATE_START =(); 文字列DATE_END igocrg0101Form.getOcrgDate_End =(); 。// 2读取模板キー、名前 のHashMap <文字列、文字列> hmReplacePara =新しいHashMapの<>(); AttachmentSearchCondImpl attachmentSearchCond =新しいAttachmentSearchCondImpl(); attachmentSearchCond.setAttkey(attrKey)。 一覧<添付資料> attachmentList = attachmentBL.searchAttachmentList(attachmentSearchCond)。 取付アタッチメント= attachmentList.get(0)。 //读取指定附件 文字列ROOTPATH = ""; ROOTPATH + = ResourceUtility.getString( "UPLOAD_FILE_ROOT_PATH_OCRG")。 StringBufferのファイルパス=新しいStringBufferの(ROOTPATH)。 filepath.append(attrKey)。 filepath.append( "/"); filepath.append(attachment.getAttname())。 。// 3读取对照表$(A):事件/服务请求管理 のHashMap <文字列、文字列> hmOCRGValueToOCRGKey =新しいHashMapの<>(); HashMapの<文字列、文字列> hmPdIdToPdName =新しいHashMapの<>(); ArrayListの<文字列> alProcessName =新しいArrayListを<>(); 一覧<OcrgContrastInfo> ocrgContrastInfoList = ocrgContrastBL.searchOcrgContrast(); 以下のために(INT i = 0; iは++; iはocrgContrastInfoList.size()<){ OcrgContrastInfo ocrgContrastInfo = ocrgContrastInfoList.get(i)を、 ストリングocrgkey = ocrgContrastInfo.getOcrgkey()。 ストリングocrgvalue = ocrgContrastInfo.getOcrgvalue()。 hmOCRGValueToOCRGKey.put(ocrgvalue、ocrgkey)。 hmReplacePara.put(ocrgkey、 "0")。 } IF(filepath.toString()。toLowerCaseメソッド()。 //读取模板文件 XWPFDocumentドキュメント=新XWPFDocument(POIXMLDocument.openPackage(filepath.toString())); //获取文档中的段落。 一覧<XWPFParagraph> xwpfParagraphList = document.getParagraphs(); 以下のために(INT i = 0; iは++; iはxwpfParagraphList.size()<){ XWPFParagraph xwpfParagraph = xwpfParagraphList.get(i)を、 ストリングparaGraphStr = xwpfParagraph.getText()。 IF(StringUtils.isNotEmpty(paraGraphStr)){ ため(のMap.Entry <文字列、文字列>エントリ:hmOCRGValueToOCRGKey.entrySet()){ 文字列ocrgValue = entry.getValue()。 IF(paraGraphStr.contains(ocrgValue)){ alProcessName.add(entry.getKey())。 } } log.debug( "文档中的段落信息:" + xwpfParagraph.getText())。 } } //读取IG380 のArrayList <ストリング> alPdId =新規のArrayList <>(); 以下のために(INT i = 0; iはalProcessName.size()<; I ++のを){ //读取ig380 IG380SearchCondImpl ig380SearchCond =新しいIG380SearchCondImpl()。 ig380SearchCond.setPdname(alProcessName.get(I)); 一覧<IG380Info> ig380InfoList = ig380BL.searchIG380Info(ig380SearchCond)。 もし(ig380InfoList!= NULL){ (INT J = 0; J <ig380InfoList.size(); J ++){ため ig500SearchCond.setPropentime_to(DATE_END + "23:59"); IG380Info ig380Info = ig380InfoList.get(J)。 alPdId.add(ig380Info.getPdid())。 hmPdIdToPdName.put(ig380Info.getPdid()、ig380Info.getPdname())。 } } } //查询IG500、按照流程关闭时间查询 IG500SearchCondImpl ig500SearchCond =新しいIG500SearchCondImpl()。 文字列[] pdIdArr =新しいString [alPdId.size()]。 alPdId.toArray(pdIdArr)。 ig500SearchCond.setPrpdid_like_or(pdIdArr)。 ig500SearchCond.setPropentime_from(DATE_START + "0時")。 {(私は++; iがig500InfoList.sizeを()<I 0 = INT)のために 一覧<IG500Info> ig500InfoList = ig500BL.searchIG500Info(ig500SearchCond)。 } IG500Info ig500Info = ig500InfoList.get(I)。 ストリングPDID = ig500Info.getPrpdid()。 ストリングpdName = hmPdIdToPdName.get(PDID)。 IF(hmOCRGValueToOCRGKey.containsKey(pdName)){ 文字列ocrgKey = hmOCRGValueToOCRGKey.get(pdName)。 IF(hmReplacePara.containsKey(ocrgKey)){ 文字列NUM = hmReplacePara.get(ocrgKey)。 hmReplacePara.put(ocrgKey、String.valueOf(Integer.parseInt(NUM)+ 1))。 } } イテレータ<XWPFParagraph> itPara = document.getParagraphsIterator()。 一方、(itPara.hasNext()){ //段落信息 XWPFParagraph段落=(XWPFParagraph)itPara.next(); 一覧<XWPFRun>実行=のparagraph.getRuns(); 以下のために(INT i = 0; i)は(runs.sizeを<; iは++){ //段落中文字 列oneparaString = runs.get(I).getText(runs.get(I).getTextPosition())。 用(のMap.Entry <文字列、文字列>エントリ:hmReplacePara.entrySet()){ //替换段落中文字 IF(oneparaString.contains(entry.getKey())){ log.debug(「普通文字--docx- -替换前:」+ oneparaString)。 oneparaString = oneparaString.replace(entry.getKey()、エントリー。 } } //段落に設定再 runs.get(I).setText(oneparaString、 0 ); Log.debug( "通常のテキストの後---- docx-置換:" + oneparaString); } 文字列exceptionCondition runs.toString =(); log.debug(「段落は何コンマを生成するスペースを削除するための特別な処理を区別するリスクレポート- ---- docx-通常のテキストの前に置き換え:「+ exceptionCondition); // APIの段落は、コンマスペース漢削除するために特別な処理を区別破る IF(StringUtils.isNotEmpty(exceptionConditionを)){ exceptionCondition = exceptionCondition。 ( " """).replaceを( ""、 "")置き換える; IF(exceptionCondition.length()> 2) exceptionCondition exceptionCondition.substring =(1、exceptionCondition.length() - 1)、 IF(exceptionCondition。含まれています( "## <")&&exceptionCondition.contains( "> ##")){ (のMap.Entry <文字列、文字列>のエントリ:hmReplacePara.entrySet())のために{ exceptionCondition = exceptionCondition.replace(entry.getKey()、entry.getValue()); } runs.get(0).setText(exceptionCondition、 0); log.info( "段落が生成されたものコンマリスクレポートのスペースを削除する場合は、特別な治療を区別- ---- docx-通常のテキストの後に交換:" + exceptionCondition); 。のために(int型I = 1;私は< runs.size();私は++){ runs.get(I).setText( ""、0); } } } } HttpServletResponseのdto.getResponse応答=(); response.reset()。 response.setContentType(「バイナリ/オクテットストリーム」); (出力ならば!= NULL){ 出力=ヌルのOutputStream; 試み{ 文字列DocTitle = "データを生成するための一つのボタンには、.docxのを報告します"; response.setHeader( "コンテンツ・処分"、 "添付ファイル;ファイル名=" +新新しいString(docTitle.getBytes( "GB2312")、 "ISO-8859-1")); 出力= response.getOutputStream(); //は導出実行 のdocument.write(出力); }キャッチ(例外E){ log.error( "インタフェース定義情報-エクスポートワード異常") ; e.printStackTrace(); } {最後に 試み{ //出力ストリーム閉じ output.closeを(); } output.flush(); IF(出力= nullを!){ output.flush(); output.close(); } }キャッチ(例外E){ log.error( ">>エクスポートWordが出力ストリーム例外が閉じ:" + e.getMessage()) ; } } } log.info( ">>テンプレートのダウンロード操作が完了する..."); DTOを返します; }
Wordテンプレートをお読みください。Wordテンプレートの内容を置き換え
おすすめ
転載: blog.csdn.net/qq_34004756/article/details/91490413
おすすめ
ランキング