/// <summary>继续由 Find 方法开始的搜索。查找匹配相同条件的上一个单元格,并返回代表该单元格的 Range 对象。该操作不影响选定内容和活动单元格。 /// </summary> /// <param name="After">指定一个单元格,查找将从该单元格之前开始。此单元格对应于从用户界面搜索时的活动单元格的位置。请注意:After 必须是区域中的单个单元格。注意,搜索是从该单元格之前开始的;直到本方法环绕到此单元格时,才检测其内容。如果未指定本参数,查找将从区域的左上角单元格之前开始。</param> public Range FindPrevious(Range After = null) { _objaParameters = new object[1] { After == null ? System.Type.Missing : After._objRange }; return new Range(_objRange.GetType().InvokeMember("FindPrevious", BindingFlags.InvokeMethod, null, _objRange, _objaParameters)); }
/// <summary>为得出特定结果而进行单变量求解。如果此特定结果是由某公式返回的量,本方法将求出该公式中未知数的值,当用该值代换公式中的未知数时,该公式将得出所需的特定结果。如果单变量求解成功,则该值为 True。 /// </summary> /// <param name="Goal">希望在该单元格中返回的结果。</param> /// <param name="ChangingCell">指定为获得目标值而应更改的单元格。</param> public bool GoalSeek(object Goal, Range ChangingCell) { _objaParameters = new object[2] { Goal, ChangingCell._objRange }; return (bool)_objRange.GetType().InvokeMember("GoalSeek", BindingFlags.InvokeMethod, null, _objRange, _objaParameters); }
/// <summary>将对象剪切到剪贴板,或者将其粘贴到指定的目的地。 /// </summary> /// <param name="Destination">应在其中粘贴对象的目标区域。如果省略此参数,区域对象会被剪切到剪贴板。</param> public dynamic Cut(Range Destination = null) { _objaParameters = new object[1] { Destination == null ? System.Type.Missing : Destination._objRange }; return _objRange.GetType().InvokeMember("Cut", BindingFlags.InvokeMethod, null, _objRange, _objaParameters); }
/// <summary>在区域中查找特定信息。 /// </summary> /// <param name="What">要搜索的数据。可为字符串或任意 Microsoft Excel 数据类型。</param> /// <param name="After">表示搜索过程将从其之后开始进行的单元格。此单元格对应于从用户界面搜索时的活动单元格的位置。请注意:After 必须是区域中的单个单元格。要记住搜索是从该单元格之后开始的;直到此方法绕回到此单元格时,才对其进行搜索。如果不指定该参数,搜索将从区域的左上角的单元格之后开始。</param> /// <param name="LookIn">信息类型。</param> /// <param name="LookAt">可为以下 XlLookAt 常量之一:xlWhole 或 xlPart。</param> /// <param name="SearchOrder">可为以下 XlSearchOrder 常量之一:xlByRows 或 xlByColumns。</param> /// <param name="SearchDirection">搜索的方向。</param> /// <param name="MatchCase">如果为 True,则搜索区分大小写。默认值为 False。</param> /// <param name="MatchByte">只在已经选择或安装了双字节语言支持时适用。如果为 True,则双字节字符只与双字节字符匹配。如果为 False,则双字节字符可与其对等的单字节字符匹配。</param> /// <param name="SearchFormat">搜索的格式。</param> public Range Find(object What, Range After = null, object LookIn = null, XlLookAt? LookAt = null, XlSearchOrder? SearchOrder = null, XlSearchDirection SearchDirection = XlSearchDirection.xlNext, bool? MatchCase = null, bool? MatchByte = null, string SearchFormat = null) { _objaParameters = new object[9] { What, After == null ? System.Type.Missing : After._objRange, LookIn == null ? System.Type.Missing : LookIn, LookAt == null ? System.Type.Missing : LookAt, SearchOrder == null ? System.Type.Missing : SearchOrder, SearchDirection, MatchCase == null ? System.Type.Missing : MatchCase, MatchByte == null ? System.Type.Missing : MatchByte, SearchFormat == null ? System.Type.Missing : SearchFormat }; return new Range(_objRange.GetType().InvokeMember("Find", BindingFlags.InvokeMethod, null, _objRange, _objaParameters)); }
/// <summary>将“剪贴板”中的内容粘贴到工作表上。 /// </summary> /// <param name="Destination">一个 Range 对象,指定用于粘贴剪贴板中内容的目标区域。如果省略此参数,就使用当前的选定区域。仅当剪贴板中的内容能被粘贴到某区域时,才能指定此参数。如果指定了此参数,则不能使用 Link 参数。</param> /// <param name="Link">如果为 True,则链接到被粘贴数据的源。如果指定此参数,则不能使用 Destination 参数。默认值是 False。</param> public void Paste(Range Destination = null, bool? Link = null) { _objaParameters = new object[2] { Destination == null ? System.Type.Missing : Destination._objRange, Link == null ? System.Type.Missing : Link }; _objWorksheet.GetType().InvokeMember("Paste", BindingFlags.InvokeMethod, null, _objWorksheet, _objaParameters); }
/// <summary>对指定区域中的单元格执行自动填充。 /// </summary> /// <param name="Destination">要填充的单元格。目标区域必须包括源区域。</param> /// <param name="Type">指定填充类型。</param> public dynamic AutoFill(Range Destination, XlAutoFillType Type = XlAutoFillType.xlFillDefault) { _objaParameters = new object[2] { Destination._objRange, Type }; return _objRange.GetType().InvokeMember("AutoFill", BindingFlags.InvokeMethod, null, _objRange, _objaParameters); }
/// <summary>为指定图表设置源数据区域。 /// </summary> /// <param name="Source">包含源数据的区域。</param> /// <param name="PlotBy">指定数据绘制方式。可为以下 XlRowCol 常量之一:xlColumns 或 xlRows。</param> public void SetSourceData(Range Source, XlRowCol? PlotBy = null) { _objaParameters = new object[2] { Source._objRange, PlotBy == null ? System.Type.Missing : PlotBy }; _objChart.GetType().InvokeMember("SetSourceData", BindingFlags.InvokeMethod, null, _objChart, _objaParameters); }
/// <summary>依据输入值和工作表上定义的公式创建数据表。 /// </summary> /// <param name="RowInput">用作数据表行输入的单个单元格。</param> /// <param name="ColumnInput">用作数据表列输入的单个单元格。</param> public dynamic Table(Range RowInput = null, Range ColumnInput = null) { _objaParameters = new object[2] { RowInput == null ? System.Type.Missing : RowInput._objRange, ColumnInput == null ? System.Type.Missing : ColumnInput._objRange }; return _objRange.GetType().InvokeMember("Table", BindingFlags.InvokeMethod, null, _objRange, _objaParameters); }
/// <summary>选定任意工作簿中的任意区域或任意 Visual Basic 过程,并且如果该工作簿未处于活动状态,就激活该工作簿。 /// 说明: /// 该方法与 Select 方法的区别: /// 如果指定的区域不在位于最前面屏幕的工作表中,Microsoft Excel 将在选定该区域之前切换至该工作表。(如果对不在屏幕的最前面的工作表中的区域使用 Select 方法,则选定该区域时并不激活该工作表)。 /// 该方法具有让用户滚动目标窗口的 Scroll 参数。 /// 当使用 Goto 方法时,前一次选定区域(Goto 方法运行前)被增加到以前选定区域的数组中(有关详细信息,请参阅 PreviousSelections 属性)。可以使用该功能快速跳过选定区域,选定区域最多为四个。 /// Select 方法具有 Replace 参数,而 Goto 方法没有该参数。 /// </summary> /// <param name="Reference">目标。可以是 Range 对象、包含 R1C1-样式批注的单元格引用的字符串或包含 Visual Basic 过程名的字符串。如果省略该参数,目标将为最近一次用 Goto 方法选定的区域。</param> /// <param name="Scroll">如果为 True,则滚动窗口直至区域的左上角出现在窗口的左上角中。如果为 False,则不滚动窗口。默认值为 False。</param> public void Goto(Range Reference = null, bool? Scroll = null) { _objaParameters = new object[2] { Reference == null ? System.Type.Missing : Reference, Scroll == null ? System.Type.Missing : Scroll }; _objApplication.GetType().InvokeMember("Goto", BindingFlags.InvokeMethod, null, _objApplication, _objaParameters); }
/// <summary>返回两个或多个区域的合并区域。必须指定至少两个 Range 对象。 /// </summary> public Range Union(Range Arg1, Range Arg2, Range Arg3 = null, Range Arg4 = null, Range Arg5 = null, Range Arg6 = null, Range Arg7 = null, Range Arg8 = null, Range Arg9 = null, Range Arg10 = null, Range Arg11 = null, Range Arg12 = null, Range Arg13 = null, Range Arg14 = null, Range Arg15 = null, Range Arg16 = null, Range Arg17 = null, Range Arg18 = null, Range Arg19 = null, Range Arg20 = null, Range Arg21 = null, Range Arg22 = null, Range Arg23 = null, Range Arg24 = null, Range Arg25 = null, Range Arg26 = null, Range Arg27 = null, Range Arg28 = null, Range Arg29 = null, Range Arg30 = null) { _objaParameters = new object[30] { Arg1, Arg2, Arg3 == null ? System.Type.Missing : Arg3, Arg4 == null ? System.Type.Missing : Arg4, Arg5 == null ? System.Type.Missing : Arg5, Arg6 == null ? System.Type.Missing : Arg6, Arg7 == null ? System.Type.Missing : Arg7, Arg8 == null ? System.Type.Missing : Arg8, Arg9 == null ? System.Type.Missing : Arg9, Arg10 == null ? System.Type.Missing : Arg10, Arg11 == null ? System.Type.Missing : Arg11, Arg12 == null ? System.Type.Missing : Arg12, Arg13 == null ? System.Type.Missing : Arg13, Arg14 == null ? System.Type.Missing : Arg14, Arg15 == null ? System.Type.Missing : Arg15, Arg16 == null ? System.Type.Missing : Arg16, Arg17 == null ? System.Type.Missing : Arg17, Arg18 == null ? System.Type.Missing : Arg18, Arg19 == null ? System.Type.Missing : Arg19, Arg20 == null ? System.Type.Missing : Arg20, Arg21 == null ? System.Type.Missing : Arg21, Arg22 == null ? System.Type.Missing : Arg22, Arg23 == null ? System.Type.Missing : Arg23, Arg24 == null ? System.Type.Missing : Arg24, Arg25 == null ? System.Type.Missing : Arg25, Arg26 == null ? System.Type.Missing : Arg26, Arg27 == null ? System.Type.Missing : Arg27, Arg28 == null ? System.Type.Missing : Arg28, Arg29 == null ? System.Type.Missing : Arg29, Arg30 == null ? System.Type.Missing : Arg30 }; return new Range(_objApplication.GetType().InvokeMember("Union", BindingFlags.InvokeMethod, null, _objApplication, _objaParameters)); }
/// <summary>在 A1 和 R1C1 引用样式之间转换、在相对和绝对引用之间转换公式中的单元格引用,或者同时进行这两种转换。Variant 类型。 /// </summary> /// <param name="Formula">包含要转换的公式的字符串。必须为有效的公式,并且必须以等号开头。</param> /// <param name="FromReferenceStyle">公式的引用样式。</param> /// <param name="ToReferenceStyle">指定要返回的引用样式的 XlReferenceStyle 常量。如果省略此参数,则引用样式不变;公式样式保持 FromReferenceStyle 参数指定的样式。</param> /// <param name="ToAbsolute">指定转换引用类型的 XlReferenceStyle 常量。如果省略该参数,则引用类型不变。</param> /// <param name="RelativeTo">包含一个单元格的 Range 对象。相对引用与此单元格相对。</param> /// <returns></returns> public dynamic ConvertFormula(string Formula, XlReferenceStyle FromReferenceStyle, XlReferenceStyle? ToReferenceStyle = null, XlReferenceStyle? ToAbsolute = null, Range RelativeTo = null) { _objaParameters = new object[5] { Formula , FromReferenceStyle , ToReferenceStyle == null ? System.Type.Missing : ToReferenceStyle, ToAbsolute == null ? System.Type.Missing : ToAbsolute, RelativeTo == null ? System.Type.Missing : RelativeTo._objRange }; return _objApplication.GetType().InvokeMember("CheckSpelling", BindingFlags.InvokeMethod, null, _objApplication, _objaParameters); }
/// <summary>停止 Microsoft Excel 应用程序中的重新计算。 /// </summary> /// <param name="KeepAbort">允许对区域执行重新计算。</param> public void CheckAbort(Range KeepAbort = null) { _objaParameters = new object[1] { KeepAbort == null ? System.Type.Missing : KeepAbort._objRange }; _objApplication.GetType().InvokeMember("CheckAbort", BindingFlags.InvokeMethod, null, _objApplication, _objaParameters); }
/// <summary>创建一个新的数据透视表。此方法不显示“数据透视表向导”,它不适用于 OLE DB 数据源。请使用 Add 方法添加数据透视表缓存,然后创建基于该缓存的数据透视表。 /// </summary> /// <param name="SourceType">一个代表报表数据源的 XlPivotTableSourceType 值。如果指定了此参数,那么必须同时指定 SourceData。如果忽略 SourceType 和 SourceData,Microsoft Excel 将假定源类型为 xlDatabase,并假定源数据来自命名区域“Database”。如果该命名区域不存在,那么当选定区域所在的当前区域中包含数据的单元格超过 10 个时,Microsoft Excel 就使用当前区域。否则,此方法将失败。</param> /// <param name="SourceData">新报表的数据。它可以是一个 Range 对象、一个区域数组或是代表其他报表名称的一个文本常量。对于外部数据库而言,SourceData 是一个包含 SQL 查询字符串的字符串数组,其中的每个元素最长为 255 个字符。您应该使用 Connection 参数指定 ODBC 连接字符串。为了能与旧版本的 Excel 兼容,SourceData 可以是一个二元数组。第一个元素是用于指定数据的 ODBC 源的连接字符串,第二个元素是用于获取数据的 SQL 查询字符串。如果指定 SourceData,则必须同时指定 SourceType。如果活动单元格位于 SourceData 区域内,则必须同时指定 TableDestination。</param> /// <param name="TableDestination">一个 Range 对象,它指定报表在工作表中的位置。如果省略此参数,则将报表置于活动单元格中。</param> /// <param name="TableName">用于指定新报表名称的字符串。</param> /// <param name="RowGrand">如果为 True,则显示报表中的行总计。</param> /// <param name="ColumnGrand">如果为 True,则显示报表中的列总计。</param> /// <param name="SaveData">如果为 True,则保存报表中的数据。如果为 False,则仅保存报表的定义。</param> /// <param name="HasAutoFormat">如果为 True,当刷新报表或移动字段时,Microsoft Excel 将自动设置其格式。</param> /// <param name="AutoPage">仅当 SourceType 为 xlConsolidation 时有效。如果值为 True,Microsoft Excel 将为合并创建页字段。如果 AutoPage 为 False,则必须创建一个或多个页字段。</param> /// <param name="Reserved">不在 Microsoft Excel 中使用。</param> /// <param name="BackgroundQuery">如果为 True,则 Excel 将异步执行(后台执行)报表查询。默认值为 False。</param> /// <param name="OptimizeCache">如果为 True,则在构造数据透视表的缓存时对其进行优化。默认值为 False。</param> /// <param name="PageFieldOrder">在数据透视表布局中添加页字段的顺序。可为以下 XlOrder 常量之一:xlDownThenOver 或 xlOverThenDown。默认值为 xlDownThenOver。</param> /// <param name="PageFieldWrapCount">数据透视表中每列或每行的页字段数。默认值为 0(零)。</param> /// <param name="ReadData">如果为 True,则创建数据透视表缓存以包含外部数据库中的所有记录;此时缓存可能会很大。如果 ReadData 为 False,则可在实际读取数据之前,将某些字段设为基于服务器的页字段。</param> /// <param name="Connection">包含 ODBC 设置的字符串,这些设置使得 Excel 可以连接 ODBC 数据源。连接字符串的格式为“ODBC;<连接字符串>”。该参数取代以前为 PivotCache 对象的 Connection 属性所做的任何设置。</param> public PivotTable PivotTableWizard(XlPivotTableSourceType? SourceType = null, object SourceData = null, Range TableDestination = null, string TableName = null, bool? RowGrand = null, bool? ColumnGrand = null, bool? SaveData = null, bool? HasAutoFormat = null, bool? AutoPage = null, object Reserved = null, bool? BackgroundQuery = null, bool? OptimizeCache = null, XlOrder? PageFieldOrder = null, int? PageFieldWrapCount = null, bool? ReadData = null, string Connection = null) { _objaParameters = new object[16] { SourceType == null ? System.Type.Missing : SourceType, SourceData == null ? System.Type.Missing : SourceData, TableDestination == null ? System.Type.Missing : TableDestination._objRange, TableName == null ? System.Type.Missing : TableName, RowGrand == null ? System.Type.Missing : RowGrand, ColumnGrand == null ? System.Type.Missing : ColumnGrand, SaveData == null ? System.Type.Missing : SaveData, HasAutoFormat == null ? System.Type.Missing : HasAutoFormat, AutoPage == null ? System.Type.Missing : AutoPage, Reserved == null ? System.Type.Missing : Reserved, BackgroundQuery == null ? System.Type.Missing : BackgroundQuery, OptimizeCache == null ? System.Type.Missing : OptimizeCache, PageFieldOrder == null ? System.Type.Missing : PageFieldOrder, PageFieldWrapCount == null ? System.Type.Missing : PageFieldWrapCount, ReadData == null ? System.Type.Missing : ReadData, Connection == null ? System.Type.Missing : Connection }; return new PivotTable(_objWorksheet.GetType().InvokeMember("PivotTableWizard", BindingFlags.InvokeMethod, null, _objWorksheet, _objaParameters)); }
/// <summary>分列区域内的数据并将这些数据分散放置于若干单元格中。将区域内容分配于多个相邻接的列中;该区域只能包含一列。 /// </summary> /// <param name="ParseLine">包含方括号的字符串,用以指明在何处拆分单元格。</param> /// <param name="Destination">一个代表用于放置分列数据的目标区域的左上角的 Range 对象。如果省略该参数,Microsoft Excel 将在原处进行分列。</param> public dynamic Parse(string ParseLine = null, Range Destination = null) { _objaParameters = new object[2] { ParseLine == null ? System.Type.Missing : ParseLine, Destination == null ? System.Type.Missing : Destination._objRange }; return _objRange.GetType().InvokeMember("Parse", BindingFlags.InvokeMethod, null, _objRange, _objaParameters); }
/// <summary> /// </summary> public void FillAcrossSheets(Range Range, XlFillWith Type = XlFillWith.xlFillWithAll) { _objaParameters = new object[2] { Range._objRange, Type }; _objCharts.GetType().InvokeMember("FillAcrossSheets", BindingFlags.InvokeMethod, null, _objCharts, _objaParameters); }
/// <summary>返回一个 Range 对象,该对象表示每行中与比较单元格内容不同的所有单元格。 /// </summary> /// <param name="Comparison">用于与指定区域进行比较的单个单元格。</param> public Range RowDifferences(Range Comparison) { _objaParameters = new object[1] { Comparison._objRange }; return new Range(_objRange.GetType().InvokeMember("RowDifferences", BindingFlags.InvokeMethod, null, _objRange, _objaParameters)); }
/// <summary>基于条件区域从列表中筛选或复制数据。如果初始选定区域为单个单元格,则使用单元格的当前区域。 /// </summary> /// <param name="Action">XlFilterAction 的常量之一,用于指定是否就地复制或筛选列表。</param> /// <param name="CriteriaRange">条件区域。如果省略该参数,则没有条件限制。</param> /// <param name="CopyToRange">如果 Action 为 xlFilterCopy,则为复制行的目标区域。否则,忽略该参数。</param> /// <param name="Unique">如果为 True,则只筛选唯一记录。如果为 False,则筛选符合条件的所有记录。默认值为 False。</param> public dynamic AdvancedFilter(XlFilterAction Action, Range CriteriaRange = null, Range CopyToRange = null, bool? Unique = null) { _objaParameters = new object[4] { Action, CriteriaRange == null ? System.Type.Missing : CriteriaRange._objRange, CopyToRange == null ? System.Type.Missing : CopyToRange._objRange, Unique == null ? System.Type.Missing : Unique }; return _objRange.GetType().InvokeMember("AdvancedFilter", BindingFlags.InvokeMethod, null, _objRange, _objaParameters); }
/// <summary>将包含文本的一列单元格分解为若干列。 /// </summary> /// <param name="Destination">一个 Range 对象,指定 Microsoft Excel 放置结果的位置。如果该区域大于一个单元格,则使用左上角的单元格。</param> /// <param name="DataType">将被拆分到多列中的文本的格式。</param> /// <param name="TextQualifier">指定是将单引号、双引号用作文本分隔符还是不使用引号。</param> /// <param name="ConsecutiveDelimiter">如果为 True,则 Microsoft Excel 将连续分隔符视为一个分隔符。默认值为 False。</param> /// <param name="Tab">如果为 True,则 DataType 为 xlDelimited 并将制表符作为分隔符。默认值为 False。</param> /// <param name="Semicolon">如果为 True,则 DataType 为 xlDelimited 并将分号作为分隔符。默认值为 False。</param> /// <param name="Comma">如果为 True,则 DataType 为 xlDelimited 并将逗号作为分隔符。默认值为 False。</param> /// <param name="Space">如果为 True,则 DataType 为 xlDelimited 并将空格字符作为分隔符。默认值为 False。</param> /// <param name="Other">如果为 True,则 DataType 为 xlDelimited 并将 OtherChar 参数指定的字符作为分隔符。默认值为 False。</param> /// <param name="OtherChar">(如果 Other 为 True,则为必选项)。当 Other 为 True 时的分隔符。如果指定了多个字符,则仅使用字符串中的第一个字符而忽略剩余字符。</param> /// <param name="FieldInfo">包含单列数据相关分列信息的数组。对该参数的解释取决于 DataType 的值。如果此数据由分隔符分隔,则该参数为由两元素数组组成的数组,其中每个两元素数组指定一个特定列的转换选项。第一个元素为列标(从 1 开始),第二个元素是 xlColumnDataType 的常量之一,用于指定分列方式。</param> /// <param name="DecimalSeparator">识别数字时,Microsoft Excel 使用的小数分隔符。默认设置为系统设置。</param> /// <param name="ThousandsSeparator">识别数字时,Excel 使用的千位分隔符。默认设置为系统设置。</param> /// <param name="TrailingMinusNumbers">以减号字符开始的数字。</param> public dynamic TextToColumns(Range Destination = null, XlTextParsingType DataType = XlTextParsingType.xlDelimited, XlTextQualifier TextQualifier = XlTextQualifier.xlTextQualifierDoubleQuote, bool? ConsecutiveDelimiter = null, bool? Tab = null, bool? Semicolon = null, bool? Comma = null, bool? Space = null, bool? Other = null, string OtherChar = null, object FieldInfo = null, string DecimalSeparator = null, string ThousandsSeparator = null, int? TrailingMinusNumbers = null) { _objaParameters = new object[14] { Destination == null ? System.Type.Missing : Destination._objRange, DataType, TextQualifier, ConsecutiveDelimiter == null ? System.Type.Missing : ConsecutiveDelimiter, Tab == null ? System.Type.Missing : Tab, Semicolon == null ? System.Type.Missing : Semicolon, Comma == null ? System.Type.Missing : Comma, Space == null ? System.Type.Missing : Space, Other == null ? System.Type.Missing : Other, OtherChar == null ? System.Type.Missing : OtherChar, FieldInfo == null ? System.Type.Missing : FieldInfo, DecimalSeparator == null ? System.Type.Missing : DecimalSeparator, ThousandsSeparator == null ? System.Type.Missing : ThousandsSeparator, TrailingMinusNumbers == null ? System.Type.Missing : TrailingMinusNumbers }; return _objRange.GetType().InvokeMember("TextToColumns", BindingFlags.InvokeMethod, null, _objRange, _objaParameters); }
/// <summary>返回一个 Range 对象,它代表一个单元格或单元格区域。 /// </summary> /// <param name="Cell1">ExcelCell1</param> /// <param name="Cell2">ExcelCell2</param> /// <returns></returns> public Range get_Range(Range Cell1, Range Cell2) { _objaParameters = new object[2] { Cell1._objRange, Cell2._objRange }; object objRange = _objWorksheet.GetType().InvokeMember("Range", BindingFlags.GetProperty, null, _objWorksheet, _objaParameters); return new Range(objRange); }