Java Apache POI删除CTHyperlink[低级代码]

Java Apache POI删除CTHyperlink[低级代码],java,xml,hyperlink,ms-word,apache-poi,Java,Xml,Hyperlink,Ms Word,Apache Poi,继续我的实际错误: 使用此代码: public void eliminarHyperLink(XWPFDocument doc){ XWPFHeaderFooterPolicy policy= doc.getHeaderFooterPolicy(); XWPFFooter footer = policy.getDefaultFooter(); List<XWPFParagraph> paragraphs = footer.getParagraphs();

继续我的实际错误:

使用此代码:

public void eliminarHyperLink(XWPFDocument doc){
    XWPFHeaderFooterPolicy policy= doc.getHeaderFooterPolicy();
    XWPFFooter footer = policy.getDefaultFooter();
    List<XWPFParagraph> paragraphs = footer.getParagraphs();
    boolean primero = false;
    for (XWPFParagraph xwpfParagraph : paragraphs) {
        List<XWPFRun> runs = xwpfParagraph.getRuns();
        if(primero == true){
            for (XWPFRun run : runs) {
                if(run instanceof XWPFHyperlinkRun) {
                    XWPFHyperlinkRun linkRun = (XWPFHyperlinkRun)run;
                    ((XWPFHyperlinkRun) run).getCTHyperlink();
                    System.out.println(((XWPFHyperlinkRun) run).getCTHyperlink()); //Here is the output xml showen below
                }
            }
        }
        primero = true;
    }
}
public void eliminarHyperLink(XWPFDocument文档){
XWPFHeaderFooterPolicy=doc.getHeaderFooterPolicy();
xwpfooter footer=policy.getDefaultFooter();
列表段落=footer.getPages();
布尔素数=假;
对于(XWPFParagraph XWPFParagraph:段落){
List runs=xwpfParagraph.getRuns();
if(primero==true){
对于(XWPFRun运行:运行){
if(运行XWPFHyperlinkRun的实例){
XWPFHyperlinkRun linkRun=(XWPFHyperlinkRun)run;
((XWPFHyperlinkRun)run).getCTHyperlink();
System.out.println(((XWPFHyperlinkRun)run).getCTHyperlink());//下面是输出xml
}
}
}
primero=真;
}
}
到达包含我需要删除的超链接的xml,是否有方法删除该超链接

<xml-fragment r:id="rId1" w:history="1" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
<w:r w:rsidRPr="003A2DF6">
    <w:rPr>
        <w:rFonts w:ascii="Adobe Caslon Pro" w:hAnsi="Adobe Caslon Pro"/>
        <w:b/>
        <w:sz w:val="16"/>
        <w:szCs w:val="16"/>
    </w:rPr>
    <w:t>www.cnbv.gob.mx</w:t> //This is what I need to remove!!!!!!!!!!!
</w:r>
</xml-fragment>

www.cnbv.gob.mx//这就是我需要删除的内容!!!!!!!!!!!

如果有人有任何答案,我将非常感激!关于。

以下代码应删除段落列表中的所有超链接

import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHyperlink;

...
  for (XWPFParagraph paragraph : paragraphs) {
   List<CTHyperlink> hyperlinks = paragraph.getCTP().getHyperlinkList();
   CTHyperlink[] hyperlinksarr = hyperlinks.toArray(new CTHyperlink[0]);
   for (int i = 0; i < hyperlinksarr.length; i++ ) {
    CTHyperlink hyperlink = hyperlinksarr[i];
System.out.println(hyperlink.getRArray(0).getTArray(0).getStringValue());
    paragraph.getCTP().removeHyperlink(0);
   }
  }
...
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHyperlink;
...
对于(XWPFParagraph段落:段落){
列表超链接=段落.getCTP().getHyperlinkList();
CTHyperlink[]hyperlinksarr=hyperlinks.toArray(新的CTHyperlink[0]);
对于(int i=0;i
段落.getCTP().getHyperlinkList()
生成的
列表
似乎不正确。每个
迭代器和
似乎都不能使用它。因此,我从中创建了一个
数组

编辑:


当然,由
段落.getCTP().getHyperlinkList()
生成的
列表
对于使用
迭代器
对每个
都是正确的。但我不正确;-)。如果我们在迭代此列表时从列表中删除元素,那么如果
迭代器将被弄乱,我们也不会感到惊讶。

I这两天怎么样,非常感谢!很好,你救了我!问候和感谢!