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
7 changes: 7 additions & 0 deletions OpenXmlFormats/Drawing/BaseTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public string uri
set
{
this.uriField = value;
this.uriSpecifiedField = !string.IsNullOrEmpty(this.uriField);
}
}

Expand Down Expand Up @@ -2114,6 +2115,12 @@ public List<CT_OfficeArtExtension> ext
this.extField = value;
}
}

public CT_OfficeArtExtension AddNewExt()
{
extField.Add(new CT_OfficeArtExtension());
return extField[extField.Count - 1];
}
}

[Serializable]
Expand Down
76 changes: 71 additions & 5 deletions OpenXmlFormats/Drawing/SpreadsheetDrawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ public bool hiddenSpecified
{
get { return (null != hiddenField); }
}

public CT_OfficeArtExtensionList AddNewExtLst()
{
this.extLstField = new CT_OfficeArtExtensionList();
return this.extLst;
}
}
[Serializable]
[System.ComponentModel.DesignerCategoryAttribute("code")]
Expand Down Expand Up @@ -627,6 +633,13 @@ public CT_SolidColorFillProperties AddNewSolidFill()
this.solidFillField = new CT_SolidColorFillProperties();
return this.solidFillField;
}

public CT_BlipFillProperties AddNewBlipFill()
{
this.blipFillField = new CT_BlipFillProperties();
return this.blipFillField;
}

public CT_CustomGeometry2D AddNewCustGeom()
{
this.custGeomField = new CT_CustomGeometry2D();
Expand Down Expand Up @@ -1317,7 +1330,7 @@ public class CT_Drawing
{
private List<IEG_Anchor> cellAnchors = new List<IEG_Anchor>();
//private List<CT_AbsoulteCellAnchor> absoluteCellAnchors = new List<CT_AbsoulteCellAnchor>();

private bool inAlternateContent = false;
public CT_TwoCellAnchor AddNewTwoCellAnchor()
{
CT_TwoCellAnchor anchor = new CT_TwoCellAnchor();
Expand All @@ -1343,10 +1356,21 @@ public void Save(Stream stream)
{
sw.Write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
sw.Write("<xdr:wsDr xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">");
if(inAlternateContent)
{
sw.Write("<mc:AlternateContent xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\">");
sw.Write("<mc:Choice xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" Requires=\"a14\">");
}
foreach (IEG_Anchor anchor in this.cellAnchors)
{
anchor.Write(sw);
}
if(inAlternateContent)
{
sw.Write("</mc:Choice>");
sw.Write("<mc:Fallback />");
sw.Write("</mc:AlternateContent>");
}
sw.Write("</xdr:wsDr>");
}
}
Expand Down Expand Up @@ -1399,11 +1423,18 @@ public static CT_Drawing Parse(XmlDocument xmldoc, XmlNamespaceManager namespace
{
return new CT_Drawing();
}
XmlNodeList cellanchorNodes = root.SelectNodes("descendant::xdr:oneCellAnchor|descendant::xdr:twoCellAnchor|descendant::xdr:absCellAnchor", namespaceManager);
//XmlNodeList childNodes = root.SelectNodes("descendant::xdr:oneCellAnchor|descendant::xdr:twoCellAnchor|descendant::xdr:absCellAnchor", namespaceManager);
XmlNodeList childNodes = xmldoc.SelectNodes("/xdr:wsDr/*", namespaceManager);
CT_Drawing ctDrawing = new CT_Drawing();
foreach (XmlNode node in cellanchorNodes)
// handle with-/out AlternateContent wrappers
foreach (XmlNode node in childNodes)
{
if (node.LocalName == "twoCellAnchor")
if(node.LocalName == "AlternateContent")
{
ctDrawing.inAlternateContent = true;
ctDrawing.cellAnchors.Add(ParseAlternateContent(node, namespaceManager));
}
else if (node.LocalName == "twoCellAnchor")
{
CT_TwoCellAnchor twoCellAnchor = CT_TwoCellAnchor.Parse(node, namespaceManager);
ctDrawing.cellAnchors.Add(twoCellAnchor);
Expand All @@ -1421,6 +1452,40 @@ public static CT_Drawing Parse(XmlDocument xmldoc, XmlNamespaceManager namespace
}
return ctDrawing;
}

private static IEG_Anchor ParseAlternateContent(XmlNode node, XmlNamespaceManager namespaceManager)
{
IEG_Anchor anchor = null;
if(node.ChildNodes.Count == 0)
return null;
if(node.ChildNodes[0].LocalName == "Choice")
{
foreach(XmlNode cnode in node.ChildNodes[0].ChildNodes)
{
if(cnode.LocalName == "twoCellAnchor")
{
anchor = CT_TwoCellAnchor.Parse(cnode, namespaceManager);
}
else if(cnode.LocalName == "oneCellAnchor")
{
anchor = CT_OneCellAnchor.Parse(cnode, namespaceManager);
}
else if(cnode.LocalName == "absCellAnchor")
{
anchor = CT_AbsoluteCellAnchor.Parse(cnode, namespaceManager);
}
else
{
throw new InvalidOperationException($"invalid localname {cnode.LocalName}");
}
}
}
else
{
throw new NotImplementedException($"invalid localname {node.ChildNodes[0].LocalName}");
}
return anchor;
}
}
[Serializable]
[XmlType(Namespace = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")]
Expand Down Expand Up @@ -1950,7 +2015,7 @@ internal static CT_TwoCellAnchor Parse(XmlNode node, XmlNamespaceManager namespa

[Serializable]
[XmlType(Namespace = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")]
public class CT_Connector // empty interface: EG_ObjectChoices
public class CT_Connector: XmlObject // empty interface: EG_ObjectChoices
{
string macroField;
bool fPublishedField;
Expand Down Expand Up @@ -1978,6 +2043,7 @@ public static CT_Connector Parse(XmlNode node, XmlNamespaceManager namespaceMana
else if (childNode.LocalName == "style")
ctObj.style = CT_ShapeStyle.Parse(childNode, namespaceManager);
}
ctObj.Node = node;
return ctObj;
}

Expand Down
6 changes: 4 additions & 2 deletions OpenXmlFormats/Drawing/SpreadsheetPicture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace NPOI.OpenXmlFormats.Dml.Spreadsheet

[Serializable]
[XmlType(Namespace = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")]
public class CT_Picture // empty interface: EG_ObjectChoices
public class CT_Picture : XmlObject // empty interface: EG_ObjectChoices
{
private CT_PictureNonVisual nvPicPrField = new CT_PictureNonVisual(); // draw-ssdraw: 1..1
private CT_BlipFillProperties blipFillField = new CT_BlipFillProperties(); // draw-ssdraw: 1..1
Expand All @@ -37,6 +37,7 @@ public static CT_Picture Parse(XmlNode node, XmlNamespaceManager namespaceManage
else if (childNode.LocalName == "style")
ctObj.style = CT_ShapeStyle.Parse(childNode, namespaceManager);
}
ctObj.Node = node;
return ctObj;
}

Expand Down Expand Up @@ -167,7 +168,7 @@ public void Set(CT_Picture pict)
// see same class in different name space in Picture.cs
[Serializable]
[XmlType(Namespace = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")]
public class CT_PictureNonVisual
public class CT_PictureNonVisual: XmlObject
{

private CT_NonVisualDrawingProps cNvPrField = new CT_NonVisualDrawingProps(); // 1..1
Expand All @@ -185,6 +186,7 @@ public static CT_PictureNonVisual Parse(XmlNode node, XmlNamespaceManager namesp
else if (childNode.LocalName == "cNvPicPr")
ctObj.cNvPicPr = CT_NonVisualPictureProperties.Parse(childNode, namespaceManager);
}
ctObj.Node = node;
return ctObj;
}

Expand Down
24 changes: 18 additions & 6 deletions OpenXmlFormats/Drawing/spreadsheetShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@

namespace NPOI.OpenXmlFormats.Dml.Spreadsheet
{
/// <summary>
/// Hold xml data
/// </summary>
public class XmlObject
{
public XmlNode Node { get; set; }
}
[Serializable]
[XmlType(Namespace = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")]
public class CT_Shape // empty interface: EG_ObjectChoices
public class CT_Shape : XmlObject // empty interface: EG_ObjectChoices
{
private CT_ShapeNonVisual nvSpPrField;
private CT_ShapeProperties spPrField;
Expand Down Expand Up @@ -57,6 +64,7 @@ public static CT_Shape Parse(XmlNode node, XmlNamespaceManager namespaceManager)
else if (childNode.LocalName == "style")
ctObj.style = CT_ShapeStyle.Parse(childNode, namespaceManager);
}
ctObj.Node = node;
return ctObj;
}

Expand Down Expand Up @@ -179,7 +187,7 @@ public bool fPublished

[System.ComponentModel.DesignerCategory("code")]
[XmlType(Namespace = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")]
public class CT_TextBody
public class CT_TextBody : XmlObject
{

private CT_TextBodyProperties bodyPrField;
Expand All @@ -203,6 +211,7 @@ public static CT_TextBody Parse(XmlNode node, XmlNamespaceManager namespaceManag
else if (childNode.LocalName == "p")
ctObj.p.Add(CT_TextParagraph.Parse(childNode, namespaceManager));
}
ctObj.Node = node;
return ctObj;
}

Expand Down Expand Up @@ -441,7 +450,7 @@ public CT_FontReference fontRef

[Serializable]
[XmlType(Namespace = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")]
public class CT_ShapeNonVisual
public class CT_ShapeNonVisual : XmlObject
{
private CT_NonVisualDrawingProps cNvPrField;
private CT_NonVisualDrawingShapeProps cNvSpPrField;
Expand Down Expand Up @@ -491,6 +500,7 @@ public static CT_ShapeNonVisual Parse(XmlNode node, XmlNamespaceManager namespac
else if (childNode.LocalName == "cNvSpPr")
ctObj.cNvSpPr = CT_NonVisualDrawingShapeProps.Parse(childNode, namespaceManager);
}
ctObj.Node = node;
return ctObj;
}

Expand Down Expand Up @@ -595,7 +605,7 @@ public bool txBox
}
[Serializable]
[XmlType(Namespace = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")]
public class CT_GroupShape
public class CT_GroupShape : XmlObject
{
CT_GroupShapeProperties grpSpPrField;
CT_GroupShapeNonVisual nvGrpSpPrField;
Expand Down Expand Up @@ -646,7 +656,7 @@ public CT_Picture AddNewPic()
pictures.Add(pic);
return pic;
}
public CT_GroupShape AddNewGroup()
public CT_GroupShape AddNewGroupShape()
{
var group = new CT_GroupShape();
groups.Add(group);
Expand Down Expand Up @@ -734,6 +744,7 @@ public static CT_GroupShape Parse(XmlNode node, XmlNamespaceManager namespaceMan
ctObj.groups.Add(group);
}
}
ctObj.Node = node;
return ctObj;
}

Expand Down Expand Up @@ -782,7 +793,7 @@ internal void Write(StreamWriter sw, string nodeName)

[Serializable]
[XmlType(Namespace = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")]
public class CT_GroupShapeNonVisual
public class CT_GroupShapeNonVisual : XmlObject
{
CT_NonVisualDrawingProps cNvPrField;
CT_NonVisualGroupDrawingShapeProps cNvGrpSpPrField;
Expand All @@ -798,6 +809,7 @@ public static CT_GroupShapeNonVisual Parse(XmlNode node, XmlNamespaceManager nam
else if (childNode.LocalName == "cNvGrpSpPr")
ctObj.cNvGrpSpPr = CT_NonVisualGroupDrawingShapeProps.Parse(childNode, namespaceManager);
}
ctObj.Node = node;
return ctObj;
}

Expand Down
Loading
Loading