本帖最后由 buqibushe 于 2012-10-16 18:52:12 编辑

解决方案 »

  1.   

    如果是类似数据库的那样的话 只能指点sheet如果不是用的话应该可以吧
      

  2.   

    如果是数据库的话,那不是更加要知道工作薄中工作表的确切名称!我之前用java的时候,有很多好用的开源类可以读到这些信息,难道C#读自己家里的excel的工作表名都不行??多谢了
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Reflection;
    using System.Data.OleDb;namespace ExcelBomTest
    {
        public partial class Form1 : Form
        {
            private object missing = Missing.Value;
            private Microsoft.Office.Interop.Excel._Application ExcelRS;
            private Microsoft.Office.Interop.Excel.Workbook RSbook;
            private Microsoft.Office.Interop.Excel._Worksheet RSsheet;        public Form1()
            {
                InitializeComponent();
            }        private void txtbxInfo_TextChanged(object sender, EventArgs e)
            {        }        public static DataTable ExcelToDataTable(string strExcelFileName, string strSheetName)
            {
                //源的定义
                string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strExcelFileName + ";" + "Extended Properties='Excel 8.0;HDR=NO;IMEX=1';";            //Sql语句
               // string strExcel = string.Format("select * from [{0}$]", strSheetName); //这是一种方法
                string strExcel = "select * from   [sheet1$]";
                //定义存放的数据表
                DataSet ds = new DataSet();            //连接数据源
                OleDbConnection conn = new OleDbConnection(strConn);            conn.Open();            //适配到数据源
                OleDbDataAdapter adapter = new OleDbDataAdapter(strExcel, strConn);
                adapter.Fill(ds, strSheetName);            conn.Close();            return ds.Tables[strSheetName];
            }        private void Form1_Load(object sender, EventArgs e)
            {
                DataTable myT = ExcelToDataTable("C:/test.xls", "sheet1");
                for (int i = 0; i < 10; i++) {
                    for (int j = 0; j < 10; j++)
                    {
                        this.txtbxInfo.Text += myT.Rows[i][j].ToString();
                    }
                }
            }
        }
    }
      

  3.   

    http://blog.csdn.net/jyz123456/article/details/7966871
    看看这个吧
      

  4.   

    //创建Application对象 
    Excel.Application xApp=new Excel.ApplicationClass(); xApp.Visible=true; 
    //得到WorkBook对象, 可以用两种方式之一: 下面的是打开已有的文件 
    Excel.Workbook xBook=xApp.Workbooks._Open(@"D:\Sample.xls", 
    Missing.Value,Missing.Value,Missing.Value,Missing.Value 
    ,Missing.Value,Missing.Value,Missing.Value,Missing.Value 
    ,Missing.Value,Missing.Value,Missing.Value,Missing.Value);               //xBook=xApp.Workbooks.Add(Missing.Value);//新建文件的代码 
    //指定要操作的Sheet,两种方式: Excel.Worksheet xSheet=(Excel.Worksheet)xBook.Sheets[1]; 
    //Excel.Worksheet xSheet=(Excel.Worksheet)xApp.ActiveSheet; //读取数据,通过Range对象 
    Excel.Range rng1=xSheet.get_Range("A1",Type.Missing); 
    Console.WriteLine(rng1.Value2);