Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions OpenXmlFormats/Wordprocessing/Paragraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using NPOI.OpenXml4Net.Util;
using System.Collections;
using System.CodeDom;

namespace NPOI.OpenXmlFormats.Wordprocessing
{
Expand Down Expand Up @@ -171,12 +172,16 @@ public static CT_P Parse(XmlNode node, XmlNamespaceManager namespaceManager)
}
else if (childNode.LocalName == "fldSimple")
{
ctObj.Items.Add(CT_SimpleField.Parse(childNode, namespaceManager));
var sf = CT_SimpleField.Parse(childNode, namespaceManager);
sf.parent = ctObj;
ctObj.Items.Add(sf);
ctObj.ItemsElementName.Add(ParagraphItemsChoiceType.fldSimple);
}
else if (childNode.LocalName == "hyperlink")
{
ctObj.Items.Add(CT_Hyperlink1.Parse(childNode, namespaceManager));
var hl=CT_Hyperlink1.Parse(childNode, namespaceManager);
hl.parent = ctObj;
ctObj.Items.Add(hl);
ctObj.ItemsElementName.Add(ParagraphItemsChoiceType.hyperlink);
}
else if (childNode.LocalName == "ins")
Expand Down Expand Up @@ -247,7 +252,40 @@ public bool IsSetRsidR()
{
return this.rsidRField != null && rsidRField.Length > 0;
}

public void RemoveHyperlink(CT_Hyperlink1 hl)
{
int index=-1;
for(int i = 0; i<Items.Count; i++)
{
if(Items[i].Equals(hl))
{
index=i;
break;
}
}
if(index>=0)
{
Items.RemoveAt(index);
ItemsElementName.RemoveAt(index);
}
}
public void RemoveSimpleField(CT_SimpleField sf)
{
int index=-1;
for(int i = 0; i<Items.Count; i++)
{
if(Items[i].Equals(sf))
{
index=i;
break;
}
}
if(index>=0)
{
Items.RemoveAt(index);
ItemsElementName.RemoveAt(index);
}
}
internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<w:{0}", nodeName));
Expand Down
43 changes: 43 additions & 0 deletions OpenXmlFormats/Wordprocessing/wml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,7 @@ public class CT_SimpleField
private ST_OnOff dirtyField;

private bool dirtyFieldSpecified;
internal CT_P parent;

public CT_SimpleField()
{
Expand All @@ -1732,6 +1733,13 @@ public CT_SimpleField()
//this.fldDataField = new CT_Text();
}

public CT_R AddNewR()
{
CT_R r = new CT_R();
this.itemsField.Add(r);
return r;
}

[XmlElement(Order = 0)]
public CT_Text fldData
{
Expand All @@ -1744,6 +1752,17 @@ public CT_Text fldData
this.fldDataField = value;
}
}
public CT_P Parent
{
get
{
return parent;
}
set
{
parent=value;
}
}
public static CT_SimpleField Parse(XmlNode node, XmlNamespaceManager namespaceManager)
{
if (node == null)
Expand Down Expand Up @@ -2349,11 +2368,23 @@ public class CT_Hyperlink1

private string idField;

internal CT_P parent;

public CT_Hyperlink1()
{
this.itemsElementNameField = new List<ItemsChoiceType12>();
this.itemsField = new ArrayList();
}
public CT_P Parent
{
get
{
return parent;
}
set {
parent=value;
}
}
public static CT_Hyperlink1 Parse(XmlNode node, XmlNamespaceManager namespaceManager)
{
if (node == null)
Expand Down Expand Up @@ -2658,6 +2689,18 @@ public ArrayList Items
}
}

public CT_R AddNewR()
{
CT_R r = new CT_R();
this.Items.Add(r);
return r;
}

public CT_R GetRArray(int index)
{
return this.itemsField[index] as CT_R;
}

[XmlElement("ItemsElementName", Order = 1)]
[XmlIgnore]
public List<ItemsChoiceType12> ItemsElementName
Expand Down
11 changes: 11 additions & 0 deletions ooxml/XWPF/Usermodel/XWPFDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,17 @@ public XWPFHyperlink GetHyperlinkByID(String id)
return link;
}

// If the link was not found, rebuild the list (maybe a new link was added into the document) and check again.
InitHyperlinks();
foreach(XWPFHyperlink link in hyperlinks)
{
if(link.Id.Equals(id))
{
return link;
}
}
// Link still not there? Giving up.

return null;
}

Expand Down
Loading
Loading