Ejemplo n.º 1
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string fileName = GeneralUtility.GetExcelFile(xlsxSchol);


            if (!String.IsNullOrEmpty(fileName))
            {
                var       ExcelResult = ExcelPlus.ReadExcel(fileName, 2);
                DataTable dt          = new DataTable();
                dt.Columns.Add("ID");
                dt.Columns.Add("Firstname");
                dt.Columns.Add("Lastname");
                dt.Columns.Add("Othername");
                dt.Columns.Add("Address");
                dt.Columns.Add("Origin");
                dt.Columns.Add("LGA");
                dt.Columns.Add("DOB");
                dt.Columns.Add("Sex");
                dt.Columns.Add("GName");
                dt.Columns.Add("GAddress");
                dt.Columns.Add("GPhone");
                dt.Columns.Add("GEmail");
                dt.Columns.Add("Relation");

                for (int i = 0; i < ExcelResult.Tables[0].Rows.Count; i++)
                {
                    // string STUDENT_ID = Convert.ToString(ExcelResult.Tables[0].Rows[i][1]);
                    string ID        = Convert.ToString(ExcelResult.Tables[0].Rows[i][0]);
                    string Name      = Convert.ToString(ExcelResult.Tables[0].Rows[i][1]);
                    string Lastname  = Convert.ToString(ExcelResult.Tables[0].Rows[i][2]);
                    string Othername = Convert.ToString(ExcelResult.Tables[0].Rows[i][4]);
                    string Address   = Convert.ToString(ExcelResult.Tables[0].Rows[i][5]);
                    string Origin    = Convert.ToString(ExcelResult.Tables[0].Rows[i][3]);
                    string LGA       = Convert.ToString(ExcelResult.Tables[0].Rows[i][6]);
                    string DOB       = Convert.ToString(ExcelResult.Tables[0].Rows[i][7]);
                    string Sex       = Convert.ToString(ExcelResult.Tables[0].Rows[i][8]);
                    string GName     = Convert.ToString(ExcelResult.Tables[0].Rows[i][9]);
                    string GAddress  = Convert.ToString(ExcelResult.Tables[0].Rows[i][10]);
                    string GPhone    = Convert.ToString(ExcelResult.Tables[0].Rows[i][11]);
                    string GEmail    = Convert.ToString(ExcelResult.Tables[0].Rows[i][12]);
                    string Relation  = Convert.ToString(ExcelResult.Tables[0].Rows[i][13]);

                    dt.Rows.Add(ID, Name, Lastname, Othername, Address, Origin, LGA, DOB, Sex, GName, GAddress, GPhone, Relation);
                }

                gvResult.DataSource = dt;
                gvResult.DataBind();
                excelDiv.Visible = true;
                gvResult.HeaderRow.TableSection = TableRowSection.TableHeader;
            }
            else
            {
            }
        }
Ejemplo n.º 2
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            //HttpPostedFileBase file = xlsxSchol.PostedFile.
            var fileName = GeneralUtility.GetExcelFile(xlsxSchol);

            if (!String.IsNullOrEmpty(fileName))
            {
                var       ExcelResult = ExcelPlus.ReadExcel(fileName, 2);
                DataTable dt          = new DataTable();
                dt.Columns.Add("ID");
                dt.Columns.Add("Name");
                dt.Columns.Add("Address");
                dt.Columns.Add("Email");
                dt.Columns.Add("MobileNo");
                dt.Columns.Add("LGA");
                dt.Columns.Add("Type");
                dt.Columns.Add("Category");
                dt.Columns.Add("DateOfInCorporation");
                dt.Columns.Add("PrincipalName");

                for (int i = 0; i < ExcelResult.Tables[0].Rows.Count; i++)
                {
                    // string STUDENT_ID = Convert.ToString(ExcelResult.Tables[0].Rows[i][1]);
                    string ID                  = Convert.ToString(ExcelResult.Tables[0].Rows[i][0]);
                    string Name                = Convert.ToString(ExcelResult.Tables[0].Rows[i][1]);
                    string Address             = Convert.ToString(ExcelResult.Tables[0].Rows[i][2]);
                    string Email               = Convert.ToString(ExcelResult.Tables[0].Rows[i][4]);
                    string MobileNo            = Convert.ToString(ExcelResult.Tables[0].Rows[i][5]);
                    string LGA                 = Convert.ToString(ExcelResult.Tables[0].Rows[i][3]);
                    string Type                = Convert.ToString(ExcelResult.Tables[0].Rows[i][6]);
                    string category            = Convert.ToString(ExcelResult.Tables[0].Rows[i][7]);
                    string DateOfInCorporation = Convert.ToString(ExcelResult.Tables[0].Rows[i][8]);
                    string PrincipalName       = Convert.ToString(ExcelResult.Tables[0].Rows[i][9]);


                    dt.Rows.Add(ID, Name, Address, Email, MobileNo, LGA, Type, category, DateOfInCorporation, PrincipalName);
                }

                gvResult.DataSource = dt;
                gvResult.DataBind();
                excelDiv.Visible = true;
            }
            else
            {
            }
        }