好的,所以这里是独家新闻。我有一个excel表,其中包含存储在我的工作表中C列的客户的报价编号。我有它所以当选择时,程序将从datagridview获取报价编号并在excel中搜索它。这是代码:
public static string pQuoteHolder;
file = Path.Combine(Application.StartupPath, "__Quote_Tracker.xlsm");
Excel.Application xlapp = new Excel.Application();
Excel.Workbook workbook = xlapp.Workbooks.Open(file);
Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Sheets[1];
Excel.Range currentFind = null;
Excel.Range firstFind = null;
Excel.Range range;
Excel.Range clients = xlapp.get_Range("C1", "C500");
pQuoteHolder = Convert.ToString(dataGridView2.CurrentRow.Cells[1].Value);
worksheet = (Excel.Worksheet)workbook.Sheets[1];
currentFind = clients.Find(pQuoteHolder, Type.Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false, Type.Missing, Type.Missing);
if (currentFind == null)
{
MessageBox.Show("Nobody was found.");
}
所以这就是问题,我从调试中看到qQuoteHolder从datagridview获取了正确的值,我可以看到我自己的excel表中的所有引号都在C列和范围内,所以为什么是currentfind返回null?我还在学习excel和c#,我是否设法编写了range.Find方法错误?
提前致谢!