System.Type.GetType

来源: 作者:admin 时间:11/12/13 点击:0
protected void Button1_Click(object sender, EventArgs e)
    {
        string excelFilePath = @"D:\jbnt1.xls";
        Excel.Application myExcel = new Excel.ApplicationClass();
        object oMissing = System.Reflection.Missing.Value;
        myExcel.Application.Workbooks.Open(excelFilePath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
        Excel.Workbook myBook = myExcel.Workbooks[1];
        Excel.Worksheet mySheet = (Excel.Worksheet)myBook.Worksheets[1];
        System.Data.DataTable dt = new System.Data.DataTable("mytable");
        dt.Columns.Add("F1", System.Type.GetType("System.String"));
        dt.Columns.Add("F2", System.Type.GetType("System.String"));
        dt.Columns.Add("F3", System.Type.GetType("System.String"));
        dt.Columns.Add("F4", System.Type.GetType("System.String"));
        dt.Columns.Add("F5", System.Type.GetType("System.String"));
        DataSet myDs = new DataSet();
        myDs.Tables.Add(dt);
        DataRow myRow;
        myDs.Clear();
        for (int i = 2; i <= 9; i++) //第一行动题目,不读取
        {
            myRow = myDs.Tables["mytable"].NewRow();
            for (int j = 1; j <= 5; j++)
            {
                Excel.Range r = (Excel.Range)mySheet.Cells ;
                string strValue = r.Text.ToString();
                string aa = strValue;
                string columnname = "F" + j.ToString();
                myRow[columnname] = strValue;
            }
            myDs.Tables["mytable"].Rows.Add(myRow);
        }
        GridView1.DataSource = myDs.Tables["mytable"].DefaultView;
        GridView1.DataBind();
    }