doc文檔內(nèi)容分析檢錯
一個(gè)問題記錄
獲取標(biāo)題列表編號的時(shí)候與實(shí)際值不符,查了一下發(fā)現(xiàn)aspose 19.8的發(fā)行說明里有一條,
而我項(xiàng)目里面使用的是aspose版本是19.7
具體參考:
Implemented an option that allows specifying whether to work with the original or revised version of a document
doc文檔分析回顧
NAME檢查:[分析:]Name會出現(xiàn)在兩種類型的地方:第一種,遍歷所有段落,當(dāng)段落樣式名包含"標(biāo)題",由于Name是不包含中文的,使用[\u4e00-\u9fa5]+過濾掉包含中文的,然后進(jìn)一步處理;另一種,出現(xiàn)在表頭為"標(biāo)示"的表格中
檢查NAME包含多表格名稱是否出現(xiàn)2個(gè)及以上連續(xù)_(下劃線),如有可自動刪除,只保留一個(gè)[分析:]當(dāng)段文字中包含兩個(gè)下劃線時(shí)繼續(xù)處理(para.getRange().replace) ? ? ? ? ? ?[注意:]para.getText()與para.toString(SaveFormat.TEXT).trim()的不同之處在于,舉個(gè)例子,當(dāng)你獲取一個(gè)標(biāo)題的文字的時(shí)候,前者只會獲得標(biāo)題編號后的文字,而后者則會包含標(biāo)題的編號
檢查NAME包含多表格名稱字符間不能出現(xiàn)空格,如有可自動刪除[分析:]當(dāng)段文字中包含兩個(gè)空格時(shí)繼續(xù)處理
檢查NAME多格式大小寫X和x不能混用,比如x,只能一種;[分析:]當(dāng)段文字中包含"Xx"或者"xX"時(shí)繼續(xù)處理
ID檢查:[分析:]Name會出現(xiàn)在兩種類型的地方:第一種,Paragraph以"標(biāo)示[:/:]"或"標(biāo)識[:/:]"開始的非表頭格式的后面部分;另一種,出現(xiàn)在表頭為"標(biāo)示"的表格中的第一列除了第一行的所有單元格內(nèi)容
檢查“標(biāo)識”或"ID"關(guān)鍵詞下是否缺失16進(jìn)制或10進(jìn)制ID(0x----)[分析:]當(dāng)不包含"0x"的時(shí)候,正則查找[0-9]+獲得其十進(jìn)制的值后,String.format("0x%X(%d)",dex,dex)進(jìn)行替換
檢查關(guān)鍵詞"標(biāo)識"是否正確,其他別字(如標(biāo)示)均報(bào)錯,可自動修改為"標(biāo)識"[分析:]使用para.getRange().replace進(jìn)行歸一化處理
檢查“標(biāo)識:0x1234()”,結(jié)尾不能出現(xiàn)其他符號,如有可自動刪除多余符號[分析:]首先將中文括號歸一化為英文括號,然后當(dāng)字段包含括號時(shí),如果包含"(0x"則可能是(0xccc)111這種錯誤樣式,采用正則"\((0x[A-Z0-9]+)\)([0-9]+)"進(jìn)行匹配,替換為m.group(1)+"("+m.group(2)+")",忽略包含頓號和短橫的多ID并列的情況,由于前面已經(jīng)移除了空格,所以現(xiàn)在只要判斷括號后面有沒有部分標(biāo)點(diǎn),使用正則"\)[,.;,。;]+"進(jìn)行查找;另外一種情況字段不包含括號,同樣忽略包含頓號或者橫桿的范圍并列的情況,原來只包含十六進(jìn)制的情況,采用"(0x[A-Z0-9]+)[,.;,。;]+"查找并消除后面的其他標(biāo)點(diǎn),然后通過"0x([A-Z0-9]+)"替換成"0x"+m.group(1)+"("+Integer.toString(hex)+")"補(bǔ)上十進(jìn)制的字段
檢查16進(jìn)制ID是否大小寫混用,如“0xAbC7”,可自動修改為大寫[分析:]0x不要求大寫,首先將"0X"替換成"0x",移除"0x"后自身與其轉(zhuǎn)大寫不相等則繼續(xù)處理,for(Run run:para.getRuns()) {String ot = run.getText();run.setText(ot.toUpperCase());},最后把"0X"替換成"0x"
支持檢查格式:word[分析:]限定到doc
報(bào)錯機(jī)制:在錯誤處進(jìn)行標(biāo)記(批注形式)[分析:]添加批注的邏輯前面我是調(diào)用的時(shí)候即時(shí)就添加了,但是其實(shí)這樣會帶來一些問題,因?yàn)閏omment中也是添加了Paragraph的,這樣就有可能影響一些分析后來的改進(jìn)是不即時(shí)添加,
//先記錄 public?static?void?addComment(Document?doc,int[]?commentId,Paragraph?para,String?text){ CComment?ccomment?=?new?CComment(para,text); pendingComment.put(commentId[0],ccomment); commentId[0]+=1; } //最后集中添加批注 ????public?static?void?addComment(Document?doc)?{ for(Map.Entryentry:pendingComment.entrySet())?{ Node[]?runs?=?entry.getValue().Paragraph.getChildNodes(NodeType.RUN,?true).toArray(); NodeCollection?coms?=?entry.getValue().Paragraph.getChildNodes(NodeType.COMMENT,?true); if(coms.getCount()>0)?{ Comment?oldComment?=?(Comment)coms.get(0); oldComment.getFirstParagraph().getRuns().add(new?Run(doc,?"and?err:"+entry.getValue().text.replace('\r',?'
//先記錄 public?static?void?addComment(Document?doc,int[]?commentId,Paragraph?para,String?text){ CComment?ccomment?=?new?CComment(para,text); pendingComment.put(commentId[0],ccomment); commentId[0]+=1; } //最后集中添加批注 ????public?static?void?addComment(Document?doc)?{ for(Map.Entryentry:pendingComment.entrySet())?{ Node[]?runs?=?entry.getValue().Paragraph.getChildNodes(NodeType.RUN,?true).toArray(); NodeCollection?coms?=?entry.getValue().Paragraph.getChildNodes(NodeType.COMMENT,?true); if(coms.getCount()>0)?{ Comment?oldComment?=?(Comment)coms.get(0); oldComment.getFirstParagraph().getRuns().add(new?Run(doc,?"and?err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); }else?{ if(runs==null?||?runs.length==0)?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); }else?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); /*CommentRangeStart?start?=?new?CommentRangeStart(doc,?entry.getKey()); CommentRangeEnd?end?=?new?CommentRangeEnd(doc,?entry.getKey()); runs[0].getParentNode().insertBefore(start,runs[0]); runs[runs.length-1].getParentNode().insertAfter(end,runs[runs.length-1]); end.getParentNode().insertBefore(comment,end);*/ entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); } } }
').replace('\n',?'//先記錄 public?static?void?addComment(Document?doc,int[]?commentId,Paragraph?para,String?text){ CComment?ccomment?=?new?CComment(para,text); pendingComment.put(commentId[0],ccomment); commentId[0]+=1; } //最后集中添加批注 ????public?static?void?addComment(Document?doc)?{ for(Map.Entryentry:pendingComment.entrySet())?{ Node[]?runs?=?entry.getValue().Paragraph.getChildNodes(NodeType.RUN,?true).toArray(); NodeCollection?coms?=?entry.getValue().Paragraph.getChildNodes(NodeType.COMMENT,?true); if(coms.getCount()>0)?{ Comment?oldComment?=?(Comment)coms.get(0); oldComment.getFirstParagraph().getRuns().add(new?Run(doc,?"and?err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); }else?{ if(runs==null?||?runs.length==0)?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); }else?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); /*CommentRangeStart?start?=?new?CommentRangeStart(doc,?entry.getKey()); CommentRangeEnd?end?=?new?CommentRangeEnd(doc,?entry.getKey()); runs[0].getParentNode().insertBefore(start,runs[0]); runs[runs.length-1].getParentNode().insertAfter(end,runs[runs.length-1]); end.getParentNode().insertBefore(comment,end);*/ entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); } } }
'))); }else?{ if(runs==null?||?runs.length==0)?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'//先記錄 public?static?void?addComment(Document?doc,int[]?commentId,Paragraph?para,String?text){ CComment?ccomment?=?new?CComment(para,text); pendingComment.put(commentId[0],ccomment); commentId[0]+=1; } //最后集中添加批注 ????public?static?void?addComment(Document?doc)?{ for(Map.Entryentry:pendingComment.entrySet())?{ Node[]?runs?=?entry.getValue().Paragraph.getChildNodes(NodeType.RUN,?true).toArray(); NodeCollection?coms?=?entry.getValue().Paragraph.getChildNodes(NodeType.COMMENT,?true); if(coms.getCount()>0)?{ Comment?oldComment?=?(Comment)coms.get(0); oldComment.getFirstParagraph().getRuns().add(new?Run(doc,?"and?err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); }else?{ if(runs==null?||?runs.length==0)?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); }else?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); /*CommentRangeStart?start?=?new?CommentRangeStart(doc,?entry.getKey()); CommentRangeEnd?end?=?new?CommentRangeEnd(doc,?entry.getKey()); runs[0].getParentNode().insertBefore(start,runs[0]); runs[runs.length-1].getParentNode().insertAfter(end,runs[runs.length-1]); end.getParentNode().insertBefore(comment,end);*/ entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); } } }
').replace('\n',?'//先記錄 public?static?void?addComment(Document?doc,int[]?commentId,Paragraph?para,String?text){ CComment?ccomment?=?new?CComment(para,text); pendingComment.put(commentId[0],ccomment); commentId[0]+=1; } //最后集中添加批注 ????public?static?void?addComment(Document?doc)?{ for(Map.Entryentry:pendingComment.entrySet())?{ Node[]?runs?=?entry.getValue().Paragraph.getChildNodes(NodeType.RUN,?true).toArray(); NodeCollection?coms?=?entry.getValue().Paragraph.getChildNodes(NodeType.COMMENT,?true); if(coms.getCount()>0)?{ Comment?oldComment?=?(Comment)coms.get(0); oldComment.getFirstParagraph().getRuns().add(new?Run(doc,?"and?err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); }else?{ if(runs==null?||?runs.length==0)?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); }else?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); /*CommentRangeStart?start?=?new?CommentRangeStart(doc,?entry.getKey()); CommentRangeEnd?end?=?new?CommentRangeEnd(doc,?entry.getKey()); runs[0].getParentNode().insertBefore(start,runs[0]); runs[runs.length-1].getParentNode().insertAfter(end,runs[runs.length-1]); end.getParentNode().insertBefore(comment,end);*/ entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); } } }
'))); }else?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); /*CommentRangeStart?start?=?new?CommentRangeStart(doc,?entry.getKey()); CommentRangeEnd?end?=?new?CommentRangeEnd(doc,?entry.getKey()); runs[0].getParentNode().insertBefore(start,runs[0]); runs[runs.length-1].getParentNode().insertAfter(end,runs[runs.length-1]); end.getParentNode().insertBefore(comment,end);*/ entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'//先記錄 public?static?void?addComment(Document?doc,int[]?commentId,Paragraph?para,String?text){ CComment?ccomment?=?new?CComment(para,text); pendingComment.put(commentId[0],ccomment); commentId[0]+=1; } //最后集中添加批注 ????public?static?void?addComment(Document?doc)?{ for(Map.Entryentry:pendingComment.entrySet())?{ Node[]?runs?=?entry.getValue().Paragraph.getChildNodes(NodeType.RUN,?true).toArray(); NodeCollection?coms?=?entry.getValue().Paragraph.getChildNodes(NodeType.COMMENT,?true); if(coms.getCount()>0)?{ Comment?oldComment?=?(Comment)coms.get(0); oldComment.getFirstParagraph().getRuns().add(new?Run(doc,?"and?err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); }else?{ if(runs==null?||?runs.length==0)?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); }else?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); /*CommentRangeStart?start?=?new?CommentRangeStart(doc,?entry.getKey()); CommentRangeEnd?end?=?new?CommentRangeEnd(doc,?entry.getKey()); runs[0].getParentNode().insertBefore(start,runs[0]); runs[runs.length-1].getParentNode().insertAfter(end,runs[runs.length-1]); end.getParentNode().insertBefore(comment,end);*/ entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); } } }
').replace('\n',?'//先記錄 public?static?void?addComment(Document?doc,int[]?commentId,Paragraph?para,String?text){ CComment?ccomment?=?new?CComment(para,text); pendingComment.put(commentId[0],ccomment); commentId[0]+=1; } //最后集中添加批注 ????public?static?void?addComment(Document?doc)?{ for(Map.Entryentry:pendingComment.entrySet())?{ Node[]?runs?=?entry.getValue().Paragraph.getChildNodes(NodeType.RUN,?true).toArray(); NodeCollection?coms?=?entry.getValue().Paragraph.getChildNodes(NodeType.COMMENT,?true); if(coms.getCount()>0)?{ Comment?oldComment?=?(Comment)coms.get(0); oldComment.getFirstParagraph().getRuns().add(new?Run(doc,?"and?err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); }else?{ if(runs==null?||?runs.length==0)?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); }else?{ Comment?comment?=?new?Comment(doc,?"amrf000",?"DH",?new?Date()); /*CommentRangeStart?start?=?new?CommentRangeStart(doc,?entry.getKey()); CommentRangeEnd?end?=?new?CommentRangeEnd(doc,?entry.getKey()); runs[0].getParentNode().insertBefore(start,runs[0]); runs[runs.length-1].getParentNode().insertAfter(end,runs[runs.length-1]); end.getParentNode().insertBefore(comment,end);*/ entry.getValue().Paragraph.appendChild(comment); comment.getParagraphs().add(new?Paragraph(doc)); ????????comment.getFirstParagraph().getRuns().add(new?Run(doc,?"err:"+entry.getValue().text.replace('\r',?'\0').replace('\n',?'\0'))); } } }
'))); } } }支持文件夾下多word文檔檢查(至少5個(gè))[分析:]這個(gè)沒什么好說的在Swingworker中遍歷處理就行,如果要采用并行提升處理效率的話,下一步在分析
表格檢查[分析:]doc.getChildNodes(NodeType.TABLE, true)獲取文檔中的所有表格,通過工具類PageNumberFinder,finder.GetPage(table.getFirstChild())獲取表格的起始頁碼
表格下空行檢查檢查文檔中的表格下是否有且只有一個(gè)空行[分析:]table.getPreviousSibling();table.getNextSibling();獲取表格相鄰兩個(gè)節(jié)點(diǎn),如果next是段落并且toString(SaveFormat.TEXT).trim()不為空則異常;next.getNextSibling(),獲取下下個(gè)節(jié)點(diǎn),如果連續(xù)兩個(gè)都為空,則異常
表格標(biāo)題行重復(fù)屬性未設(shè)置表格表頭是否設(shè)置標(biāo)題行重復(fù)屬性[分析:]通過finder.GetPage(table.getLastChild())獲取表格結(jié)束頁碼,當(dāng)開始不等于結(jié)束頁時(shí)即表格是跨頁的,這個(gè)時(shí)候如果table.getFirstRow().getRowFormat().getHeadingFormat()為false則標(biāo)題行重復(fù)屬性未設(shè)置
表注位置檢查表注位于表格上方[分析:]首先前面檢測表后非空行已經(jīng)一定程度上包含了這一點(diǎn),另外當(dāng)沒有表注的時(shí)候也是要求判定正常的,遍歷所有字段,如果字段格式為"Figure Description"或"Table Description"并且非空串,獲取相鄰的段落,如果為空則位置異常
圖形檢查[分析:]doc.getChildNodes(NodeType.SHAPE, true)獲取所有圖形
圖注位置檢查圖注位于圖片上方[分析:]如果前一個(gè)段落樣式為"Figure Description"則為圖注,finder.GetPage(pre)!=finder.GetPage(shape)則圖形段落與上下同頁未勾選;如果下一行是段落且段落內(nèi)容為空,并且下下段落不為空(包含Shape也為不空)則正常,ImageData ida = shape.getImageData()如果ida.getTitle()不是說明和警告等則圖后面非空行;遍歷所有字段,如果字段格式為"Figure Description"或"Table Description"并且非空串,獲取相鄰的段落,如果為空則位置異常
標(biāo)識文本[分析:]如果ida.getTitle()等于說明或者警告等
說明樣式檢查"檢查文檔中“說明”“竅門”上、下無空行,內(nèi)容不跨頁;[分析:]shape.getParentNode().getPreviousSibling()或者shape.getParentNode().getNextSibling()獲取前后的段落,如果是說明類的上下任意為空則異常,如果是警告類的上面為空或警告后不為空則異常,如果警告類的后面的空行多于1則異常
“警告”“注意”“危險(xiǎn)”上空1行,下不空行,內(nèi)容不跨頁"[分析:]循環(huán)獲取后面的節(jié)點(diǎn)如果樣式不等于"Notes Text"/"Notes Heading"/"Notes Text List"/"CAUTION Text"/"CAUTION Heading"/"CAUTION Text List"則該區(qū)段結(jié)束,獲取結(jié)束的頁碼如果不等于開始則跨頁了,如果結(jié)束后面的一個(gè)字段為空則異常(包含除了Heading的段落)
標(biāo)題
標(biāo)題不帶標(biāo)點(diǎn)符號1~3級標(biāo)題不帶標(biāo)點(diǎn)符號(/~-+&除外)[分析:]樣式名包含標(biāo)題且Pattern.compile("[\pP]+").matcher(para.text.replaceAll("/|~|-|&|_|\.", "")).find()則異常
Block Label樣式標(biāo)題檢查Block Label樣式標(biāo)題下必須要有內(nèi)容
標(biāo)題編號檢查檢查文檔中標(biāo)題編號方式是否與模板相同,具體包括1~4級標(biāo)題、Item step樣式,圖號,表號是否連續(xù) [分析:]para.Paragraph.getListFormat().getListLevel().getNumberStyle()!=NumberStyle.ARABIC則異常
文檔內(nèi)容
重復(fù)或錯字詞檢查檢查重復(fù)的字和詞,如的的、功能功能[分析:]遍歷錯詞作為匹配條件查找
成對符號檢查檢查中文狀態(tài)的圓括號()和書名《》號是否成對出現(xiàn)[分析:]在段落中分別對各個(gè)符號進(jìn)行while(m.find()) {++op;}計(jì)數(shù),應(yīng)該成對的不相等時(shí)則異常
數(shù)值范圍單位檢查文檔中表示數(shù)值范圍時(shí),數(shù)字帶有國際單位和表示量的數(shù)詞時(shí),兩個(gè)數(shù)字都要加上單位,例如:錯誤“1~/-5Hz”,正確“1Hz~5Hz”[分析:]正則"\d+[~|-]\dHz"
空白頁檢查頁面不應(yīng)有多余空白頁[分析:]通過工具類PageNumberFinder將所有段落分頁緩存起來,doc.getPageCount()獲取總頁數(shù),從1開始遍歷段落緩存,循環(huán)該頁段落,疊加段落正文直到trim()非空或者都循環(huán)完(當(dāng)段落包含shape子時(shí),正文也不為空),循環(huán)結(jié)束,如果疊加結(jié)果為空則異常
文檔樣式
頁眉頁腳檢查[分析:]doc.getChildNodes(NodeType.HEADER_FOOTER, true)獲取所有的頁眉頁腳,finder.GetPage(para.getParentNode())獲取父節(jié)點(diǎn)的頁碼,頁眉頁腳是對于section的,獲取的頁碼也是section的
封面無頁眉頁腳(文檔前2頁)[分析:],通過isHeader()可以獲取當(dāng)前section屬于頁眉的,頁腳偶數(shù)頁取HeaderFooterType.FOOTER_EVEN,奇數(shù)頁取HeaderFooterType.FOOTER_PRIMARY,如果頁碼小于等于2時(shí)對應(yīng)的頁眉頁腳非空則異常
前言及正文頁眉處為1級標(biāo)題名稱[分析:]通過h.getRange().getFields()遍歷,當(dāng)類型為FieldType.FIELD_STYLE_REF時(shí)并且樣式不為"Heading1 no Number"或"Contents"或"1"時(shí),即前言及正文頁眉處不為1級標(biāo)題名稱
前言及目錄(包含表目錄,圖目錄)頁腳的頁碼使用希臘數(shù)字i、ii、iii….[分析:]section.getPageSetup().getPageNumberStyle()獲取頁碼數(shù)字樣式,正文前面的章節(jié)應(yīng)該是NumberStyle.LOWERCASE_ROMAN后面的章節(jié)應(yīng)該是NumberStyle.ARABIC
第1章節(jié)開始,頁碼使用數(shù)字1、2、3…"[分析:]通過doc.getChildNodes(NodeType.SECTION, true)獲取所有章節(jié),section.getBody().getFirstParagraph()獲取章節(jié)正文第一個(gè)段落的樣式名,如果等于"標(biāo)題1"說明后面的其他章節(jié)包括本章是doc的正文部分,正文的第一個(gè)章節(jié)的頁碼需要重新計(jì)數(shù)檢查section.getPageSetup().getRestartPageNumbering()是否為true
圖表跨頁檢查檢查文檔中圖表標(biāo)注和圖表本身是否在同一頁[分析:]如果表前段落樣式為"Table Description",finder.GetPage(pre)!=finder.GetPage(table.getFirstChild())則表格的屬性段落與上下同頁未勾選,同理對于圖片前段落為"Figure Description"且finder.GetPage(shape)!=finder.GetPage(pre)則其與上下同頁未勾選
鏈接[分析:]doc.getRange().getFields()獲取所有域,field.getStart().getParentParagraph()可以獲得域的父段落
鏈接正確性檢查檢查文檔中所有鏈接是否正確(包含總目錄、章節(jié)目錄、文中的超鏈接及交叉引用)[分析:]field.isDirty()說明改域未更新,對于FieldType.FIELD_REF,獲取其引用getBookmarkName()==>doc.getRange().getBookmarks().get(bookmarkName)如果結(jié)果為null說明引用的目標(biāo)已經(jīng)被刪除了
歸檔檢查
修訂標(biāo)記歸檔時(shí)不允許出現(xiàn)修訂標(biāo)記[分析:]doc.getRevisions().getCount()>0則原文存在修訂標(biāo)記,doc.stopTrackRevisions()doc.setTrackRevisions(false)可以關(guān)閉修訂
批注歸檔時(shí)不允許出現(xiàn)批注[分析:]doc.getChildNodes(NodeType.COMMENT, true).getCount()>0則原文存在批注
=============================================================================
背景:
java環(huán)境下可以使用:
jacob是java調(diào)用com;
poi屬于獨(dú)立解析;
docx4j只支持docx,需要先將doc轉(zhuǎn)換成docx轉(zhuǎn)換;
試了試直接在doc里面寫一些vba,感覺分析效率太低了;
考慮到j(luò)acob很這種方式機(jī)制上比較相似,目前考慮先使用poi看看能不能達(dá)到預(yù)期;
==>由于poi不方便在doc格式下添加批注(docx可以)
后來采用了aspose,這個(gè)是個(gè)有些商業(yè)屬性的包
關(guān)于去除aspose功能限制,首先運(yùn)行下面的初始化代碼:
public?static?void?doInit(){ ?InputStream?is?=?xxxx.class.getClassLoader().getResourceAsStream("\license.xml"); ?License?aposeLic?=?new?License(); ?try?{ aposeLic.setLicense(is); }?catch?(Exception?e)?{ e.printStackTrace(); } ????}
運(yùn)行后可以定位到報(bào)錯的類和方法
我不是用的javassist進(jìn)行修改,aspose最近的版本javassit修改結(jié)果有問題,
使用jd-gui打開后找到對應(yīng)的類復(fù)制出來,在項(xiàng)目中的對應(yīng)于該類文件創(chuàng)建一個(gè)一樣的類,粘貼進(jìn)去,修改掉一些語法錯誤,
將target中生成的.class用壓縮工具拷貝回jar中對應(yīng)的位置,
刪除jar中的META-INF文件夾
參考:
aspose.word.19.3
aspose.words
Aspose-words 18.8
下面這個(gè)是個(gè)很有意思的問題:
現(xiàn)象p.getRange().replace似乎越界了,也像連續(xù)replace導(dǎo)致迭代器失效,下面這個(gè)方法可以解決這個(gè)問題
https://forum.aspose.com/t/range-replace-how-to-replace-first-occurence-only/40275
https://webcache.googleusercontent.com/search?q=cache:0WkLaYf_T4oJ:https://forum.aspose.com/t/range-replace-how-to-replace-first-occurence-only/40275+&cd=2&hl=zh-CN&ct=clnk
https://docs.aspose.com/display/wordsnet/Find+and+Replace
https://apireference.aspose.com/java/words/com.aspose.words/IReplacingCallback
https://blog.csdn.net/lqzkcx3/article/details/71414693
https://blog.csdn.net/WuLex/article/details/81702812
其他參考:
https://forum.aspose.com/t/multiple-lines-of-text-in-replace-command/126960
https://webcache.googleusercontent.com/search?q=cache:8jdDEL02sLQJ:https://docs.aspose.com/display/wordsjava/Find%2Band%2BReplace+&cd=2&hl=zh-CN&ct=clnk
https://forum.aspose.com/t/identifying-the-paragraph-and-edit-replace-delete/53097/2
https://www.cnblogs.com/ggjucheng/p/3423731.html
https://blog.csdn.net/weixin_34409703/article/details/85974476
測試doc內(nèi)容
0xDA00 0xDA01 0xDA02 0xDA03 0xDA04# 0xDA05 0xDA06(1256);. dddd 0xDA00 0xDA01(7788) dddd 0xDA02(3256) 0xDA03 0xDA04 0xDA05
處理
class?ReplaceFirstOccourance?implements?IReplacingCallback{
記錄兩個(gè)比較低級的問題
InputStream is=xxx.class.getClassLoader().getResourceAsStream("license.xml");
文件放在了resources目錄下,在eclipse中調(diào)試啟動可以正常找到到,打包成可執(zhí)行jar找不到這個(gè)文件了,
需要將resources路徑添加到Source中,這樣打包后才會出現(xiàn)在類路徑里
java 反射傳遞變長參數(shù)的例子
class?PWorker?extends?SwingWorker
jar運(yùn)行路徑下如果放了和jar中類路徑相同的.class文件,會導(dǎo)致java.lang.vertify的異常
附件: aspose-words-19.8-jdk17.zip 12.36M 下載次數(shù):1次
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。