无需打开excel文件c#.net即可读取数据 [英] Read data without opening excel file c# .net

查看:185
本文介绍了无需打开excel文件c#.net即可读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个软件,其中数据存储在excel数据库列中的是Product_ID&描述。我已经包含了基于Product_ID显示结果的搜索功能。但问题是,当excel文件打开但我想在不打开excel文件的情况下读取数据时,它只检索/读取/搜索数据?有没有办法做到这一点????我的代码用于搜索 - :



I've a software in which data is stored in excel database columns are Product_ID & Description. I've included searching feature which displays result based on Product_ID. But the problem is it only retrieves/read/search data when that excel file is open but i want to read data without opening excel file ? Is there any way to do this ???? My code is for searching -:

public Form3()
  {
      InitializeComponent();
  }

  private void button1_Click(object sender, EventArgs e)
  {
      srch();
  }

  private void srch()
  {
      DataTable sheetData = new DataTable();
      string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= 'c:\\Product Details.xlsx';Extended Properties='Excel 8.0;HDR=Yes;'";
      string query = "select * from [Sheet1$]" ;

      DataSet excelDataSet = new DataSet();
      OleDbDataAdapter da = new OleDbDataAdapter(query, strConn);
      da.Fill(excelDataSet);
      dataGridView1.DataSource = excelDataSet.Tables[0];
      DataView dv = ((DataTable)dataGridView1.DataSource).DefaultView;
      DataView dv_filter = new DataView();
      dv_filter.Table = excelDataSet.Tables[0];
      dv_filter.RowFilter = "Product_ID = '" + textBox1.Text + "'";
      dataGridView1.DataSource = dv_filter;

  }

推荐答案

;

DataSet excelDataSet = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(query,strConn );
da.Fill(excelDataSet);
dataGridView1.DataSource = excelDataSet.Tables [ 0 ];
DataView dv =( (DataTable)dataGridView1.DataSource).DefaultView;
DataView dv_filter = new DataView();
dv_filter.Table = excelDataSet.Tables [ 0 ];
dv_filter.RowFilter = Product_ID = ' + textBox1.Text + ';
dataGridView1.DataSource = dv_filter;

}
" ; DataSet excelDataSet = new DataSet(); OleDbDataAdapter da = new OleDbDataAdapter(query, strConn); da.Fill(excelDataSet); dataGridView1.DataSource = excelDataSet.Tables[0]; DataView dv = ((DataTable)dataGridView1.DataSource).DefaultView; DataView dv_filter = new DataView(); dv_filter.Table = excelDataSet.Tables[0]; dv_filter.RowFilter = "Product_ID = '" + textBox1.Text + "'"; dataGridView1.DataSource = dv_filter; }


您好b $ b

查看此lin k



Excel c#.net在不在后台打开Excel的情况下检索数据 [ ^ ]



希望你能得到想法
Hi
Check this link

Excel c#.net retrieving data without opening excel in the background[^]

hope u will get idea


这篇关于无需打开excel文件c#.net即可读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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