/// <summary> /// Adds a <b>glow</b> node to the nodes of type <b>effectLst</b> specified. Not supported in <b>EPPlus</b> library. /// </summary> /// <param name="effectLstNode"><b>outerShdw</b> node (glow).</param> /// <param name="illumination">Illumination from model.</param> /// <param name="documentHelper">Target xml document helper.</param> /// <remarks> /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_scrgbClr-1.html">http://www.schemacentral.com/sc/ooxml/e-a_scrgbClr-1.html</a> /// </remarks> private static void AddGlowNode(this XmlNode effectLstNode, XlsxIlluminationShapeEffect illumination, IXmlHelper documentHelper) { var radAttr = documentHelper.CreateAttribute("rad"); radAttr.Value = $"{illumination.Size * OfficeOpenXmlHelper.EMU_PER_POINT}"; var glowNode = documentHelper.CreateOrDefaultAndAppendElementToNode(effectLstNode, "a", "glow"); glowNode.Attributes?.Append(radAttr); var clrValAttr = documentHelper.CreateAttribute("val"); clrValAttr.Value = ColorHelper.ToHex(illumination.GetColor()).Replace("#", string.Empty); var rgbColorModelPercentageVariantNode = documentHelper.CreateOrDefaultAndAppendElementToNode(glowNode, "a", "srgbClr"); rgbColorModelPercentageVariantNode.Attributes?.Append(clrValAttr); var alphaValueAttr = documentHelper.CreateAttribute("val"); alphaValueAttr.Value = $"{(100 - illumination.Transparency) * OfficeOpenXmlHelper.ST_PERCENTAGE}"; var alphaNode = documentHelper.CreateOrDefaultAndAppendElementToNode(rgbColorModelPercentageVariantNode, "a", "alpha"); alphaNode.Attributes?.Append(alphaValueAttr); }
/// <summary> /// Adds a <b>innerShdw</b> node (Inner Shadow) to the node of type <b>effectLst</b> (Effect Container) specified. Not supported in <b>EPPlus</b> library. /// </summary> /// <param name="effectContainerNode"><b>effectLst</b> node (Effect Container).</param> /// <param name="shadow">Shadow from model.</param> /// <param name="documentHelper">Target xml document helper.</param> /// <remarks> /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_outerShdw-2.html">http://www.schemacentral.com/sc/ooxml/e-a_outerShdw-2.html</a> /// </remarks> private static void AddInnerShadowNode(this XmlNode effectContainerNode, XlsxBaseShadow shadow, IXmlHelper documentHelper) { var blurRadAttr = documentHelper.CreateAttribute("blurRad"); blurRadAttr.Value = $"{shadow.Blur * OfficeOpenXmlHelper.EMU_PER_POINT}"; var distAttr = documentHelper.CreateAttribute("dist"); distAttr.Value = $"{shadow.Offset * OfficeOpenXmlHelper.EMU_PER_POINT}"; var dirAttr = documentHelper.CreateAttribute("dir"); dirAttr.Value = $"{shadow.Angle * OfficeOpenXmlHelper.ST_POSITIVE_FIXED_ANGLE}"; var rotWithShapeAttr = documentHelper.CreateAttribute("rotWithShape"); rotWithShapeAttr.Value = "0"; var outerShadowNode = documentHelper.CreateOrDefaultAndAppendElementToNode(effectContainerNode, "a", "innerShdw"); if (outerShadowNode.Attributes == null) { return; } outerShadowNode.Attributes.Append(blurRadAttr); outerShadowNode.Attributes.Append(distAttr); outerShadowNode.Attributes.Append(dirAttr); outerShadowNode.Attributes.Append(rotWithShapeAttr); outerShadowNode.AddRgbColorModelPercentageVariantNode(shadow, documentHelper); }
/// <summary> /// Adds a <c>defRPr</c> node (Default Text Run Properties) to the node of type <c>pPr</c> (Text Paragraph Properties) specified. Not supported in <c>EPPlus</c> library. /// </summary> /// <param name="node"><c>pPr</c> node (Text Paragraph Properties).</param> /// <param name="model">Font from model.</param> /// <param name="documentHelper">Target xml document helper.</param> /// <remarks> /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_defRPr-1.html">http://www.schemacentral.com/sc/ooxml/e-a_defRPr-1.html</a> /// </remarks> private static void AddDefaultTextRunPropertiesNode(this XmlNode node, FontModel model, IXmlHelper documentHelper) { var sizeAttr = documentHelper.CreateAttribute("sz"); sizeAttr.Value = (model.Size * 100).ToString(CultureInfo.InvariantCulture); var boldAttr = documentHelper.CreateAttribute("b"); boldAttr.Value = model.Bold == YesNo.Yes ? "1" : "0"; var italicAttr = documentHelper.CreateAttribute("i"); italicAttr.Value = model.Italic == YesNo.Yes ? "1" : "0"; var underlineAttr = documentHelper.CreateAttribute("u"); underlineAttr.Value = model.Underline == YesNo.Yes ? "sng" : "none"; var defaultTextRunPropertiesNode = documentHelper.CreateOrDefaultAndAppendElementToNode(node, "a", "defRPr"); defaultTextRunPropertiesNode.Attributes.Append(boldAttr); defaultTextRunPropertiesNode.Attributes.Append(sizeAttr); defaultTextRunPropertiesNode.Attributes.Append(italicAttr); defaultTextRunPropertiesNode.Attributes.Append(underlineAttr); defaultTextRunPropertiesNode.AddSolidFillNode(model.GetColor(), documentHelper); defaultTextRunPropertiesNode.AddLatinFontNode(model.Name, documentHelper); defaultTextRunPropertiesNode.AddEastAsianFontNode(model.Name, documentHelper); defaultTextRunPropertiesNode.AddComplexScriptFontNode(model.Name, documentHelper); }
/// <summary> /// Adds a <b>reflection</b> node to the nodes of type <b>effectLst</b> specified. Not supported in <b>EPPlus</b> library. /// </summary> /// <param name="effectLstNode"><b>outerShdw</b> node (glow).</param> /// <param name="reflection">Reflection from model.</param> /// <param name="documentHelper">Target xml document helper.</param> /// <remarks> /// For more information please see <a href="http://officeopenxml.com/drwSp-effects.phpl">http://officeopenxml.com/drwSp-effects.php</a> /// </remarks> private static void AddReflectionNode(this XmlNode effectLstNode, XlsxReflectionShapeEffect reflection, IXmlHelper documentHelper) { var blurRadAttr = documentHelper.CreateAttribute("blurRad"); blurRadAttr.Value = $"{reflection.Blur * OfficeOpenXmlHelper.EMU_PER_POINT}"; var staAttr = documentHelper.CreateAttribute("stA"); staAttr.Value = $"{reflection.Transparency * OfficeOpenXmlHelper.ST_PERCENTAGE}"; var endaAttr = documentHelper.CreateAttribute("endA"); endaAttr.Value = $"{0.3 * OfficeOpenXmlHelper.ST_PERCENTAGE}"; var endPosAttr = documentHelper.CreateAttribute("endPos"); endPosAttr.Value = $"{reflection.Size * OfficeOpenXmlHelper.ST_PERCENTAGE}"; var distAttr = documentHelper.CreateAttribute("dist"); distAttr.Value = $"{reflection.Offset * OfficeOpenXmlHelper.ST_PERCENTAGE}"; var dirAttr = documentHelper.CreateAttribute("dir"); dirAttr.Value = $"{90 * OfficeOpenXmlHelper.ST_POSITIVE_FIXED_ANGLE}"; var syAttr = documentHelper.CreateAttribute("sy"); syAttr.Value = $"{-100 * OfficeOpenXmlHelper.ST_PERCENTAGE}"; var algnAttr = documentHelper.CreateAttribute("algn"); algnAttr.Value = "bl"; var rotWithShapeAttr = documentHelper.CreateAttribute("rotWithShape"); rotWithShapeAttr.Value = "0"; var reflectionNode = documentHelper.CreateOrDefaultAndAppendElementToNode(effectLstNode, "a", "reflection"); reflectionNode.Attributes?.Append(blurRadAttr); reflectionNode.Attributes?.Append(staAttr); reflectionNode.Attributes?.Append(endaAttr); reflectionNode.Attributes?.Append(endPosAttr); if (reflection.Offset != 0.0f) { reflectionNode.Attributes?.Append(distAttr); } reflectionNode.Attributes?.Append(dirAttr); reflectionNode.Attributes?.Append(syAttr); reflectionNode.Attributes?.Append(algnAttr); reflectionNode.Attributes?.Append(rotWithShapeAttr); }
/// <summary> /// Adds a <c>bodyPr</c> node (Body Properties) to the node of type <c>txPr</c> (Text properties) specified. Not supported in <c>EPPlus</c> library. /// </summary> /// <param name="textPropertiesNode"><c>txPr</c> node (Text properties).</param> /// <param name="orientation">A <see cref="KnownLabelOrientation" /> value from model.</param> /// <param name="documentHelper">Target xml document helper.</param> /// <remarks> /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_bodyPr-2.html">http://www.schemacentral.com/sc/ooxml/e-a_bodyPr-2.html</a> /// </remarks> private static void AddBodyPropertiesNode(this XmlNode textPropertiesNode, LabelOrientation orientation, IXmlHelper documentHelper) { var rotAttr = documentHelper.CreateAttribute("rot"); rotAttr.Value = orientation.ToAngle().ToString(CultureInfo.InvariantCulture); var vertAttr = documentHelper.CreateAttribute("vert"); vertAttr.Value = orientation == LabelOrientation.Vertical ? "wordArtVert" : "horz"; var bodyPropertiesNode = documentHelper.CreateOrDefaultAndAppendElementToNode(textPropertiesNode, "a", "bodyPr"); bodyPropertiesNode.Attributes.Append(rotAttr); bodyPropertiesNode.Attributes.Append(vertAttr); }
/// <summary> /// Adds the label alignment to the specified axis. Not supported in <b>EPPlus</b> library. /// </summary> /// <param name="axis"><b>Xml</b> node than represent an axis definition.</param> /// <param name="model">A <see cref="KnownHorizontalAlignment"/> value from model.</param> /// <param name="documentHelper">Target xml document helper.</param> /// <exception cref="ArgumentNullException">If <paramref name="axis"/> is <b>null</b>.</exception> /// <exception cref="InvalidEnumArgumentException">The value specified is outside the range of valid values.</exception> /// <exception cref="InvalidOperationException">If <paramref name="axis"/> is not an axis.</exception> public static void AddAxisLabelAlignment(this XmlNode axis, KnownHorizontalAlignment model, IXmlHelper documentHelper) { SentinelHelper.ArgumentNull(axis, nameof(axis)); SentinelHelper.IsEnumValid(model); SentinelHelper.IsFalse(axis.Name.Contains("catAx") || axis.Name.Contains("valAx") || axis.Name.Contains("dateAx"), "Imposible extraer tipo. el nodo no es de tipo eje"); var axisType = axis.ExtractAxisType(documentHelper); switch (axisType) { case KnownAxisType.PrimaryCategoryAxis: case KnownAxisType.SecondaryCategoryAxis: var valAttr = documentHelper.CreateAttribute("val"); valAttr.Value = model.ToEppLabelAlignmentString(); var lblAlignXmlNode = documentHelper.CreateOrDefaultAndAppendElementToNode(axis, "c:lblAlgn"); lblAlignXmlNode.Attributes.Append(valAttr); break; case KnownAxisType.PrimaryValueAxis: case KnownAxisType.SecondaryValueAxis: break; } }
/// <summary> /// Adds a <b>scrgbClr</b> node (Rgb Color Model Percentage Variant) to the nodes of type <b>outerShdw</b> (Outer Shadow), <b>innerShdw</b> (Inner Shadow), specified. Not supported in <b>EPPlus</b> library. /// </summary> /// <param name="outerShadowNode"><b>outerShdw</b> node (Outer Shadow).</param> /// <param name="shadow">Shadow from model.</param> /// <param name="documentHelper">Target xml document helper.</param> /// <remarks> /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_scrgbClr-1.html">http://www.schemacentral.com/sc/ooxml/e-a_scrgbClr-1.html</a> /// </remarks> private static void AddRgbColorModelPercentageVariantNode(this XmlNode outerShadowNode, XlsxBaseShadow shadow, IXmlHelper documentHelper) { var valueAttr = documentHelper.CreateAttribute("val"); valueAttr.Value = ColorHelper.ToHex(shadow.GetColor()).Replace("#", string.Empty); var rgbColorModelPercentageVariantNode = documentHelper.CreateOrDefaultAndAppendElementToNode(outerShadowNode, "a", "srgbClr"); rgbColorModelPercentageVariantNode.Attributes?.Append(valueAttr); var alphaValueAttr = documentHelper.CreateAttribute("val"); alphaValueAttr.Value = $"{(100 - shadow.Transparency) * OfficeOpenXmlHelper.ST_PERCENTAGE}"; var alphaNode = documentHelper.CreateOrDefaultAndAppendElementToNode(rgbColorModelPercentageVariantNode, "a", "alpha"); alphaNode.Attributes?.Append(alphaValueAttr); }
/// <summary> /// Adds a <c>endParaRPr</c> node (End Paragraph Run Properties) to the node of type <c>p</c> (Text Paragraphs) specified. Not supported in <c>EPPlus</c> library. /// </summary> /// <param name="textParagraphsNode"><c>p</c> node (Text Paragraphs).</param> /// <param name="documentHelper">Target xml document helper.</param> /// <remarks> /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_endParaRPr-1.html">http://www.schemacentral.com/sc/ooxml/e-a_endParaRPr-1.html</a> /// </remarks> private static void AddEndParagraphRunPropertiesNode(this XmlNode textParagraphsNode, IXmlHelper documentHelper) { var langAttr = documentHelper.CreateAttribute("lang"); langAttr.Value = CultureInfo.CurrentCulture.Name; var endParagraphRunPropertiesNode = documentHelper.CreateOrDefaultAndAppendElementToNode(textParagraphsNode, "a", "endParaRPr"); endParagraphRunPropertiesNode.Attributes.Append(langAttr); }
/// <summary> /// Adds a <b>softEdge</b> node to the nodes of type <b>effectLst</b> specified. Not supported in <b>EPPlus</b> library. /// </summary> /// <param name="effectLstNode"><b>outerShdw</b> node (glow).</param> /// <param name="softEdge">Soft edge from model.</param> /// <param name="documentHelper">Target xml document helper.</param> /// <remarks> /// For more information please see <a href="http://officeopenxml.com/drwSp-effects.php">http://officeopenxml.com/drwSp-effects.php</a> /// </remarks> private static void AddSoftEdgeNode(this XmlNode effectLstNode, XlsxSoftEdgeShapeEffect softEdge, IXmlHelper documentHelper) { var radAttr = documentHelper.CreateAttribute("rad"); radAttr.Value = $"{softEdge.Size * OfficeOpenXmlHelper.EMU_PER_POINT}"; var reflectionNode = documentHelper.CreateOrDefaultAndAppendElementToNode(effectLstNode, "a", "softEdge"); reflectionNode.Attributes?.Append(radAttr); }
/// <summary> /// Adds a <c>ea</c> node (East Asian Font) to the node of type <c>defRPr</c> (Default Text Run Properties) specified. Not supported in <c>EPPlus</c> library. /// </summary> /// <param name="node"><c>defRPr</c> node (Shape Properties).</param> /// <param name="fontname">Font name.</param> /// <param name="documentHelper">Target xml document helper.</param> /// <remarks> /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_ea-1.html">http://www.schemacentral.com/sc/ooxml/e-a_ea-1.html</a> /// </remarks> private static void AddEastAsianFontNode(this XmlNode node, string fontname, IXmlHelper documentHelper) { var typefaceAttr = documentHelper.CreateAttribute("typeface"); typefaceAttr.Value = fontname; var eastAsianFontNode = documentHelper.CreateOrDefaultAndAppendElementToNode(node, "a", "ea"); eastAsianFontNode.Attributes.Append(typefaceAttr); }
/// <summary> /// Adds a <c>cs</c> node (Complex Script Font) to the node of type <c>defRPr</c> (Default Text Run Properties) specified. Not supported in <c>EPPlus</c> library. /// </summary> /// <param name="node"><c>defRPr</c> node (Shape Properties).</param> /// <param name="fontname">Font name.</param> /// <param name="documentHelper">Target xml document helper.</param> /// <remarks> /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_cs-1.html">http://www.schemacentral.com/sc/ooxml/e-a_cs-1.html</a> /// </remarks> private static void AddComplexScriptFontNode(this XmlNode node, string fontname, IXmlHelper documentHelper) { var typefaceAttr = documentHelper.CreateAttribute("typeface"); typefaceAttr.Value = fontname; var complexScriptFontNode = documentHelper.CreateOrDefaultAndAppendElementToNode(node, "a", "cs"); complexScriptFontNode.Attributes.Append(typefaceAttr); }
/// <summary> /// Adds a <c>solidFill</c> node (Solid Fill Properties) to the node of type <c>spPr</c> (Shape properties) specified. Not supported in <c>EPPlus</c> library. /// </summary> /// <param name="shapePropertiesNode"><c>spPr</c> node (Shape Properties).</param> /// <param name="color">Fill color.</param> /// <param name="documentHelper">Target xml document helper.</param> /// <remarks> /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_solidFill-1.html">http://www.schemacentral.com/sc/ooxml/e-a_solidFill-1.html</a> /// </remarks> public static void AddSolidFillNode(this XmlNode shapePropertiesNode, Color color, IXmlHelper documentHelper) { var solidFillNode = documentHelper.CreateOrDefaultAndAppendElementToNode(shapePropertiesNode, "a", "solidFill"); var valAttr = documentHelper.CreateAttribute("val"); valAttr.Value = ColorHelper.ToHex(color).Replace("#", string.Empty); var srgbClrNode = documentHelper.CreateOrDefaultAndAppendElementToNode(solidFillNode, "a", "srgbClr"); srgbClrNode.Attributes.Append(valAttr); }
/// <summary> /// Modifies crosses for the specified axis. Supported in <c>EPPlus</c> library but fails. /// </summary> /// <param name="axis"><c>Xml</c> node than represent an axis definition.</param> /// <param name="documentHelper">Target xml document helper.</param> /// <exception cref="T:System.ArgumentNullException">If <paramref name="axis" /> is <c>null</c>.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="axis" /> is not an axis.</exception> public static void ModifyAxisCrosses(this XmlNode axis, IXmlHelper documentHelper) { SentinelHelper.ArgumentNull(axis, nameof(axis)); SentinelHelper.IsFalse(axis.Name.Contains("catAx") || axis.Name.Contains("valAx") || axis.Name.Contains("dateAx"), "Imposible extraer tipo. el nodo no es de tipo eje"); var axisType = axis.ExtractAxisType(documentHelper); if (axisType != KnownAxisType.SecondaryCategoryAxis) { return; } var valAttr = documentHelper.CreateAttribute("val"); valAttr.Value = "max"; var crossesXmlNode = documentHelper.CreateOrDefaultAndAppendElementToNode(axis, "c:crosses"); crossesXmlNode.Attributes.Append(valAttr); }
/// <summary> /// Adds a <b>outerShdw</b> node (Outer Shadow) to the node of type <b>effectLst</b> (Effect Container) specified. Not supported in <b>EPPlus</b> library. /// </summary> /// <param name="effectContainerNode"><b>effectLst</b> node (Effect Container).</param> /// <param name="shadow">Shadow from model.</param> /// <param name="documentHelper">Target xml document helper.</param> /// <remarks> /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_outerShdw-2.html">http://www.schemacentral.com/sc/ooxml/e-a_outerShdw-2.html</a> /// </remarks> private static void AddPerspectiveShadowNode(this XmlNode effectContainerNode, XlsxPerspectiveShadow shadow, IXmlHelper documentHelper) { var blurRadAttr = documentHelper.CreateAttribute("blurRad"); blurRadAttr.Value = $"{shadow.Blur * OfficeOpenXmlHelper.EMU_PER_POINT}"; var distAttr = documentHelper.CreateAttribute("dist"); distAttr.Value = $"{shadow.Offset * OfficeOpenXmlHelper.EMU_PER_POINT}"; var dirAttr = documentHelper.CreateAttribute("dir"); dirAttr.Value = $"{shadow.Angle * OfficeOpenXmlHelper.ST_POSITIVE_FIXED_ANGLE}"; var sxAttr = documentHelper.CreateAttribute("sx"); var syAttr = documentHelper.CreateAttribute("sy"); var kxAttr = documentHelper.CreateAttribute("kx"); var algnAttr = documentHelper.CreateAttribute("algn"); switch (shadow.Angle) { case 225: sxAttr.Value = null; syAttr.Value = $"{23 * OfficeOpenXmlHelper.ST_PERCENTAGE}"; kxAttr.Value = $"{1200 * OfficeOpenXmlHelper.ST_PERCENTAGE}"; algnAttr.Value = "br"; break; case 315: sxAttr.Value = null; syAttr.Value = $"{23 * OfficeOpenXmlHelper.ST_PERCENTAGE}"; kxAttr.Value = $"{-1200 * OfficeOpenXmlHelper.ST_PERCENTAGE}"; algnAttr.Value = "bl"; break; case 135: sxAttr.Value = null; syAttr.Value = $"{-23 * OfficeOpenXmlHelper.ST_PERCENTAGE}"; kxAttr.Value = "800400"; algnAttr.Value = "br"; break; case 45: sxAttr.Value = null; syAttr.Value = $"{-23 * OfficeOpenXmlHelper.ST_PERCENTAGE}"; kxAttr.Value = "-800400"; algnAttr.Value = "bl"; break; case 90: sxAttr.Value = $"{90 * OfficeOpenXmlHelper.ST_PERCENTAGE}"; syAttr.Value = $"{-19 * OfficeOpenXmlHelper.ST_PERCENTAGE}"; kxAttr.Value = null; algnAttr.Value = null; break; } var rotWithShapeAttr = documentHelper.CreateAttribute("rotWithShape"); rotWithShapeAttr.Value = "0"; var outerShadowNode = documentHelper.CreateOrDefaultAndAppendElementToNode(effectContainerNode, "a", "outerShdw"); if (outerShadowNode.Attributes == null) { return; } outerShadowNode.Attributes.Append(blurRadAttr); outerShadowNode.Attributes.Append(distAttr); outerShadowNode.Attributes.Append(dirAttr); if (!string.IsNullOrEmpty(sxAttr.Value)) { outerShadowNode.Attributes.Append(sxAttr); } outerShadowNode.Attributes.Append(syAttr); if (!string.IsNullOrEmpty(kxAttr.Value)) { outerShadowNode.Attributes.Append(kxAttr); } if (!string.IsNullOrEmpty(algnAttr.Value)) { outerShadowNode.Attributes.Append(algnAttr); } outerShadowNode.Attributes.Append(rotWithShapeAttr); outerShadowNode.AddRgbColorModelPercentageVariantNode(shadow, documentHelper); }