【C#】【EXCEL】Bumblebee/Classes/ExRange.cs

server/2024/9/24 8:54:46/

Flow diagram

为了创建一个全面但不过于复杂的流程图,我们将重点关注 ExRange 类的主要功能和方法。以下是一个中英双语的流程图,展示了 ExRange 类的主要结构和操作流程:

默认构造函数
Default Constructor
COM 对象构造函数
COM Object Constructor
复制构造函数
Copy Constructor
属性操作
Property Operations
数据操作
Data Operations
格式化操作
Formatting Operations
条件格式化
Conditional Formatting
图表操作
Chart Operations
开始 / Start
创建 ExRange 实例
Create ExRange Instance
选择构造方法
Choose Constructor
创建空 ExRange
Create Empty ExRange
从 Excel Range 创建
Create from Excel Range
复制现有 ExRange
Copy Existing ExRange
选择操作类型
Choose Operation Type
获取/设置属性
Get/Set Properties
读取/写入数据
Read/Write Data
设置单元格格式
Set Cell Formatting
添加条件格式
Add Conditional Formatting
添加迷你图
Add Sparklines
字体属性
Font Properties
边框属性
Border Properties
单元格尺寸
Cell Dimensions
读取数据
Read Data
清除内容
Clear Content
设置字体
Set Font
设置边框
Set Border
合并单元格
Merge Cells
添加值条件
Add Value Condition
添加平均值条件
Add Average Condition
添加数据条
Add Data Bar
添加折线图
Add Line Sparkline
添加柱状图
Add Column Sparkline
操作完成
Operation Completed
结束 / End

这个流程图展示了 ExRange 类的主要功能和操作流程:

  1. 创建 ExRange 实例(对应构造函数)
  2. 选择操作类型(对应类中的不同方法组)
  3. 执行具体操作(对应具体的方法)
  4. 完成操作

流程图中的每个节点都有中英文说明,对应了代码中的相关部分。例如:

  • “创建 ExRange 实例” 对应了类的构造函数
  • “属性操作” 对应了类中的各种属性,如 FontFamily, FontSize 等
  • “数据操作” 对应了 ReadData() 和 ClearContent() 等方法
  • “格式化操作” 对应了 SetFont(), SetBorder() 等方法
  • “条件格式化” 对应了 AddConditionalValue(), AddConditionalAverage() 等方法
  • “图表操作” 对应了 AddSparkLine() 和 AddSparkColumn() 方法

Description

  1. ReadData() 方法
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;
}
  1. SetFont() 方法
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();
}
  1. AddConditionalValue() 方法
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;
}
  1. AddSparkLine() 方法
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 类中的其他重要方法,并解释它们的功能。

  1. ReadFillColors() 方法
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;
}
  1. GetMinPixel() 和 GetMaxPixel() 方法
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);
}
  1. ClearContent() 和 ClearFormat() 方法
public void ClearContent()
{// 清除范围内的所有内容,但保留格式this.ComObj.ClearContents();
}public void ClearFormat()
{// 清除范围内的所有格式,但保留内容this.ComObj.ClearFormats();
}
  1. MergeCells() 和 UnMergeCells() 方法
public void MergeCells()
{// 合并选定范围内的所有单元格this.ComObj.MergeCells = true;
}public void UnMergeCells()
{// 取消合并选定范围内的单元格this.ComObj.UnMerge();
}
  1. SetBorder() 方法
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;// ... (其他情况的处理)}
}
  1. AddSparkColumn() 方法
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;
}
  1. AddConditionalScale() 方法
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}
}

http://www.ppmy.cn/server/106241.html

相关文章

Django Signals

Django Signals 当某个事件发生的时候&#xff0c;signal(信号)允许senders(发送者)用来通知receivers(接收者)&#xff0c;通知receivers干嘛&#xff1f;你想要recivers干嘛就可以干嘛。这在多处代码对同一个事件感兴趣的时候就有用武之地了。 比如&#xff1a;Django提供了…

找在两个汉字中间的句号,如何写正则表达式?

要在两个汉字之间找到句号&#xff0c;可以使用以下正则表达式&#xff1a; (?<[\u4e00-\u9fff])。(?[\u4e00-\u9fff])解释&#xff1a; (?<[\u4e00-\u9fff]) 表示前面的字符是汉字。。 表示句号。(?[\u4e00-\u9fff]) 表示后面的字符是汉字。 这个正则表达式将匹配…

爆改YOLOv8 | 利用MB-TaylorFormer提高YOLOv8图像去雾检测

1&#xff0c;本文介绍 MB-TaylorFormer是一种新型多支路线性Transformer网络&#xff0c;用于图像去雾任务。它通过泰勒展开改进了softmax-attention&#xff0c;使用多支路和多尺度结构以获取多层次和多尺度的信息&#xff0c;且比传统方法在性能、计算量和网络重量上更优。…

Git的使用教程及常用语法02

四.将文件添加到仓库 创建仓库 git init查看仓库的状态 git status 添加到暂存区 git add提交 git commitgit status 可以查看当前仓库的状态信息&#xff0c;例如包含哪些分支&#xff0c;有哪些文件以及这些文件当前处在怎样的一个状态。 由于当前没有存储任何的东西&…

【Redis】

一.Widows下如何安装Redis? *(1) .下载地址: 点击跳转. 如下图: 在这里插入图片描述 *(2) .下载成功后将其移动到我们想要安装的目录下并且解压: 如下图: 在这里插入图片描述 *(3) .进入后有以下内容文件&#xff1a; *(4) .先点击redis-server.e…

SQLserver使用sql语句创建主键,外键,唯一约束,自增

在 SQL Server 中&#xff0c;可以通过 SQL 语句在创建表时或在现有表上添加约束&#xff0c;如主键&#xff08;PRIMARY KEY&#xff09;、外键&#xff08;FOREIGN KEY&#xff09;、唯一约束&#xff08;UNIQUE&#xff09;和自增&#xff08;IDENTITY&#xff09;。以下是如…

【蓝桥杯集训100题】scratch绘制扇子 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第28题

scratch绘制扇子 蓝桥杯集训100题第28题模拟练习解析 此题曾经作为第十届省赛的真题考过 一、题目要求 以坐标(0,0)点为中心绘制一把扇子;扇面和扇把都是三分之一圆,扇面的半径 为 100 左右,扇把的半径为 20 左右。 编程实现 每次点击绿旗后,舞台背景为白色,…

解锁 TypeScript Record 的奇妙用法:轻松搞定键值对!

在没有非常了解 Record 之前&#xff0c;定义对象的类型&#xff0c;一般使用 interface。它是 TS 中定义数据结构的一种方式&#xff0c;用来描述对象的形状、函数类型、类的结构等。 // 基本用法 interface User {name: string;age: number;isAdmin: boolean; }const user: …