Skip to content

Commit

Permalink
Merge branch 'master' of https:/nissl-lab/npoi
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyqus committed Apr 24, 2024
2 parents 83106c2 + 989cb6b commit e82fa27
Show file tree
Hide file tree
Showing 24 changed files with 904 additions and 472 deletions.
147 changes: 146 additions & 1 deletion OpenXmlFormats/Spreadsheet/CustomXmlMappings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using NPOI.OpenXml4Net.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

Expand All @@ -23,6 +25,40 @@ public class CT_MapInfo

private string selectionNamespacesField = string.Empty; // 1..1

public static CT_MapInfo Parse(XmlNode node, XmlNamespaceManager namespaceManager)
{
CT_MapInfo ctObj = new CT_MapInfo();
ctObj.SelectionNamespaces = XmlHelper.ReadString(node.Attributes["SelectionNamespaces"]);
foreach(XmlNode cn in node.ChildNodes)
{
if(cn.LocalName == "Schema")
{
ctObj.Schema.Add(CT_Schema.Parse(cn, namespaceManager));
}
else if(cn.LocalName == "Map")
{
ctObj.Map.Add(CT_Map.Parse(cn, namespaceManager));
}
}
return ctObj;
}

internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<{0}", nodeName));
XmlHelper.WriteAttribute(sw, "SelectionNamespaces", this.SelectionNamespaces);
sw.Write(">");
foreach(CT_Schema ctSchema in Schema)
{
ctSchema.Write(sw, "Schema");
}

foreach(CT_Map ctMap in Map)
{
ctMap.Write(sw, "Map");
}
sw.Write(string.Format("</{0}>", nodeName));
}
[XmlElement("Schema")]
public List<CT_Schema> Schema
{
Expand Down Expand Up @@ -77,6 +113,30 @@ public class CT_Schema

private string namespaceField = null; // 0..1

private string schemaLanguageField;

public static CT_Schema Parse(XmlNode node, XmlNamespaceManager namespaceManager)
{
CT_Schema ctObj = new CT_Schema();
ctObj.ID = node.Attributes["ID"].Value;
ctObj.Namespace = XmlHelper.ReadString(node.Attributes["Namespace"]);
ctObj.SchemaRef = XmlHelper.ReadString(node.Attributes["SchemaRef"]);
ctObj.SchemaLanguage = XmlHelper.ReadString(node.Attributes["SchemaLanguage"]);
ctObj.Any = node.FirstChild as XmlElement;
return ctObj;
}
internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<{0}", nodeName));
XmlHelper.WriteAttribute(sw, "ID", this.ID);
XmlHelper.WriteAttribute(sw, "Namespace", this.Namespace);
XmlHelper.WriteAttribute(sw, "SchemaRef", this.SchemaRef);
XmlHelper.WriteAttribute(sw, "SchemaLanguage", this.SchemaLanguage);
sw.Write(">");
if(anyField != null)
sw.Write(anyField.OuterXml);
sw.Write(string.Format("</{0}>", nodeName));
}
[XmlAnyElement]
public System.Xml.XmlElement Any
{
Expand Down Expand Up @@ -144,7 +204,23 @@ public bool NamespaceSpecified
get { return null != this.namespaceField; }
}

public string InnerXml;
public string SchemaLanguage
{
get
{
return this.schemaLanguageField;
}
set
{
schemaLanguageField = value;
}
}

[XmlIgnore]
public bool SchemaLanguageSpecified
{
get { return null != this.schemaLanguageField; }
}
}


Expand Down Expand Up @@ -176,6 +252,49 @@ public class CT_Map

private bool preserveFormatField;

public static CT_Map Parse(XmlNode node, XmlNamespaceManager namespaceManager)
{
CT_Map ctMap = new CT_Map();
ctMap.ID = XmlHelper.ReadUInt(node.Attributes["ID"]);
ctMap.Name = XmlHelper.ReadString(node.Attributes["Name"]);
ctMap.RootElement = XmlHelper.ReadString(node.Attributes["RootElement"]);
ctMap.SchemaID = XmlHelper.ReadString(node.Attributes["SchemaID"]);
ctMap.ShowImportExportValidationErrors = XmlHelper.ReadBool(node.Attributes["ShowImportExportValidationErrors"]);
ctMap.PreserveFormat = XmlHelper.ReadBool(node.Attributes["PreserveFormat"]);
ctMap.PreserveSortAFLayout = XmlHelper.ReadBool(node.Attributes["PreserveSortAFLayout"]);
ctMap.Append = XmlHelper.ReadBool(node.Attributes["Append"]);
ctMap.AutoFit = XmlHelper.ReadBool(node.Attributes["AutoFit"]);
foreach(XmlElement ele in node)
{
if(ele.LocalName == "DataBinding")
{
ctMap.DataBinding = CT_DataBinding.Parse(ele, namespaceManager);
}
}
return ctMap;
}
internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<{0}", nodeName));
XmlHelper.WriteAttribute(sw, "ID", this.ID);
XmlHelper.WriteAttribute(sw, "Name", this.Name);
XmlHelper.WriteAttribute(sw, "RootElement", this.RootElement);
XmlHelper.WriteAttribute(sw, "SchemaID", this.SchemaID);
XmlHelper.WriteAttribute(sw, "ShowImportExportValidationErrors", this.ShowImportExportValidationErrors);
XmlHelper.WriteAttribute(sw, "PreserveFormat", this.PreserveFormat);
XmlHelper.WriteAttribute(sw, "PreserveSortAFLayout", this.PreserveSortAFLayout);
XmlHelper.WriteAttribute(sw, "Append", this.Append);
XmlHelper.WriteAttribute(sw, "AutoFit", this.AutoFit);

if(dataBindingField != null)
{
sw.Write(">");
dataBindingField.Write(sw, "DataBinding");
sw.Write(string.Format("</{0}>", nodeName));
}
else
sw.Write("/>");
}
[XmlElement]
public CT_DataBinding DataBinding
{
Expand Down Expand Up @@ -343,7 +462,33 @@ public partial class CT_DataBinding

private uint dataBindingLoadModeField = 0; // 1..1 - default value not defined in xsd

public static CT_DataBinding Parse(XmlNode ele, XmlNamespaceManager namespaceManager)
{
CT_DataBinding ctObj = new CT_DataBinding();
ctObj.Any = ele.FirstChild as XmlElement;
ctObj.connectionIDField = ele.Attributes["ConnectionID"] ==null ? null : XmlHelper.ReadUInt(ele.Attributes["ConnectionID"]);
ctObj.DataBindingName = XmlHelper.ReadString(ele.Attributes["DataBindingName"]);
ctObj.FileBindingName = XmlHelper.ReadString(ele.Attributes["FileBindingName"]);
ctObj.DataBindingLoadMode = XmlHelper.ReadUInt(ele.Attributes["DataBindingLoadMode"]);
ctObj.fileBindingField = ele.Attributes["FileBinding"] ==null ? null : XmlHelper.ReadBool(ele.Attributes["FileBinding"]);
return ctObj;
}

internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<{0}", nodeName));
if(this.FileBindingSpecified)
XmlHelper.WriteAttribute(sw, "FileBinding", FileBinding);
if(this.ConnectionIDSpecified)
XmlHelper.WriteAttribute(sw, "ConnectionID", ConnectionID);
XmlHelper.WriteAttribute(sw, "DataBindingLoadMode", DataBindingLoadMode);
XmlHelper.WriteAttribute(sw, "DataBindingName", DataBindingName);
XmlHelper.WriteAttribute(sw, "FileBindingName", FileBindingName);
sw.Write(">");
if(anyField != null)
sw.Write(anyField.OuterXml);
sw.Write(string.Format("</{0}>", nodeName));
}
[XmlAnyElement]
public System.Xml.XmlElement Any
{
Expand Down
83 changes: 9 additions & 74 deletions OpenXmlFormats/Spreadsheet/Document/MapInfoDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,105 +7,40 @@ namespace NPOI.OpenXmlFormats.Spreadsheet
{
public class MapInfoDocument
{
CT_MapInfo map = null;
CT_MapInfo mapInfo = null;

public MapInfoDocument()
{
}
public MapInfoDocument(CT_MapInfo map)
{
this.map = map;
this.mapInfo = map;
}
public CT_MapInfo GetMapInfo()
{
return this.map;
return this.mapInfo;
}
public void SetMapInfo(CT_MapInfo map)
{
this.map = map;
this.mapInfo = map;
}
public void SetComments(CT_MapInfo map)
{
this.map = map;
this.mapInfo = map;
}
public string SelectionNamespaces { get; set; }
public void Save(Stream stream)
{
using (StreamWriter sw = new StreamWriter(stream))
{
sw.Write("<MapInfo xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" SelectionNamespaces=\"xmlns:ns1='http://schemas.openxmlformats.org/spreadsheetml/2006/main'\">");
if (this.map.Schema != null)
{
foreach (CT_Schema ctSchema in this.map.Schema)
{
sw.Write(string.Format("<Schema ID=\"{0}\"", ctSchema.ID));
if (ctSchema.Namespace != null)
sw.Write(string.Format(" Namespace=\"{0}\"", ctSchema.Namespace));
if (ctSchema.SchemaRef != null)
sw.Write(string.Format(" SchemaRef=\"{0}\"", ctSchema.SchemaRef));
sw.Write(">");
sw.Write(ctSchema.InnerXml);
sw.Write("</Schema>");
}
}
if (this.map.Map != null)
{
foreach (CT_Map ctMap in this.map.Map)
{
sw.Write(string.Format("<Map ID=\"{0}\"", ctMap.ID));
if (ctMap.SchemaID != null)
sw.Write(string.Format(" SchemaID=\"{0}\"", ctMap.SchemaID));
if (ctMap.RootElement != null)
sw.Write(string.Format(" RootElement=\"{0}\"", ctMap.RootElement));
if (ctMap.Name != null)
sw.Write(string.Format(" Name=\"{0}\"", ctMap.Name));
if (ctMap.PreserveFormat)
sw.Write(" PreserveFormat=\"true\"");
if (ctMap.PreserveSortAFLayout)
sw.Write(" PreserveSortAFLayout=\"true\"");
if (ctMap.ShowImportExportValidationErrors)
sw.Write(" ShowImportExportValidationErrors=\"true\"");
if (ctMap.Append)
sw.Write(" Append=\"true\"");
if (ctMap.AutoFit)
sw.Write(" AutoFit=\"true\"");
sw.Write(" />");
}
}
sw.Write("</MapInfo");
mapInfo.Write(sw, "MapInfo");
}
}

public static MapInfoDocument Parse(System.Xml.XmlDocument xmldoc, System.Xml.XmlNamespaceManager NameSpaceManager)
public static MapInfoDocument Parse(XmlDocument xmlDoc, XmlNamespaceManager nameSpaceManager)
{
MapInfoDocument doc = new MapInfoDocument();
doc.map = new CT_MapInfo();
doc.map.Map = new System.Collections.Generic.List<CT_Map>();
foreach (XmlElement mapNode in xmldoc.SelectNodes("d:MapInfo/d:Map", NameSpaceManager))
{
CT_Map ctMap=new CT_Map();
ctMap.ID = XmlHelper.ReadUInt(mapNode.GetAttributeNode("ID"));
ctMap.Name = XmlHelper.ReadString(mapNode.GetAttributeNode("Name"));
ctMap.RootElement = XmlHelper.ReadString(mapNode.GetAttributeNode("RootElement"));
ctMap.SchemaID = XmlHelper.ReadString(mapNode.GetAttributeNode("SchemaID"));
ctMap.ShowImportExportValidationErrors = XmlHelper.ReadBool(mapNode.GetAttributeNode("ShowImportExportValidationErrors"));
ctMap.PreserveFormat = XmlHelper.ReadBool(mapNode.GetAttributeNode("PreserveFormat"));
ctMap.PreserveSortAFLayout = XmlHelper.ReadBool(mapNode.GetAttributeNode("PreserveSortAFLayout"));
ctMap.Append = XmlHelper.ReadBool(mapNode.GetAttributeNode("Append"));
ctMap.AutoFit = XmlHelper.ReadBool(mapNode.GetAttributeNode("AutoFit"));
doc.map.Map.Add(ctMap);
}
doc.map.Schema = new System.Collections.Generic.List<CT_Schema>();
foreach (XmlNode schemaNode in xmldoc.SelectNodes("d:MapInfo/d:Schema", NameSpaceManager))
{
CT_Schema ctSchema = new CT_Schema();
ctSchema.ID = schemaNode.Attributes["ID"].Value;
if (schemaNode.Attributes["Namespace"] != null)
ctSchema.Namespace = schemaNode.Attributes["Namespace"].Value;
if (schemaNode.Attributes["SchemaRef"] != null)
ctSchema.SchemaRef = schemaNode.Attributes["SchemaRef"].Value;
ctSchema.InnerXml = schemaNode.InnerXml;
doc.map.Schema.Add(ctSchema);
}
doc.mapInfo = CT_MapInfo.Parse(xmlDoc.DocumentElement, nameSpaceManager);
return doc;
}
}
Expand Down
29 changes: 29 additions & 0 deletions OpenXmlFormats/Spreadsheet/Sheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7133,6 +7133,8 @@ public static CT_DataValidations Parse(XmlNode node, XmlNamespaceManager namespa

internal void Write(StreamWriter sw, string nodeName)
{
if (this.countField == 0)
return;
sw.Write(string.Format("<{0}", nodeName));
XmlHelper.WriteAttribute(sw, "disablePrompts", this.disablePrompts);
XmlHelper.WriteAttribute(sw, "xWindow", this.xWindow);
Expand Down Expand Up @@ -7387,6 +7389,33 @@ public void Set(CT_DataValidation obj)
promptField = obj.promptField;
sqrefField = obj.sqrefField;
}

public override bool Equals(object obj)
{
CT_DataValidation o = (CT_DataValidation)obj;

if (o is null)
{
return false;
}

return formula1Field == o.formula1Field
&& formula2Field == o.formula2Field
&& typeField == o.typeField
&& errorStyleField == o.errorStyleField
&& imeModeField == o.imeModeField
&& operatorField == o.operatorField
&& allowBlankField == o.allowBlankField
&& showDropDownField == o.showDropDownField
&& showInputMessageField == o.showInputMessageField
&& showErrorMessageField == o.showErrorMessageField
&& errorTitleField == o.errorTitleField
&& errorField == o.errorField
&& promptTitleField == o.promptTitleField
&& promptField == o.promptField
&& sqrefField == o.sqrefField;
}

[XmlElement(Order = 0)]
public string formula1
{
Expand Down
Loading

0 comments on commit e82fa27

Please sign in to comment.