public static ConditionalFormattingRule Convert(IXLConditionalFormat conditionalFormat, Int32 priority, XLWorkbook.SaveContext context) { return(Converters[conditionalFormat.ConditionalFormatType].Convert(conditionalFormat, priority, context)); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = new ConditionalFormattingRule { FormatId = (UInt32)context.DifferentialFormats[cf.Style], Type = cf.ConditionalFormatType.ToOpenXml(), Priority = priority }; var formula = new Formula { Text = "NOT(ISERROR(" + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + "))" }; conditionalFormattingRule.Append(formula); return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); if (!cf.Style.Equals(XLWorkbook.DefaultStyle)) { conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cf.Style]; } conditionalFormattingRule.TimePeriod = cf.TimePeriod.ToOpenXml(); var address = cf.Range.RangeAddress.FirstAddress.ToStringRelative(false); var formula = new Formula { Text = String.Format(formulaTemplates[cf.TimePeriod], address) }; conditionalFormattingRule.Append(formula); return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = new ConditionalFormattingRule { FormatId = (UInt32)context.DifferentialFormats[cf.Style], Type = cf.ConditionalFormatType.ToOpenXml(), Priority = priority }; return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { UInt32 val = UInt32.Parse(cf.Values[1].Value); var conditionalFormattingRule = new ConditionalFormattingRule { FormatId = (UInt32)context.DifferentialFormats[cf.Style], Percent = cf.Percent, Type = cf.ConditionalFormatType.ToOpenXml(), Priority = priority, Rank = val, Bottom = cf.Bottom }; return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { UInt32 val = UInt32.Parse(cf.Values[1].Value); var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cf.Style]; conditionalFormattingRule.Percent = cf.Percent; conditionalFormattingRule.Rank = val; conditionalFormattingRule.Bottom = cf.Bottom; return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { String val = cf.Values[1].Value; var conditionalFormattingRule = new ConditionalFormattingRule { FormatId = (UInt32)context.DifferentialFormats[cf.Style], Operator = ConditionalFormattingOperatorValues.EndsWith, Text = val, Type = cf.ConditionalFormatType.ToOpenXml(), Priority = priority }; var formula = new Formula { Text = "RIGHT(" + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + "," + val.Length.ToString() + ")=\"" + val + "\"" }; conditionalFormattingRule.Append(formula); return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { String val = GetQuoted(cf.Values[1]); var conditionalFormattingRule = new ConditionalFormattingRule { FormatId = (UInt32)context.DifferentialFormats[cf.Style], Operator = cf.Operator.ToOpenXml(), Type = cf.ConditionalFormatType.ToOpenXml(), Priority = priority }; var formula = new Formula(); if (cf.Operator == XLCFOperator.Equal || cf.Operator == XLCFOperator.NotEqual) { formula.Text = val; } else { formula.Text = val; } conditionalFormattingRule.Append(formula); if (cf.Operator == XLCFOperator.Between || cf.Operator == XLCFOperator.NotBetween) { var formula2 = new Formula { Text = GetQuoted(cf.Values[2]) }; conditionalFormattingRule.Append(formula2); } return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { UInt32 val = UInt32.Parse(cf.Values[1].Value); var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); var cfStyle = (cf.Style as XLStyle).Value; if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) { conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; } conditionalFormattingRule.Percent = cf.Percent; conditionalFormattingRule.Rank = val; conditionalFormattingRule.Bottom = cf.Bottom; return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, XLWorkbook.SaveContext context) { ConditionalFormattingRule conditionalFormattingRule = new ConditionalFormattingRule() { Type = DocumentFormat.OpenXml.Spreadsheet.ConditionalFormatValues.DataBar, Id = (cf as XLConditionalFormat).Id.WrapInBraces() }; DataBar dataBar = new DataBar() { MinLength = 0, MaxLength = 100, Gradient = true, ShowValue = !cf.ShowBarOnly }; var cfMinType = cf.ContentTypes.TryGetValue(1, out var contentType1) ? Convert(contentType1.ToOpenXml()) : ConditionalFormattingValueObjectTypeValues.AutoMin; var cfMin = new ConditionalFormattingValueObject { Type = cfMinType }; if (cf.Values.Any() && cf.Values[1]?.Value != null) { cfMin.Type = ConditionalFormattingValueObjectTypeValues.Numeric; cfMin.Append(new Formula() { Text = cf.Values[1].Value }); } var cfMaxType = cf.ContentTypes.TryGetValue(2, out var contentType2) ? Convert(contentType2.ToOpenXml()) : ConditionalFormattingValueObjectTypeValues.AutoMax; var cfMax = new ConditionalFormattingValueObject { Type = cfMaxType }; if (cf.Values.Count >= 2 && cf.Values[2]?.Value != null) { cfMax.Type = ConditionalFormattingValueObjectTypeValues.Numeric; cfMax.Append(new Formula() { Text = cf.Values[2].Value }); } var barAxisColor = new BarAxisColor { Rgb = XLColor.Black.Color.ToHex() }; var negativeFillColor = new NegativeFillColor { Rgb = cf.Colors[1].Color.ToHex() }; if (cf.Colors.Count == 2) { negativeFillColor = new NegativeFillColor { Rgb = cf.Colors[2].Color.ToHex() }; } dataBar.Append(cfMin); dataBar.Append(cfMax); dataBar.Append(negativeFillColor); dataBar.Append(barAxisColor); conditionalFormattingRule.Append(dataBar); return(conditionalFormattingRule); }
public static ConditionalFormattingRule Convert(IXLConditionalFormat conditionalFormat, Int32 priority, XLWorkbook.SaveContext context) { if (!Converters.TryGetValue(conditionalFormat.ConditionalFormatType, out var converter)) { throw new NotImplementedException(string.Format("Conditional formatting rule '{0}' hasn't been implemented", conditionalFormat.ConditionalFormatType)); } return(converter.Convert(conditionalFormat, priority, context)); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); var dataBar = new DataBar { ShowValue = !cf.ShowBarOnly }; var conditionalFormatValueObject1 = new ConditionalFormatValueObject { Type = cf.ContentTypes[1].ToOpenXml() }; if (cf.Values.Any() && cf.Values[1]?.Value != null) { conditionalFormatValueObject1.Val = cf.Values[1].Value; } var conditionalFormatValueObject2 = new ConditionalFormatValueObject { Type = cf.ContentTypes[2].ToOpenXml() }; if (cf.Values.Count >= 2 && cf.Values[2]?.Value != null) { conditionalFormatValueObject2.Val = cf.Values[2].Value; } var color = new Color(); switch (cf.Colors[1].ColorType) { case XLColorType.Color: color.Rgb = cf.Colors[1].Color.ToHex(); break; case XLColorType.Theme: color.Theme = System.Convert.ToUInt32(cf.Colors[1].ThemeColor); break; case XLColorType.Indexed: color.Indexed = System.Convert.ToUInt32(cf.Colors[1].Indexed); break; } dataBar.Append(conditionalFormatValueObject1); dataBar.Append(conditionalFormatValueObject2); dataBar.Append(color); conditionalFormattingRule.Append(dataBar); if (cf.Colors.Count > 1) { ConditionalFormattingRuleExtensionList conditionalFormattingRuleExtensionList = new ConditionalFormattingRuleExtensionList(); ConditionalFormattingRuleExtension conditionalFormattingRuleExtension = new ConditionalFormattingRuleExtension { Uri = "{B025F937-C7B1-47D3-B67F-A62EFF666E3E}" }; conditionalFormattingRuleExtension.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); DocumentFormat.OpenXml.Office2010.Excel.Id id = new DocumentFormat.OpenXml.Office2010.Excel.Id { Text = (cf as XLConditionalFormat).Id.WrapInBraces() }; conditionalFormattingRuleExtension.Append(id); conditionalFormattingRuleExtensionList.Append(conditionalFormattingRuleExtension); conditionalFormattingRule.Append(conditionalFormattingRuleExtensionList); } return(conditionalFormattingRule); }
public static ConditionalFormattingRule Convert(IXLConditionalFormat conditionalFormat, Int32 priority, XLWorkbook.SaveContext context) { var converter = Converters[conditionalFormat.ConditionalFormatType]; if (converter == null) { throw new NotImplementedException(string.Format("Conditional formatting rule '{0}' hasn't been implemented", conditionalFormat.ConditionalFormatType)); } return(converter.Convert(conditionalFormat, priority, context)); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); conditionalFormattingRule.FormatId = (uint)context.DifferentialFormats[cf.Style]; return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { String val = GetQuoted(cf.Values[1]); var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); var cfStyle = (cf.Style as XLStyle).Value; if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) { conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; } conditionalFormattingRule.Operator = cf.Operator.ToOpenXml(); var formula = new Formula(val); conditionalFormattingRule.Append(formula); if (cf.Operator == XLCFOperator.Between || cf.Operator == XLCFOperator.NotBetween) { var formula2 = new Formula { Text = GetQuoted(cf.Values[2]) }; conditionalFormattingRule.Append(formula2); } return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = new ConditionalFormattingRule { Type = cf.ConditionalFormatType.ToOpenXml(), Priority = priority }; var colorScale = new ColorScale(); for (Int32 i = 1; i <= cf.Values.Count; i++) { var conditionalFormatValueObject = new ConditionalFormatValueObject { Type = cf.ContentTypes[i].ToOpenXml(), Val = cf.Values[i].Value }; colorScale.Append(conditionalFormatValueObject); } for (Int32 i = 1; i <= cf.Values.Count; i++) { Color color = new Color { Rgb = cf.Colors[i].Color.ToHex() }; colorScale.Append(color); } conditionalFormattingRule.Append(colorScale); return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = new ConditionalFormattingRule { Type = cf.ConditionalFormatType.ToOpenXml(), Priority = priority }; var dataBar = new DataBar { ShowValue = !cf.ShowBarOnly }; var conditionalFormatValueObject1 = new ConditionalFormatValueObject { Type = cf.ContentTypes[1].ToOpenXml() }; if (cf.Values.Any() && cf.Values[1]?.Value != null) { conditionalFormatValueObject1.Val = cf.Values[1].Value; } var conditionalFormatValueObject2 = new ConditionalFormatValueObject { Type = cf.ContentTypes[2].ToOpenXml() }; if (cf.Values.Count >= 2 && cf.Values[2]?.Value != null) { conditionalFormatValueObject2.Val = cf.Values[2].Value; } var color = new Color(); switch (cf.Colors[1].ColorType) { case XLColorType.Color: color.Rgb = cf.Colors[1].Color.ToHex(); break; case XLColorType.Theme: color.Theme = System.Convert.ToUInt32(cf.Colors[1].ThemeColor); break; case XLColorType.Indexed: color.Indexed = System.Convert.ToUInt32(cf.Colors[1].Indexed); break; } dataBar.Append(conditionalFormatValueObject1); dataBar.Append(conditionalFormatValueObject2); dataBar.Append(color); conditionalFormattingRule.Append(dataBar); return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { String val = cf.Values[1].Value; var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); var cfStyle = (cf.Style as XLStyle).Value; if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) { conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle]; } conditionalFormattingRule.Operator = ConditionalFormattingOperatorValues.BeginsWith; conditionalFormattingRule.Text = val; var formula = new Formula { Text = "LEFT(" + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + "," + val.Length.ToString() + ")=\"" + val + "\"" }; conditionalFormattingRule.Append(formula); return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cf.Style]; var formula = new Formula { Text = "NOT(ISERROR(" + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + "))" }; conditionalFormattingRule.Append(formula); return(conditionalFormattingRule); }
public static ConditionalFormattingRule Convert(IXLConditionalFormat conditionalFormat, XLWorkbook.SaveContext context) { return(XLCFConvertersExtension.Converters[conditionalFormat.ConditionalFormatType].Convert(conditionalFormat, context)); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { String val = cf.Values[1].Value; var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); if (!cf.Style.Equals(XLWorkbook.DefaultStyle)) { conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cf.Style]; } conditionalFormattingRule.Operator = ConditionalFormattingOperatorValues.NotContains; conditionalFormattingRule.Text = val; var formula = new Formula { Text = "ISERROR(SEARCH(\"" + val + "\"," + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + "))" }; conditionalFormattingRule.Append(formula); return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = new ConditionalFormattingRule { Type = cf.ConditionalFormatType.ToOpenXml(), Priority = priority }; var dataBar = new DataBar { ShowValue = !cf.ShowBarOnly }; var conditionalFormatValueObject1 = new ConditionalFormatValueObject { Type = cf.ContentTypes[1].ToOpenXml() }; if (cf.Values.Count >= 1) { conditionalFormatValueObject1.Val = cf.Values[1].Value; } var conditionalFormatValueObject2 = new ConditionalFormatValueObject { Type = cf.ContentTypes[2].ToOpenXml() }; if (cf.Values.Count >= 2) { conditionalFormatValueObject2.Val = cf.Values[2].Value; } var color = new Color { Rgb = cf.Colors[1].Color.ToHex() }; dataBar.Append(conditionalFormatValueObject1); dataBar.Append(conditionalFormatValueObject2); dataBar.Append(color); conditionalFormattingRule.Append(dataBar); return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); if (!cf.Style.Equals(XLWorkbook.DefaultStyle)) { conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cf.Style]; } var formula = new Formula { Text = "LEN(TRIM(" + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + "))=0" }; conditionalFormattingRule.Append(formula); return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); var cfStyle = (cf.Style as XLStyle).Value; if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) { conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; } return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); var colorScale = new ColorScale(); for (Int32 i = 1; i <= cf.ContentTypes.Count; i++) { var type = cf.ContentTypes[i].ToOpenXml(); var val = cf.Values.TryGetValue(i, out XLFormula formula) ? formula?.Value : null; var conditionalFormatValueObject = new ConditionalFormatValueObject { Type = type }; if (val != null) { conditionalFormatValueObject.Val = val; } colorScale.Append(conditionalFormatValueObject); } for (Int32 i = 1; i <= cf.Colors.Count; i++) { var xlColor = cf.Colors[i]; var color = new Color(); switch (xlColor.ColorType) { case XLColorType.Color: color.Rgb = xlColor.Color.ToHex(); break; case XLColorType.Theme: color.Theme = System.Convert.ToUInt32(xlColor.ThemeColor); break; case XLColorType.Indexed: color.Indexed = System.Convert.ToUInt32(xlColor.Indexed); break; } colorScale.Append(color); } conditionalFormattingRule.Append(colorScale); return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = new ConditionalFormattingRule { Type = cf.ConditionalFormatType.ToOpenXml(), Priority = priority }; var colorScale = new ColorScale(); for (Int32 i = 1; i <= cf.ContentTypes.Count; i++) { var type = cf.ContentTypes[i].ToOpenXml(); var val = (cf.Values.ContainsKey(i) && cf.Values[i] != null) ? cf.Values[i].Value : null; var conditionalFormatValueObject = new ConditionalFormatValueObject { Type = type }; if (val != null) { conditionalFormatValueObject.Val = val; } colorScale.Append(conditionalFormatValueObject); } for (Int32 i = 1; i <= cf.Colors.Count; i++) { Color color = new Color { Rgb = cf.Colors[i].Color.ToHex() }; colorScale.Append(color); } conditionalFormattingRule.Append(colorScale); return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = new ConditionalFormattingRule { Type = cf.ConditionalFormatType.ToOpenXml(), Priority = priority }; var iconSet = new IconSet { ShowValue = !cf.ShowIconOnly, Reverse = cf.ReverseIconOrder, IconSetValue = cf.IconSetStyle.ToOpenXml() }; Int32 count = cf.Values.Count; for (Int32 i = 1; i <= count; i++) { var conditionalFormatValueObject = new ConditionalFormatValueObject { Type = cf.ContentTypes[i].ToOpenXml(), Val = cf.Values[i].Value, GreaterThanOrEqual = cf.IconSetOperators[i] == XLCFIconSetOperator.EqualOrGreaterThan }; iconSet.Append(conditionalFormatValueObject); } conditionalFormattingRule.Append(iconSet); return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); var dataBar = new DataBar { ShowValue = !cf.ShowBarOnly }; var conditionalFormatValueObject1 = GetConditionalFormatValueObjectByIndex(cf, 1, ConditionalFormatValueObjectValues.Min); var conditionalFormatValueObject2 = GetConditionalFormatValueObjectByIndex(cf, 2, ConditionalFormatValueObjectValues.Max); var color = new Color(); switch (cf.Colors[1].ColorType) { case XLColorType.Color: color.Rgb = cf.Colors[1].Color.ToHex(); break; case XLColorType.Theme: color.Theme = System.Convert.ToUInt32(cf.Colors[1].ThemeColor); break; case XLColorType.Indexed: color.Indexed = System.Convert.ToUInt32(cf.Colors[1].Indexed); break; } dataBar.Append(conditionalFormatValueObject1); dataBar.Append(conditionalFormatValueObject2); dataBar.Append(color); conditionalFormattingRule.Append(dataBar); var conditionalFormattingRuleExtensionList = new ConditionalFormattingRuleExtensionList(); conditionalFormattingRuleExtensionList.Append(BuildRuleExtension(cf)); conditionalFormattingRule.Append(conditionalFormattingRuleExtensionList); return(conditionalFormattingRule); }