Flow diagram
为了创建一个全面但不过于复杂的流程图,我们将重点关注 ExRange 类的主要功能和方法。以下是一个中英双语的流程图,展示了 ExRange 类的主要结构和操作流程:
这个流程图展示了 ExRange 类的主要功能和操作流程:
- 创建 ExRange 实例(对应构造函数)
- 选择操作类型(对应类中的不同方法组)
- 执行具体操作(对应具体的方法)
- 完成操作
流程图中的每个节点都有中英文说明,对应了代码中的相关部分。例如:
- “创建 ExRange 实例” 对应了类的构造函数
- “属性操作” 对应了类中的各种属性,如 FontFamily, FontSize 等
- “数据操作” 对应了 ReadData() 和 ClearContent() 等方法
- “格式化操作” 对应了 SetFont(), SetBorder() 等方法
- “条件格式化” 对应了 AddConditionalValue(), AddConditionalAverage() 等方法
- “图表操作” 对应了 AddSparkLine() 和 AddSparkColumn() 方法
Description
public GH_Structure<GH_String> ReadData()
{// 创建一个新的 GH_Structure 对象来存储单元格数据GH_Structure<GH_String> data = new GH_Structure<GH_String>();// 获取当前范围的边界信息(起始行列和结束行列)int[] L = GetRangeArray();// 从 Excel COM 对象中获取整个范围的值数组System.Array values = (System.Array)this.ComObj.Value2;// 如果值数组不为空,则开始处理数据if (values != null){// 遍历行(注意:Excel 数组索引从 1 开始)for (int i = 1; i < (L[3] - L[1] + 2); i++){// 为每一行创建一个新的路径GH_Path path = new GH_Path(i);// 遍历列for (int j = 1; j < (L[2] - L[0] + 2); j++){// 初始化单元格值为空字符串string val = string.Empty;// 如果单元格不为空,则获取其字符串表示if (values.GetValue(i, j) != null) val = values.GetValue(i, j).ToString();// 将单元格值添加到数据结构中data.Append(new GH_String(val), path);}}}// 返回包含所有单元格值的数据结构return data;
}
public void SetFont(string name, double size, Sd.Color color, Justification justification, bool bold, bool italic)
{// 获取范围的字体对象XL.Font font = this.ComObj.Font;// 设置字体名称font.Name = name;// 设置字体大小font.Size = size;// 设置字体颜色font.Color = color;// 设置是否加粗font.Bold = bold;// 设置是否斜体font.Italic = italic;// 设置水平对齐方式(使用自定义的 Justification 枚举转换方法)this.ComObj.HorizontalAlignment = justification.ToExcelHalign();// 设置垂直对齐方式(使用自定义的 Justification 枚举转换方法)this.ComObj.VerticalAlignment = justification.ToExcelValign();
}
public void AddConditionalValue(ValueCondition condition, double value, Sd.Color color)
{// 用于标记条件是否有效bool valid = true;// 根据不同的条件类型添加相应的条件格式switch (condition){case ValueCondition.Greater:// 添加"大于"条件格式this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlCellValue, XL.XlFormatConditionOperator.xlGreater, Formula1: value);break;case ValueCondition.GreaterEqual:// 添加"大于等于"条件格式this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlCellValue, XL.XlFormatConditionOperator.xlGreaterEqual, Formula1: value);break;// ... 其他条件类型的处理(省略)default:// 如果条件类型无效,将 valid 标记为 falsevalid = false;break;}// 如果条件有效,设置条件格式的背景颜色if (valid) this.ComObj.FormatConditions[this.ComObj.FormatConditions.Count].Interior.Color = color;
}
public void AddSparkLine(ExRange placement, Sd.Color color, double weight)
{// 在指定位置添加迷你图// this.ToString() 返回当前 ExRange 对象的地址字符串,用作数据源范围XL.SparklineGroup spark = placement.ComObj.SparklineGroups.Add(XL.XlSparkType.xlSparkLine, this.ToString());// 设置迷你图的颜色spark.SeriesColor.Color = color;// 设置迷你图线条的粗细spark.LineWeight = weight;
}
这些详细的中文注释解释了每个方法的功能、参数的作用以及实现的细节。它们有助于理解代码的逻辑和 Excel COM 对象的使用方式。这种详细的注释对于学习和维护代码都非常有帮助,特别是对于那些不熟悉 Excel 自动化或 COM 编程的开发者来说。
ExRange 类中的其他重要方法,并解释它们的功能。
public GH_Structure<GH_ObjectWrapper> ReadFillColors()
{// 创建一个新的 GH_Structure 来存储结果GH_Structure<GH_ObjectWrapper> ranges = new GH_Structure<GH_ObjectWrapper>();// 获取范围的起始和结束列行int Ax = this.Start.Column;int Ay = this.Start.Row;int Bx = this.Extent.Column;int By = this.Extent.Row;int k = 0;// 遍历范围内的每一列for (int i = Ax; i < Bx+1; i++){// 为每一列创建一个新的路径GH_Path path = new GH_Path(k);// 遍历该列中的每一行for (int j = Ay; j < By+1; j++){// 创建单元格地址string address = new ExCell(i, j).Address;// 为每个单元格创建一个新的 ExRange 对象ExRange rng = new ExRange(this.ComObj.Worksheet.Range[address,address]);// 将 ExRange 对象添加到结构中ranges.Append(new GH_ObjectWrapper(rng), path);}k++;}// 返回包含所有单元格 ExRange 对象的结构return ranges;
}
public Rg.Point3d GetMinPixel()
{// 返回范围左上角的像素坐标// ComObj.Left 和 ComObj.Top 分别表示左边距和上边距return new Rg.Point3d(this.ComObj.Left, this.ComObj.Top, 0);
}public Rg.Point3d GetMaxPixel()
{// 获取范围的左边距和上边距double X = this.ComObj.Left;double Y = this.ComObj.Top;// 获取范围的宽度和高度double W = this.ComObj.Width;double H = this.ComObj.Height;// 返回范围右下角的像素坐标return new Rg.Point3d(X + W, Y + H, 0);
}
public void ClearContent()
{// 清除范围内的所有内容,但保留格式this.ComObj.ClearContents();
}public void ClearFormat()
{// 清除范围内的所有格式,但保留内容this.ComObj.ClearFormats();
}
public void MergeCells()
{// 合并选定范围内的所有单元格this.ComObj.MergeCells = true;
}public void UnMergeCells()
{// 取消合并选定范围内的单元格this.ComObj.UnMerge();
}
public void SetBorder(Sd.Color color, BorderWeight weight, LineType type, HorizontalBorder horizontal, VerticalBorder vertical)
{// 获取范围的边框对象XL.Borders borders = this.ComObj.Borders;XL.Border left, right, top, bottom, betweenHorizontal, betweenVertical;// 处理水平边框switch (horizontal){case HorizontalBorder.All:// 设置底部边框bottom = borders[XL.XlBordersIndex.xlEdgeBottom];bottom.Weight = weight.ToExcel();bottom.Color = color;bottom.LineStyle = type.ToExcel();// 设置水平内部边框betweenHorizontal = borders[XL.XlBordersIndex.xlInsideHorizontal];betweenHorizontal.Weight = weight.ToExcel();betweenHorizontal.Color = color;betweenHorizontal.LineStyle = type.ToExcel();// 设置顶部边框top = borders[XL.XlBordersIndex.xlEdgeTop];top.Weight = weight.ToExcel();top.Color = color;top.LineStyle = type.ToExcel();break;// ... (其他情况的处理)}// 处理垂直边框switch (vertical){case VerticalBorder.All:// 设置左侧边框left = borders[XL.XlBordersIndex.xlEdgeLeft];left.Weight = weight.ToExcel();left.Color = color;left.LineStyle = type.ToExcel();// 设置垂直内部边框betweenVertical = borders[XL.XlBordersIndex.xlInsideVertical];betweenVertical.Weight = weight.ToExcel();betweenVertical.Color = color;betweenVertical.LineStyle = type.ToExcel();// 设置右侧边框right = borders[XL.XlBordersIndex.xlEdgeRight];right.Weight = weight.ToExcel();right.Color = color;right.LineStyle = type.ToExcel();break;// ... (其他情况的处理)}
}
public void AddSparkColumn(ExRange placement, Sd.Color color)
{// 在指定位置添加柱状迷你图// this.ToString() 返回当前范围的地址,作为迷你图的数据源XL.SparklineGroup spark = placement.ComObj.SparklineGroups.Add(XL.XlSparkType.xlSparkLine, this.ToString());// 设置迷你图类型为柱状图spark.Type = XL.XlSparkType.xlSparkColumn;// 设置迷你图的颜色spark.SeriesColor.Color = color;
}
public void AddConditionalScale(Sd.Color first, Sd.Color second, Sd.Color third, double mid = 0.5)
{// 确保 mid 值在 0 到 1 之间mid = Math.Min(mid, 1.0);mid = Math.Max(mid, 0.0);// 添加一个三色刻度的条件格式XL.ColorScale scale = this.ComObj.FormatConditions.AddColorScale(3);// 设置最低值的颜色scale.ColorScaleCriteria[1].Type = XL.XlConditionValueTypes.xlConditionValueLowestValue;scale.ColorScaleCriteria[1].FormatColor.Color = first;// 设置中间值的颜色和位置scale.ColorScaleCriteria[2].Type = XL.XlConditionValueTypes.xlConditionValuePercentile;scale.ColorScaleCriteria[2].Value = (int)(mid*100.0);scale.ColorScaleCriteria[2].FormatColor.Color = second;// 设置最高值的颜色scale.ColorScaleCriteria[3].Type = XL.XlConditionValueTypes.xlConditionValueHighestValue;scale.ColorScaleCriteria[3].FormatColor.Color = third;
}
这些详细的注释解释了每个方法的功能、参数的作用以及实现的细节。它们有助于理解代码的逻辑和 Excel COM 对象的使用方式。这种详细的注释对于学习和维护代码都非常有帮助,特别是对于那些不熟悉 Excel 自动化或 COM 编程的开发者来说。
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;using Sd = System.Drawing;using Rg = Rhino.Geometry;using XL = Microsoft.Office.Interop.Excel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;namespace Bumblebee
{public class ExRange{#region membersprotected ExCell start = new ExCell();protected ExCell extent = new ExCell();public XL.Range ComObj = null;#endregion#region constructorspublic ExRange(){}public ExRange(XL.Range comObj){this.ComObj = comObj;GetFirstCell();GetLastCell();}public ExRange(ExRange range){this.ComObj = range.ComObj;this.start = range.Start;this.extent = range.Extent;}#endregion#region propertiespublic virtual ExCell Start{get { return new ExCell(start); }set { start = new ExCell(value); }}public virtual ExCell Extent{get { return new ExCell(extent); }set { extent = new ExCell(value); }}public virtual ExWorksheet Worksheet{get { return new ExWorksheet(this.ComObj.Worksheet); }}public virtual ExWorkbook Workbook{get { return new ExWorkbook(this.Worksheet.Workbook); }}public virtual ExApp ParentApp{get { return new ExApp(this.ComObj.Application); }}public virtual bool IsSingle{get { return ((start.Column == extent.Column) & (start.Row == extent.Row)); }}public virtual string FontFamily{get { return this.ComObj.Font.Name; }set { this.ComObj.Font.Name = value; }}public virtual double FontSize{get { return this.ComObj.Font.Size; }set { this.ComObj.Font.Size = value; }}public virtual Sd.Color FontColor{get { return Sd.ColorTranslator.FromOle((int)this.ComObj.Font.Color); }set { this.ComObj.Font.Color = value; }}public virtual Justification FontJustification{set{this.ComObj.HorizontalAlignment = value.ToExcelHalign();this.ComObj.VerticalAlignment = value.ToExcelValign();}get{int align = 0;switch (this.ComObj.VerticalAlignment){case XL.XlVAlign.xlVAlignCenter:align = 3;break;case XL.XlVAlign.xlVAlignTop:align = 6;break;}switch (this.ComObj.VerticalAlignment){case XL.XlHAlign.xlHAlignLeft:case XL.XlHAlign.xlHAlignGeneral:break;case XL.XlHAlign.xlHAlignRight:align += 2;break;default:align += 1;break;}return (Justification)align;}}public bool Bold{get { return this.ComObj.Font.Bold; }set { this.ComObj.Font.Bold = value; }}public bool Italic{get { return this.ComObj.Font.Italic; }set { this.ComObj.Font.Italic = value; }}public virtual BorderWeight Weight{get { return ((XL.XlBorderWeight)this.ComObj.Borders.Weight).ToBB(); }}public virtual LineType LineType{get { return ((XL.XlLineStyle)this.ComObj.Borders.LineStyle).ToBB(); }}public virtual Sd.Color BorderColor{get { return Sd.ColorTranslator.FromOle((int)this.ComObj.Borders.Color); }}public virtual Sd.Color Background{get { return Sd.ColorTranslator.FromOle((int)this.ComObj.Interior.Color); }set { this.ComObj.Interior.Color = value; }}public virtual int Width{get { return this.ComObj.Columns.ColumnWidth; }set { this.ComObj.Columns.ColumnWidth = value; }}public virtual int Height{get { return this.ComObj.Rows.RowHeight; }set { this.ComObj.Rows.RowHeight = value; }}#endregion#region methods#region datapublic GH_Structure<GH_String> ReadData(){GH_Structure<GH_String> data = new GH_Structure<GH_String>();int[] L = GetRangeArray();System.Array values = (System.Array)this.ComObj.Value2;if (values != null){for (int i = 1; i < (L[3] - L[1] + 2); i++){GH_Path path = new GH_Path(i);for (int j = 1; j < (L[2] - L[0] + 2); j++){string val = string.Empty;if (values.GetValue(i, j) != null) val = values.GetValue(i, j).ToString();data.Append(new GH_String(val), path);}}}return data;}#endregion#region Graphicspublic GH_Structure<GH_ObjectWrapper> ReadFillColors(){GH_Structure<GH_ObjectWrapper> ranges = new GH_Structure<GH_ObjectWrapper>();int Ax = this.Start.Column;int Ay = this.Start.Row;int Bx = this.Extent.Column;int By = this.Extent.Row;int k = 0;for (int i = Ax; i < Bx+1; i++){GH_Path path = new GH_Path(k);for (int j = Ay; j < By+1; j++){string address = new ExCell(i, j).Address;ExRange rng = new ExRange(this.ComObj.Worksheet.Range[address,address]);ranges.Append(new GH_ObjectWrapper(rng), path);}k++;}return ranges;}#endregion#region Geometryprotected int[] GetRangeArray(){return new int[] { this.Start.Column, this.Start.Row, this.Extent.Column, this.Extent.Row };}public Rg.Point3d GetMinPixel(){return new Rg.Point3d(this.ComObj.Left, this.ComObj.Top, 0);}public Rg.Point3d GetMaxPixel(){double X = this.ComObj.Left;double Y = this.ComObj.Top;double W = this.ComObj.Width;double H = this.ComObj.Height;return new Rg.Point3d(X + W, Y + H, 0);}#endregion#region Extractprotected void GetFirstCell(){start= new ExCell(this.ComObj.Column, this.ComObj.Row, false, false);}protected ExRange GetFirstRange(){ExWorksheet sheet = new ExWorksheet(this.ComObj.Worksheet);return new ExRange(sheet.GetRange(start,start));}protected void GetLastCell(){extent= new ExCell(this.ComObj.Columns[this.ComObj.Columns.Count].Column, this.ComObj.Rows[this.ComObj.Rows.Count].Row, false, false);}public void ClearContent(){this.ComObj.ClearContents();}public void MergeCells(){this.ComObj.MergeCells = true;}public void UnMergeCells(){this.ComObj.UnMerge();}#endregion#region graphicspublic void ClearFormat(){this.ComObj.ClearFormats();}public void SetFont(string name, double size, Sd.Color color, Justification justification, bool bold, bool italic){XL.Font font = this.ComObj.Font;font.Name = name;font.Size = size;font.Color = color;font.Bold = bold;font.Italic = italic;this.ComObj.HorizontalAlignment = justification.ToExcelHalign();this.ComObj.VerticalAlignment = justification.ToExcelValign();}public void SetBorder(Sd.Color color, BorderWeight weight, LineType type, HorizontalBorder horizontal, VerticalBorder vertical){XL.Borders borders = this.ComObj.Borders;XL.Border left, right, top, bottom, betweenHorizontal, betweenVertical;switch (horizontal){case HorizontalBorder.All:bottom = borders[XL.XlBordersIndex.xlEdgeBottom];bottom.Weight = weight.ToExcel();bottom.Color = color;bottom.LineStyle = type.ToExcel();betweenHorizontal = borders[XL.XlBordersIndex.xlInsideHorizontal];betweenHorizontal.Weight = weight.ToExcel();betweenHorizontal.Color = color;betweenHorizontal.LineStyle = type.ToExcel();top = borders[XL.XlBordersIndex.xlEdgeTop];top.Weight = weight.ToExcel();top.Color = color;top.LineStyle = type.ToExcel();break;case HorizontalBorder.Between:betweenHorizontal = borders[XL.XlBordersIndex.xlInsideHorizontal];betweenHorizontal.Weight = weight.ToExcel();betweenHorizontal.Color = color;betweenHorizontal.LineStyle = type.ToExcel();break;case HorizontalBorder.Both:bottom = borders[XL.XlBordersIndex.xlEdgeBottom];bottom.Weight = weight.ToExcel();bottom.Color = color;bottom.LineStyle = type.ToExcel();top = borders[XL.XlBordersIndex.xlEdgeTop];top.Weight = weight.ToExcel();top.Color = color;top.LineStyle = type.ToExcel();break;case HorizontalBorder.Bottom:bottom = borders[XL.XlBordersIndex.xlEdgeBottom];bottom.Weight = weight.ToExcel();bottom.Color = color;bottom.LineStyle = type.ToExcel();break;case HorizontalBorder.Top:top = borders[XL.XlBordersIndex.xlEdgeTop];top.Weight = weight.ToExcel();top.Color = color;top.LineStyle = type.ToExcel();break;}switch (vertical){case VerticalBorder.All:left = borders[XL.XlBordersIndex.xlEdgeLeft];left.Weight = weight.ToExcel();left.Color = color;left.LineStyle = type.ToExcel();betweenVertical = borders[XL.XlBordersIndex.xlInsideVertical];betweenVertical.Weight = weight.ToExcel();betweenVertical.Color = color;betweenVertical.LineStyle = type.ToExcel();right = borders[XL.XlBordersIndex.xlEdgeRight];right.Weight = weight.ToExcel();right.Color = color;right.LineStyle = type.ToExcel();break;case VerticalBorder.Between:betweenVertical = borders[XL.XlBordersIndex.xlInsideVertical];betweenVertical.Weight = weight.ToExcel();betweenVertical.Color = color;betweenVertical.LineStyle = type.ToExcel();break;case VerticalBorder.Both:left = borders[XL.XlBordersIndex.xlEdgeLeft];left.Weight = weight.ToExcel();left.Color = color;left.LineStyle = type.ToExcel();right = borders[XL.XlBordersIndex.xlEdgeRight];right.Weight = weight.ToExcel();right.Color = color;right.LineStyle = type.ToExcel();break;case VerticalBorder.Left:left = borders[XL.XlBordersIndex.xlEdgeLeft];left.Weight = weight.ToExcel();left.Color = color;left.LineStyle = type.ToExcel();break;case VerticalBorder.Right:right = borders[XL.XlBordersIndex.xlEdgeRight];right.Weight = weight.ToExcel();right.Color = color;right.LineStyle = type.ToExcel();break;}}#endregion#region sparklinespublic void AddSparkLine(ExRange placement, Sd.Color color, double weight){XL.SparklineGroup spark = placement.ComObj.SparklineGroups.Add(XL.XlSparkType.xlSparkLine, this.ToString());spark.SeriesColor.Color= color;spark.LineWeight = weight;}public void AddSparkColumn(ExRange placement, Sd.Color color){XL.SparklineGroup spark = placement.ComObj.SparklineGroups.Add(XL.XlSparkType.xlSparkLine, this.ToString());spark.Type = XL.XlSparkType.xlSparkColumn;spark.SeriesColor.Color = color;}#endregion#region conditionalpublic void ClearConditions(){this.ComObj.FormatConditions.Delete();}public void AddConditionalValue(ValueCondition condition, double value, Sd.Color color){bool valid = true;switch (condition){case ValueCondition.Greater:this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlCellValue, XL.XlFormatConditionOperator.xlGreater, Formula1: value);break;case ValueCondition.GreaterEqual:this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlCellValue, XL.XlFormatConditionOperator.xlGreaterEqual, Formula1: value);break;case ValueCondition.Less:this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlCellValue, XL.XlFormatConditionOperator.xlLess, Formula1: value);break;case ValueCondition.LessEqual:this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlCellValue, XL.XlFormatConditionOperator.xlLessEqual, Formula1: value);break;case ValueCondition.Equal:this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlCellValue, XL.XlFormatConditionOperator.xlEqual, Formula1: value);break;case ValueCondition.NotEqual:this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlCellValue, XL.XlFormatConditionOperator.xlNotEqual, Formula1: value);break;default:valid = false;break;}if (valid) this.ComObj.FormatConditions[this.ComObj.FormatConditions.Count].Interior.Color = color;}public void AddConditionalAverage(AverageCondition condition, Sd.Color color){bool valid = true;switch (condition){case AverageCondition.AboveAverage:this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlAboveAverageCondition, XL.XlAboveBelow.xlAboveAverage);break;case AverageCondition.AboveDeviation:this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlAboveAverageCondition, XL.XlAboveBelow.xlAboveStdDev);break;case AverageCondition.AboveEqualAverage:this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlAboveAverageCondition, XL.XlAboveBelow.xlEqualAboveAverage);break;case AverageCondition.BelowAverage:this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlAboveAverageCondition, XL.XlAboveBelow.xlBelowAverage);break;case AverageCondition.BelowDeviation:this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlAboveAverageCondition, XL.XlAboveBelow.xlBelowStdDev);break;case AverageCondition.BelowEqualAverage:this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlAboveAverageCondition, XL.XlAboveBelow.xlEqualBelowAverage);break;default:valid = false;break;}if (valid) this.ComObj.FormatConditions[this.ComObj.FormatConditions.Count].Interior.Color = color;}public void AddConditionalBetween(double low, double high, Sd.Color color, bool flip=false){if (flip){this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlCellValue, XL.XlFormatConditionOperator.xlNotBetween, Formula1: low,Formula2:high);}else{this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlCellValue, XL.XlFormatConditionOperator.xlBetween, Formula1: low, Formula2: high);}this.ComObj.FormatConditions[this.ComObj.FormatConditions.Count].Interior.Color = color;}public void AddConditionalUnique(Sd.Color color, bool flip = false){XL.UniqueValues unique = this.ComObj.FormatConditions.AddUniqueValues();if (flip){unique.DupeUnique = XL.XlDupeUnique.xlDuplicate;}else{unique.DupeUnique = XL.XlDupeUnique.xlUnique;}unique.Interior.Color = color;}public void AddConditionalTopCount(int count, Sd.Color color, bool flip = false){XL.Top10 top = this.ComObj.FormatConditions.AddTop10();top.Percent = false;top.Rank = count;if (flip){top.TopBottom = XL.XlTopBottom.xlTop10Bottom;}else{top.TopBottom = XL.XlTopBottom.xlTop10Top;}top.Interior.Color = color;}public void AddConditionalTopPercent(double percent, Sd.Color color, bool flip = false){percent = Math.Min(percent, 1.0);percent = Math.Max(percent, 0.0);XL.Top10 top = this.ComObj.FormatConditions.AddTop10();top.Percent = true;top.Rank = (int)(percent*100.0);if (flip){top.TopBottom = XL.XlTopBottom.xlTop10Bottom;}else{top.TopBottom = XL.XlTopBottom.xlTop10Top;}top.Interior.Color = color;}public void AddConditionalBlanks(Sd.Color color, bool flip = false){if (flip){this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlNoBlanksCondition);}else{this.ComObj.FormatConditions.Add(XL.XlFormatConditionType.xlBlanksCondition);}this.ComObj.FormatConditions[this.ComObj.FormatConditions.Count].Interior.Color = color;}public void AddConditionalScale(Sd.Color first, Sd.Color second, Sd.Color third, double mid = 0.5){mid = Math.Min(mid, 1.0);mid = Math.Max(mid, 0.0);XL.ColorScale scale = this.ComObj.FormatConditions.AddColorScale(3);scale.ColorScaleCriteria[1].Type = XL.XlConditionValueTypes.xlConditionValueLowestValue;scale.ColorScaleCriteria[1].FormatColor.Color = first;scale.ColorScaleCriteria[2].Type = XL.XlConditionValueTypes.xlConditionValuePercentile;scale.ColorScaleCriteria[2].Value = (int)(mid*100.0);scale.ColorScaleCriteria[2].FormatColor.Color = second;scale.ColorScaleCriteria[3].Type = XL.XlConditionValueTypes.xlConditionValueHighestValue;scale.ColorScaleCriteria[3].FormatColor.Color = third;}public void AddConditionalScale(Sd.Color first, Sd.Color second){XL.ColorScale scale = this.ComObj.FormatConditions.AddColorScale(2);int count = this.ComObj.FormatConditions.Count;scale.ColorScaleCriteria[1].Type = XL.XlConditionValueTypes.xlConditionValueLowestValue;scale.ColorScaleCriteria[1].FormatColor.Color = first;scale.ColorScaleCriteria[2].Type = XL.XlConditionValueTypes.xlConditionValueHighestValue;scale.ColorScaleCriteria[2].FormatColor.Color = second;}public void AddConditionalBar(Sd.Color color, bool gradient){XL.Databar bar = this.ComObj.FormatConditions.AddDatabar();bar.BarColor.Color = color;if (gradient){bar.BarFillType = XL.XlDataBarFillType.xlDataBarFillGradient;}else{bar.BarFillType = XL.XlDataBarFillType.xlDataBarFillSolid;}}#endregion#endregion#region overridespublic override string ToString(){return this.start.Address+":"+this.extent.Address;}#endregion}
}