Skip to content

Commit

Permalink
Merge pull request #588 from nissl-lab/DocxFixes
Browse files Browse the repository at this point in the history
Fixes for NPOI 2.5.4
  • Loading branch information
tonyqus authored Aug 2, 2021
2 parents 1fab8ce + 936dbe7 commit 10ee636
Show file tree
Hide file tree
Showing 37 changed files with 419 additions and 354 deletions.
9 changes: 8 additions & 1 deletion OpenXmlFormats/Drawing/BaseTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,14 @@ public class CT_Point2D

private long yField;

private string name;

public static CT_Point2D Parse(XmlNode node, XmlNamespaceManager namespaceManager)
{
if (node == null)
return null;
CT_Point2D ctObj = new CT_Point2D();
ctObj.name = node.Name;
ctObj.x = XmlHelper.ReadLong(node.Attributes["x"]);
ctObj.y = XmlHelper.ReadLong(node.Attributes["y"]);
return ctObj;
Expand All @@ -267,7 +270,11 @@ public static CT_Point2D Parse(XmlNode node, XmlNamespaceManager namespaceManage

internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<a:{0}", nodeName));
if (name == null)
sw.Write(string.Format("<a:{0}", nodeName));
else
sw.Write(string.Format("<{0}", name));

XmlHelper.WriteAttribute(sw, "x", this.x, true);
XmlHelper.WriteAttribute(sw, "y", this.y, true);
sw.Write("/>");
Expand Down
12 changes: 9 additions & 3 deletions OpenXmlFormats/Drawing/ShapeProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,16 @@ internal void Write(StreamWriter sw, string nodeName)
XmlHelper.WriteAttribute(sw, "noChangeAspect", this.noChangeAspect, false);
XmlHelper.WriteAttribute(sw, "noMove", this.noMove, false);
XmlHelper.WriteAttribute(sw, "noResize", this.noResize, false);
sw.Write(">");
if (this.extLst != null)
if (this.extLst != null && this.extLst.ext.Count != 0)
{
sw.Write(">");
this.extLst.Write(sw, "extLst");
sw.Write(string.Format("</a:{0}>", nodeName));
sw.Write(string.Format("</a:{0}>", nodeName));
}
else
{
sw.Write("/>");
}
}

[XmlElement(Order = 0)]
Expand Down
152 changes: 102 additions & 50 deletions OpenXmlFormats/Drawing/WordprocessingDrawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ internal void Write(StreamWriter sw, string nodeName)
sw.Write(string.Format("<wp:{0}", nodeName));
XmlHelper.WriteAttribute(sw, "id", this.id, true);
XmlHelper.WriteAttribute(sw, "name", this.name);
XmlHelper.WriteAttribute(sw, "descr", this.descr);
XmlHelper.WriteAttribute(sw, "descr", this.descr.Replace("\n", "&#xA;").Replace("\r", "&#xD;"));
if(this.hidden)
XmlHelper.WriteAttribute(sw, "hidden", this.hidden);
sw.Write(">");
Expand Down Expand Up @@ -712,8 +712,7 @@ internal void Write(StreamWriter sw, string nodeName)
XmlHelper.WriteAttribute(sw, "t", this.t, true);
XmlHelper.WriteAttribute(sw, "r", this.r, true);
XmlHelper.WriteAttribute(sw, "b", this.b, true);
sw.Write(">");
sw.Write(string.Format("</wp:{0}>", nodeName));
sw.Write("/>");
}

[XmlAttribute]
Expand Down Expand Up @@ -1206,17 +1205,17 @@ public static CT_Anchor Parse(XmlNode node, XmlNamespaceManager namespaceManager
if (node == null)
return null;
CT_Anchor ctObj = new CT_Anchor();
ctObj.distT = XmlHelper.ReadUInt(node.Attributes["wp:distT"]);
ctObj.distB = XmlHelper.ReadUInt(node.Attributes["wp:distB"]);
ctObj.distL = XmlHelper.ReadUInt(node.Attributes["wp:distL"]);
ctObj.distR = XmlHelper.ReadUInt(node.Attributes["wp:distR"]);
ctObj.simplePos1 = XmlHelper.ReadBool(node.Attributes["wp:simplePos1"]);
ctObj.relativeHeight = XmlHelper.ReadUInt(node.Attributes["wp:relativeHeight"]);
ctObj.behindDoc = XmlHelper.ReadBool(node.Attributes["wp:behindDoc"]);
ctObj.locked = XmlHelper.ReadBool(node.Attributes["wp:locked"]);
ctObj.layoutInCell = XmlHelper.ReadBool(node.Attributes["wp:layoutInCell"]);
ctObj.hidden = XmlHelper.ReadBool(node.Attributes["wp:hidden"]);
ctObj.allowOverlap = XmlHelper.ReadBool(node.Attributes["wp:allowOverlap"]);
ctObj.distT = XmlHelper.ReadUInt(node.Attributes["distT"]);
ctObj.distB = XmlHelper.ReadUInt(node.Attributes["distB"]);
ctObj.distL = XmlHelper.ReadUInt(node.Attributes["distL"]);
ctObj.distR = XmlHelper.ReadUInt(node.Attributes["distR"]);
ctObj.simplePos1 = XmlHelper.ReadBool(node.Attributes["simplePos"]);
ctObj.relativeHeight = XmlHelper.ReadUInt(node.Attributes["relativeHeight"]);
ctObj.behindDoc = XmlHelper.ReadBool(node.Attributes["behindDoc"]);
ctObj.locked = XmlHelper.ReadBool(node.Attributes["locked"]);
ctObj.layoutInCell = XmlHelper.ReadBool(node.Attributes["layoutInCell"]);
ctObj.hidden = XmlHelper.ReadBool(node.Attributes["hidden"]);
ctObj.allowOverlap = XmlHelper.ReadBool(node.Attributes["allowOverlap"]);
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.LocalName == "simplePos")
Expand All @@ -1227,6 +1226,10 @@ public static CT_Anchor Parse(XmlNode node, XmlNamespaceManager namespaceManager
ctObj.positionV = CT_PosV.Parse(childNode, namespaceManager);
else if (childNode.LocalName == "extent")
ctObj.extent = CT_PositiveSize2D.Parse(childNode, namespaceManager);
else if (childNode.LocalName == "wrapSquare")
ctObj.wrapSquare = CT_WrapSquare.Parse(childNode, namespaceManager);
else if (childNode.LocalName == "wrapNone")
ctObj.wrapNone = new CT_WrapNone();
else if (childNode.LocalName == "effectExtent")
ctObj.effectExtent = CT_EffectExtent.Parse(childNode, namespaceManager);
else if (childNode.LocalName == "docPr")
Expand All @@ -1244,17 +1247,17 @@ public static CT_Anchor Parse(XmlNode node, XmlNamespaceManager namespaceManager
internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<wp:{0}", nodeName));
XmlHelper.WriteAttribute(sw, "wp:distT", this.distT);
XmlHelper.WriteAttribute(sw, "wp:distB", this.distB);
XmlHelper.WriteAttribute(sw, "wp:distL", this.distL);
XmlHelper.WriteAttribute(sw, "wp:distR", this.distR);
XmlHelper.WriteAttribute(sw, "wp:simplePos1", this.simplePos1);
XmlHelper.WriteAttribute(sw, "wp:relativeHeight", this.relativeHeight);
XmlHelper.WriteAttribute(sw, "wp:behindDoc", this.behindDoc);
XmlHelper.WriteAttribute(sw, "wp:locked", this.locked);
XmlHelper.WriteAttribute(sw, "wp:layoutInCell", this.layoutInCell);
XmlHelper.WriteAttribute(sw, "wp:hidden", this.hidden);
XmlHelper.WriteAttribute(sw, "wp:allowOverlap", this.allowOverlap);
XmlHelper.WriteAttribute(sw, "distT", this.distT);
XmlHelper.WriteAttribute(sw, "distB", this.distB);
XmlHelper.WriteAttribute(sw, "distL", this.distL);
XmlHelper.WriteAttribute(sw, "distR", this.distR);
XmlHelper.WriteAttribute(sw, "simplePos", this.simplePos1);
XmlHelper.WriteAttribute(sw, "relativeHeight", this.relativeHeight);
XmlHelper.WriteAttribute(sw, "behindDoc", this.behindDoc);
XmlHelper.WriteAttribute(sw, "locked", this.locked);
XmlHelper.WriteAttribute(sw, "layoutInCell", this.layoutInCell);
XmlHelper.WriteAttribute(sw, "hidden", this.hidden);
XmlHelper.WriteAttribute(sw, "allowOverlap", this.allowOverlap);
sw.Write(">");
if (this.simplePos != null)
this.simplePos.Write(sw, "simplePos");
Expand All @@ -1266,6 +1269,10 @@ internal void Write(StreamWriter sw, string nodeName)
this.extent.Write(sw, "extent");
if (this.effectExtent != null)
this.effectExtent.Write(sw, "effectExtent");
if (this.wrapSquare != null)
this.wrapSquare.Write(sw, "wrapSquare");
if (this.wrapNone != null)
this.wrapNone.Write(sw, "wrapNone");
if (this.docPr != null)
this.docPr.Write(sw, "docPr");
if (this.cNvGraphicFramePr != null)
Expand All @@ -1277,7 +1284,6 @@ internal void Write(StreamWriter sw, string nodeName)

}


[Serializable]

[XmlType(Namespace = "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing")]
Expand All @@ -1289,11 +1295,18 @@ public static CT_PosH Parse(XmlNode node, XmlNamespaceManager namespaceManager)
if (node == null)
return null;
CT_PosH ctObj = new CT_PosH();
ctObj.posOffset = XmlHelper.ReadInt(node.Attributes["wp:posOffset"]);
if (node.Attributes["wp:align"] != null)
ctObj.align = (ST_AlignH)Enum.Parse(typeof(ST_AlignH), node.Attributes["wp:align"].Value);
if (node.Attributes["wp:relativeFrom"] != null)
ctObj.relativeFrom = (ST_RelFromH)Enum.Parse(typeof(ST_RelFromH), node.Attributes["wp:relativeFrom"].Value);

if (node.Attributes["relativeFrom"] != null)
ctObj.relativeFrom = (ST_RelFromH)Enum.Parse(typeof(ST_RelFromH), node.Attributes["relativeFrom"].Value);

foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.LocalName == "posOffset")
ctObj.posOffset = int.TryParse(childNode.InnerText, out var i ) ? i : (int?)null;
else if (childNode.LocalName == "align")
ctObj.align = (ST_AlignH)Enum.Parse(typeof(ST_AlignH), childNode.InnerText);
}

return ctObj;
}

Expand All @@ -1302,24 +1315,29 @@ public static CT_PosH Parse(XmlNode node, XmlNamespaceManager namespaceManager)
internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<wp:{0}", nodeName));
XmlHelper.WriteAttribute(sw, "wp:posOffset", this.posOffset);
XmlHelper.WriteAttribute(sw, "wp:align", this.align.ToString());
XmlHelper.WriteAttribute(sw, "wp:relativeFrom", this.relativeFrom.ToString());
XmlHelper.WriteAttribute(sw, "relativeFrom", this.relativeFrom.ToString());
sw.Write(">");

if (this.posOffset != null)
sw.Write(string.Format("<wp:posOffset>{0}</wp:posOffset>", this.posOffset.Value));

if (this.align != null)
sw.Write(string.Format("<wp:align>{0}</wp:align>", this.align.Value));

sw.Write(string.Format("</wp:{0}>", nodeName));
}

private ST_RelFromH relativeFromField;

Int32 posOffsetField;
public Int32 posOffset
int? posOffsetField;
public int? posOffset
{
get { return this.posOffsetField; }
set { this.posOffsetField = value; }
}

ST_AlignH alignField;
public ST_AlignH align
ST_AlignH? alignField;
public ST_AlignH? align
{
get { return this.alignField; }
set { this.alignField = value; }
Expand Down Expand Up @@ -1406,11 +1424,18 @@ public static CT_PosV Parse(XmlNode node, XmlNamespaceManager namespaceManager)
if (node == null)
return null;
CT_PosV ctObj = new CT_PosV();
ctObj.posOffset = XmlHelper.ReadInt(node.Attributes["wp:posOffset"]);
if (node.Attributes["wp:align"] != null)
ctObj.align = (ST_AlignV)Enum.Parse(typeof(ST_AlignV), node.Attributes["wp:align"].Value);
if (node.Attributes["wp:relativeFrom"] != null)
ctObj.relativeFrom = (ST_RelFromV)Enum.Parse(typeof(ST_RelFromV), node.Attributes["wp:relativeFrom"].Value);

if (node.Attributes["relativeFrom"] != null)
ctObj.relativeFrom = (ST_RelFromV)Enum.Parse(typeof(ST_RelFromV), node.Attributes["relativeFrom"].Value);

foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.LocalName == "posOffset")
ctObj.posOffset = int.TryParse(childNode.InnerText, out var i) ? i : (int?)null;
else if (childNode.LocalName == "align")
ctObj.align = (ST_AlignV)Enum.Parse(typeof(ST_AlignV), childNode.InnerText);
}

return ctObj;
}

Expand All @@ -1419,24 +1444,29 @@ public static CT_PosV Parse(XmlNode node, XmlNamespaceManager namespaceManager)
internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<wp:{0}", nodeName));
XmlHelper.WriteAttribute(sw, "wp:posOffset", this.posOffset);
XmlHelper.WriteAttribute(sw, "wp:align", this.align.ToString());
XmlHelper.WriteAttribute(sw, "wp:relativeFrom", this.relativeFrom.ToString());
XmlHelper.WriteAttribute(sw, "relativeFrom", this.relativeFrom.ToString());
sw.Write(">");

if (this.posOffset != null)
sw.Write(string.Format("<wp:posOffset>{0}</wp:posOffset>", this.posOffset.Value));

if (this.align != null)
sw.Write(string.Format("<wp:align>{0}</wp:align>", this.align.Value));

sw.Write(string.Format("</wp:{0}>", nodeName));
}

private ST_RelFromV relativeFromField;

Int32 posOffsetField;
public Int32 posOffset
int? posOffsetField;
public int? posOffset
{
get { return this.posOffsetField; }
set { this.posOffsetField = value; }
}

ST_AlignV alignField;
public ST_AlignV align
ST_AlignV? alignField;
public ST_AlignV? align
{
get { return this.alignField; }
set { this.alignField = value; }
Expand Down Expand Up @@ -1518,6 +1548,11 @@ public enum ST_RelFromV
[XmlRoot(Namespace = "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", IsNullable = true)]
public class CT_WrapNone
{
internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<wp:{0}", nodeName));
sw.Write("/>");
}
}


Expand Down Expand Up @@ -1556,6 +1591,23 @@ public CT_WrapSquare()
this.effectExtentField = new CT_EffectExtent();
}

public static CT_WrapSquare Parse(XmlNode node, XmlNamespaceManager namespaceManager)
{
if (node == null)
return null;

CT_WrapSquare ctObj = new CT_WrapSquare();
ctObj.wrapText = (ST_WrapText)Enum.Parse(typeof(ST_WrapText), node.Attributes["wrapText"].Value);
return ctObj;
}

internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<wp:{0}", nodeName));
XmlHelper.WriteAttribute(sw, "wrapText", this.wrapText.ToString(), true);
sw.Write("/>");
}

[XmlElement(Order = 0)]
public CT_EffectExtent effectExtent
{
Expand Down
4 changes: 4 additions & 0 deletions OpenXmlFormats/NPOI.OpenXmlFormats.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<OutputPath>..\solution\Lib</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
<DocumentationFile></DocumentationFile>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\main\NPOI.Core.csproj" />
<ProjectReference Include="..\openxml4Net\NPOI.OpenXml4Net.Core.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion OpenXmlFormats/NPOI.OpenXmlFormats.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down
4 changes: 2 additions & 2 deletions OpenXmlFormats/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.5.3.0")]
[assembly: AssemblyFileVersion("2.5.3.0")]
[assembly: AssemblyVersion("2.5.4.0")]
[assembly: AssemblyFileVersion("2.5.4.0")]
[assembly: AssemblyInformationalVersion("2.0.0.0")]
#if NETSTANDARD2_1 || NETSTANDARD2_0 || NET40
[assembly: AllowPartiallyTrustedCallers]
Expand Down
2 changes: 1 addition & 1 deletion OpenXmlFormats/Spreadsheet/Styles/CT_PatternFill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CT_PatternFill

public bool IsSetPatternType()
{
return this.patternTypeField != ST_PatternType.none;
return this.patternTypeField!=null&&this.patternTypeField != ST_PatternType.none;
}
public CT_Color AddNewFgColor()
{
Expand Down
3 changes: 1 addition & 2 deletions OpenXmlFormats/Wordprocessing/BaseTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<w:{0}", nodeName));
XmlHelper.WriteAttribute(sw, "w:val", this.val);
sw.Write(">");
sw.Write(string.Format("</w:{0}>", nodeName));
sw.Write("/>");
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions OpenXmlFormats/Wordprocessing/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ internal void Write(StreamWriter sw)
sw.Write("xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" ");
sw.Write("xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" ");
sw.Write("xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" ");
//sw.Write("xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" ");
sw.Write("xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">");
//sw.Write("mc:Ignorable=\"w14\">");
if (this.body != null)
this.body.Write(sw, "body");
if (this.background != null)
Expand Down
Loading

0 comments on commit 10ee636

Please sign in to comment.