示例#1
0
 private void UpdateColorNode(XmlNode node, Color color)
 {
     if (!color.IsEmpty)
     {
         ExcelSparklineGroup.SetAttribute(node, "rgb", ExcelSparklineGroup.XmlColor(color));
     }
     else if (node.Attributes.Count == 0)
     {
         this.TopNode.RemoveChild(node);
     }
     // Else: the node has an unsupported color definition (such as a theme) and should be left alone.
 }
示例#2
0
 /// <summary>
 /// Create a new <see cref="ExcelSparkline"/> from scratch (without using an existing XML Node).
 /// </summary>
 /// <param name="hostCell">The <see cref="ExcelAddress"/> that hosts the sparkline.</param>
 /// <param name="formula">The <see cref="ExcelAddress"/> that the sparkline references. Can be null.</param>
 /// <param name="group">The <see cref="ExcelSparklineGroup"/> that this line will belong to.</param>
 /// <param name="nameSpaceManager">The namespace manager for the object.</param>
 public ExcelSparkline(ExcelAddress hostCell, ExcelAddress formula, ExcelSparklineGroup group, XmlNamespaceManager nameSpaceManager) : base(nameSpaceManager)
 {
     if (hostCell == null)
     {
         throw new ArgumentNullException(nameof(hostCell));
     }
     if (group == null)
     {
         throw new ArgumentNullException(nameof(group));
     }
     this.HostCell = hostCell;
     this.Group    = group;
     this.Formula  = formula;
     this.TopNode  = group.TopNode.OwnerDocument.CreateElement("x14:sparkline", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
 }
示例#3
0
        /// <summary>
        /// Create a new <see cref="ExcelSparkline"/> from an existing XML Node.
        /// </summary>
        /// <param name="group">The <see cref="ExcelSparklineGroup"/> this line will belong to.</param>
        /// <param name="nameSpaceManager">The Namespace Manager for the object.</param>
        /// <param name="topNode">The x14:Sparkline node containing information about the sparkline.</param>
        public ExcelSparkline(ExcelSparklineGroup group, XmlNamespaceManager nameSpaceManager, XmlNode topNode) : base(nameSpaceManager, topNode)
        {
            if (topNode == null)
            {
                throw new ArgumentNullException(nameof(topNode));
            }
            if (group == null)
            {
                throw new ArgumentNullException(nameof(group));
            }
            this.Group = group;
            var formulaNode = topNode.SelectSingleNode("xm:f", nameSpaceManager);
            var hostNode    = topNode.SelectSingleNode("xm:sqref", nameSpaceManager);

            this.Formula  = formulaNode != null ? new ExcelAddress(formulaNode.InnerText) : null;
            this.HostCell = group.Worksheet.Cells[hostNode.InnerText];
        }
示例#4
0
 private void SaveAttributes()
 {
     if (this.ManualMax != null)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "manualMax", this.ManualMax.ToString());
     }
     else
     {
         this.ClearAttribute(this.TopNode, "manualMax");
     }
     if (this.ManualMin != null)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "manualMin", this.ManualMin.ToString());
     }
     else
     {
         this.ClearAttribute(this.TopNode, "manualMin");
     }
     if (this.LineWeight != null && this.LineWeight != 0.75)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "lineWeight", this.LineWeight.ToString());
     }
     else
     {
         this.ClearAttribute(this.TopNode, "lineWeight");
     }
     if (this.Type != null && this.Type != SparklineType.Line)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "type", ExcelSparklineGroup.SparklineTypeToString(this.Type.Value));
     }
     else
     {
         this.ClearAttribute(this.TopNode, "type");
     }
     if (this.DateAxis)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "dateAxis", "1");
     }
     else
     {
         this.ClearAttribute(this.TopNode, "dateAxis");
     }
     if (this.DisplayEmptyCellsAs != null && this.DisplayEmptyCellsAs != DispBlanksAs.Zero)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "displayEmptyCellsAs", ExcelSparklineGroup.DisplayBlanksAsToString(this.DisplayEmptyCellsAs.Value));
     }
     else
     {
         this.ClearAttribute(this.TopNode, "displayEmptyCellsAs");
     }
     if (this.Markers)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "markers", "1");
     }
     else
     {
         this.ClearAttribute(this.TopNode, "markers");
     }
     if (this.High)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "high", "1");
     }
     else
     {
         this.ClearAttribute(this.TopNode, "high");
     }
     if (this.Low)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "low", "1");
     }
     else
     {
         this.ClearAttribute(this.TopNode, "low");
     }
     if (this.First)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "first", "1");
     }
     else
     {
         this.ClearAttribute(this.TopNode, "first");
     }
     if (this.Last)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "last", "1");
     }
     else
     {
         this.ClearAttribute(this.TopNode, "last");
     }
     if (this.Negative)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "negative", "1");
     }
     else
     {
         this.ClearAttribute(this.TopNode, "negative");
     }
     if (this.DisplayXAxis)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "displayXAxis", "1");
     }
     else
     {
         this.ClearAttribute(this.TopNode, "displayXAxis");
     }
     if (this.DisplayHidden)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "displayHidden", "1");
     }
     else
     {
         this.ClearAttribute(this.TopNode, "displayHidden");
     }
     if (this.MinAxisType != SparklineAxisMinMax.Individual)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "minAxisType", ExcelSparklineGroup.SparklineAxisMinMaxToString(this.MinAxisType));
     }
     else
     {
         this.ClearAttribute(this.TopNode, "minAxisType");
     }
     if (this.MaxAxisType != SparklineAxisMinMax.Individual)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "maxAxisType", ExcelSparklineGroup.SparklineAxisMinMaxToString(this.MaxAxisType));
     }
     else
     {
         this.ClearAttribute(this.TopNode, "maxAxisType");
     }
     if (this.RightToLeft)
     {
         ExcelSparklineGroup.SetAttribute(this.TopNode, "rightToLeft", "1");
     }
     else
     {
         this.ClearAttribute(this.TopNode, "rightToLeft");
     }
 }