Excel.Range.Find方法 [英] Excel.Range.Find method

查看:633
本文介绍了Excel.Range.Find方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Excel互操作对象,并尝试通过以下方法在指定范围内查找日期

I am using Excel interop object and trying to find a date in a specified range by below method

Excel.Range rngFind = WS.get_Range(strFromRange, strToRange).Find(strFind, Type.Missing,
                Excel.XlFindLookIn.xlFormulas, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows,
                Excel.XlSearchDirection.xlNext, false, false, false);

但是我总是将rngFind设置为null我的strFind ="Sep-08"我尝试同时使用Excel.XlFindLookIn.xlFormulas和Excel.XlFindLookIn.xlValues

but i get rngFind as null always my strFind = "Sep-08" i tried with both Excel.XlFindLookIn.xlFormulas and Excel.XlFindLookIn.xlValues

我的excel文件看起来像这样

my excel file looks like this

Sep-08  Oct-08  Nov-08  Dec-08  Jan-09  Feb-09  Mar-09  Apr-09  May-09  Jun-09  Jul-09

当我单击Sep-08单元格时,我在Excel的公式字段中得到9/1/2008 我也尝试过搜索2008年9月1日,但是根据RegionalSettings Date格式,它会因系统而异...

where as wheni click on Sep-08 cell i get 9/1/2008 in the formula field in Excel i have also tried searching for 9/1/2008 but it varies system by system as per the RegionalSettings Date format...

请帮助我.基本上我是在获取查找字符串的单元格地址

Please help me. basically i am doing to get the cell address of the finding string

推荐答案

使用Office 2007,Interop是直接从Visual Studio生成的.我使用以下代码查找有问题的单元格:

Using Office 2007, Interop generated directly from Visual Studio. I used the following code to find the cell in question:

using System.Reflection;
using Microsoft.Office.Interop.Excel;

object False = false;
object True = true;

_Application excel = new Microsoft.Office.Interop.Excel.ApplicationClass();

Workbook wb = excel.Workbooks._Open(@"C:\tmp\StackOverflow.xlsx",False, False,Missing.Value,Missing.Value,False,False,Missing.Value,Missing.Value,False,Missing.Value,Missing.Value,True);

_Worksheet ws = (_Worksheet)wb.Worksheets[1];

string from = "A1";
string to = "B1";

Range rng = ws.get_Range(from,to);

Range findRng = rng.Find("Sep-08",Missing.Value,XlFindLookIn.xlValues,Missing.Value,Missing.Value,XlSearchDirection.xlNext,False,False,Missing.Value);

您可以在如何使用Visual Studio使Excel自动化中找到Microsoft示例. C#使用数组填充或获取范围内的数据.

这篇关于Excel.Range.Find方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆