从Excel检索值 [英] Retrieve value from Excel

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

问题描述

我想制作一个应用程序,该应用程序将首先搜索用户提到的值:
1.如果在指定的列中找到了用户提到的值,则检索同一行的值并显示它
2.如果未找到提及的值,则应显示未找到值的消息.

如何使用C#在指定的列中查找值并从Excel工作表中检索特定行的值?

I want to make an application which will first search the value mentioned by user:
1. if the value mentioned by user is found in specified column then retrieve the values of the same row and show it
2. if value mentioned is not found then message should be displayed that value is not found.

How to find the value in a specified column and retrieve values of particular row from an Excel Sheet using C#?

推荐答案

只需尝试如下操作:

Simply try something like this:

this.openFileDialog1.FileName = "*.xls";
  if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
   {
      Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(
         openFileDialog1.FileName, 0, true, 5,
          "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false,
          0, true); 
     Excel.Sheets sheets = theWorkbook.Worksheets;
     Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1);
     for (int i = 1; i <= 10; i++)
     {
     Excel.Range range = worksheet.get_Range("A"+i.ToString(), "J" + i.ToString());
     System.Array myvalues = (System.Array)range.Cells.Value;
     string[] strArray = ConvertToStringArray(myvalues);
     }
}



您只需调整代码即可获得所需的范围.

祝你好运!



You could simply adjust the code to get the range you need.

Good luck!


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

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