Excel.Range.Find method

烈酒焚心 提交于 2019-11-29 07:54:51

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);

You can find the Microsoft example at How to automate Excel by using Visual C# to fill or to obtain data in a range by using arrays.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!