在C#.net中读取excel单元格值 [英] read excel cell value in C#.net

查看:101
本文介绍了在C#.net中读取excel单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要在C#.net中读取excel单元格值。喜欢单元格A1或M33等的值。

提前致谢。

Hi All,
I need to read excel cell value in C#.net. like value of cell A1 or M33 etc.
Thanks in advance.

推荐答案

Freind,请使用以下链接:

http://ambeshdevloper.blogspot.com/2012/10/read-values-from-microsoft-excel-in.html#!/2012/10/read-values-from-microsoft-excel -in.html [ ^ ]



谢谢,

Ambesha
Freind, use the following link:
http://ambeshdevloper.blogspot.com/2012/10/read-values-from-microsoft-excel-in.html#!/2012/10/read-values-from-microsoft-excel-in.html[^]

Thanks,
Ambesha


试一试,可能会对你有所帮助......





Try This Out ,May be would help to you...


if (!Page.IsPostBack)
            {
                Excel.Application appExl;
                Excel.Workbook workbook;
                Excel.Worksheet NwSheet;
                Excel.Range ShtRange;
                appExl = new Excel.ApplicationClass();
 

                  //Opening Excel file(myData.xlsx)
                workbook = appExl.Workbooks.Open(Server.MapPath("myData.xlsx"), Missing.Value, Missing.Value,Missing.Value,Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value, Missing.Value);

                NwSheet = (Excel.Worksheet)workbook.Sheets.get_Item(1);
                int Cnum = 0;
                int Rnum = 0;
     
                ShtRange = NwSheet.UsedRange; //gives the used cells in sheet
               
                  //Reading Excel file.
               //Creating datatable to read the containt of the Sheet in File.
                DataTable dt = new DataTable();
                dt.Columns.Add("ID");
                dt.Columns.Add("Name");
                dt.Columns.Add("Status");
                dt.Columns.Add("Contact");

                for (Rnum = 2; Rnum <= ShtRange.Rows.Count; Rnum++)
                {
                    DataRow dr = dt.NewRow();
//Reading Each Column value From sheet to datatable Colunms                  
                    for (Cnum = 1; Cnum <= ShtRange.Columns.Count; Cnum++)
                 {
                       dr[Cnum - 1] = (ShtRange.Cells[Rnum, Cnum] as Excel.Range).Value2.ToString();
                    }
                    dt.Rows.Add(dr); // adding Row into DataTable
                    dt.AcceptChanges();
                }

                workbook.Close(true, Missing.Value, Missing.Value);
                appExl.Quit();

                 gvOne.DataSource = dt;//DataSource to GrigView(Id:gvOne)
                gvOne.DataBind();
      }


Google的权力约5,850,000个结果(0.42秒) [ ^ ]。
The power of Google: About 5,850,000 results (0.42 seconds)[^].


这篇关于在C#.net中读取excel单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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