本文整理汇总了C#中Range.Find方法的典型用法代码示例。如果您正苦于以下问题:C# Range.Find方法的具体用法?C# Range.Find怎么用?C# Range.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Range
的用法示例。
在下文中一共展示了Range.Find方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: return
TryGetNonEmptyRange
(
Range range,
out Range usedRange
)
{
Debug.Assert(range != null);
usedRange = null;
if (range.Rows.Count == 1 && range.Columns.Count == 1)
{
// The code below fails for the single-cell case -- iFirstColumn
// ends up being greater than iLastColumn. Check the cell
// manually.
if (range.get_Value(Missing.Value) == null)
{
return (false);
}
usedRange = range;
return (true);
}
const String WildCard = "*";
Range oFirstRow = range.Find(WildCard,
range.Cells[range.Rows.Count, 1], XlFindLookIn.xlValues,
XlLookAt.xlPart, XlSearchOrder.xlByRows,
XlSearchDirection.xlNext, false, false, Missing.Value);
if (oFirstRow == null)
{
return (false);
}
Range oFirstColumn = range.Find(WildCard,
range.Cells[1, range.Columns.Count], XlFindLookIn.xlValues,
XlLookAt.xlPart, XlSearchOrder.xlByColumns,
XlSearchDirection.xlNext, false, false, Missing.Value);
Range oLastRow = range.Find(WildCard,
range.Cells[1, 1], XlFindLookIn.xlValues,
XlLookAt.xlPart, XlSearchOrder.xlByRows,
XlSearchDirection.xlPrevious, false, false, Missing.Value);
Range oLastColumn = range.Find(WildCard,
range.Cells[1, 1], XlFindLookIn.xlValues,
XlLookAt.xlPart, XlSearchOrder.xlByColumns,
XlSearchDirection.xlPrevious, false, false, Missing.Value);
Debug.Assert(oFirstColumn != null);
Debug.Assert(oLastRow != null);
Debug.Assert(oLastColumn != null);
Int32 iFirstRow = oFirstRow.Row;
Int32 iFirstColumn = oFirstColumn.Column;
Int32 iLastRow = oLastRow.Row;
Int32 iLastColumn = oLastColumn.Column;
Worksheet oWorksheet = range.Worksheet;
usedRange = (Range)oWorksheet.get_Range(
(Range)oWorksheet.Cells[iFirstRow, iFirstColumn],
(Range)oWorksheet.Cells[iLastRow, iLastColumn]
);
return (true);
}
示例2: AssertValid
GetColumn1HeaderCellForStackedTable
(
Microsoft.Office.Interop.Excel.Worksheet oWorksheet,
Range oColumnARange
)
{
Debug.Assert(oWorksheet != null);
Debug.Assert(oColumnARange != null);
AssertValid();
// The worksheet can contain multiple stacked tables, so we need to
// find where to put the new table. Find the first empty cell in
// column A. If it's not the worksheet's first cell, move three
// columns down to provide a two-line buffer between tables.
Range oColumn1HeaderCell = oColumnARange.Find("*", Missing.Value,
XlFindLookIn.xlValues, XlLookAt.xlWhole, XlSearchOrder.xlByRows,
XlSearchDirection.xlPrevious, true, true, Missing.Value);
if (oColumn1HeaderCell == null)
{
oColumn1HeaderCell = ExcelUtil.GetRange(oWorksheet, "A1");
}
else
{
ExcelUtil.OffsetRange(ref oColumn1HeaderCell, 3, 0);
}
return (oColumn1HeaderCell);
}
示例3: FillBackGroundColor
/// <summary>
/// This method fills the background color of a particular range depending
/// on the content within the range.
/// </summary>
/// <param name="currentRange">Range whose background color has to be filled.</param>
private void FillBackGroundColor(Range currentRange)
{
this.ScreenUpdate(false);
if (currentRange.FormatConditions.Count > 0)
{
currentRange.FormatConditions.Delete();
}
foreach (var color in this.colorMap)
{
if (color.Value == null) // skip if no color specified
{
continue;
}
if (color.Value.A == 0) // skip if transparent
{
continue;
}
Range keyExists = currentRange.Find(
new string(new[] { (char)color.Key }),
Missing.Value,
Missing.Value,
XlLookAt.xlWhole,
Missing.Value,
XlSearchDirection.xlNext,
false,
Missing.Value,
Missing.Value);
if (null != keyExists)
{
var cond =
(FormatCondition)
currentRange.FormatConditions.Add(
XlFormatConditionType.xlCellValue,
XlFormatConditionOperator.xlEqual,
new string(new[] { (char)color.Key }),
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value);
cond.Interior.Color = ColorTranslator.ToWin32(color.Value);
}
}
this.ScreenUpdate(true);
}