日期:2014-05-16  浏览次数:20858 次

dataGridView导入Excel的时候怎么把表格的前4行和后4行去掉
 /// <summary>
        /// 导入Excel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
         string abc = "";
        string houzhui = "";
        private void button1_Click(object sender, EventArgs e)
        {
            string filepath = "";
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if ((ofd.OpenFile()) != null)
                {
                    filepath = ofd.FileName;

                    abc = filepath.Substring(filepath.LastIndexOf("\\") + 1, filepath.Substring(filepath.LastIndexOf("\\") + 1).Length - 4);
                    houzhui = filepath.Substring(filepath.LastIndexOf(".") + 1);

                    if (houzhui.ToUpper() != "XLS")
                    {
                        MessageBox.Show("文件必须为EXCEL表格。");
                        return;
                    }
                }
            }
            try
            {
                string strCon = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + filepath + "; Extended Properties=Excel 12.0";
                OleDbConnection myConn = new OleDbConnection(strCon);

                myConn.Open();
               &nbs