取得excel有效信息

          //0/加入using Excel; 

          string strFileName = "test.xls";
            //1、判斷file this.Server.MapPath(strFileName)存在
            //2、取信息
            object missing = System.Reflection.Missing.Value;

            ApplicationClass appc = new ApplicationClass();//lauch excel application

            if (appc != null)
            {
                //open excel file
                if (appc.Application.Workbooks != null)
                {
                    Workbook wb = appc.Application.Workbooks.Open(this.Server.MapPath(strFileName), missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);

                    int srow = 2;
                    int erow = ws.UsedRange.Rows.Count;
                    int scolumn = 1;
                    int ecolumn = ws.UsedRange.Columns.Count;
                    for (int irow = srow; irow <= erow; irow++)
                    {
                        strValue += "Row" + (irow-1);
                        for (int icolu = scolumn; icolu <= ecolumn; icolu++)
                        {
                            strValue += " Cell" + icolu + ":" + ((Range)ws.Cells.get_Item(irow, icolu)).Value2.ToString();
                        }
                        strValue += "<br/>";
                    }
                    this.Response.Write(strValue);
                }

            }
            appc.Quit();

            appc = null;

posted on 2008-08-23 13:06  freeliver54  阅读(374)  评论(0编辑  收藏  举报

导航