数据导入与导出

导入:

protected void btninsert_Click(object sender, EventArgse)

        {

string err = "";

            if(!FileUpload1.HasFile)

                err += "请选择上传文件。";

            elseif (!FileUpload1.FileName.EndsWith(".xls"))

                err += "请上传Execl文件。";

            if(txtname.Text.Trim() == "")

                err += "请填写工作表名。";

 

            if(err != "")

            {

                Utility.MessageBox.ShowAlert(this,err);

                return;

            }

 

            stringfileName = FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf("/") + 1);

            stringpath = Path.Combine(Server.MapPath(TEMP_PATH),

                string.Format("{0}_{1}",DateTime.Now.Ticks, fileName));

           FileUpload1.SaveAs(path);

 

            DataSetds = Utility.ExcelHelper.ReaderExcel(path,txtname.Text.Trim());

            if(ds == null)

            {

                Utility.MessageBox.ShowAlert(this,"数据表读取失败。");

                return;

            }

 

            exlgridview.DataSource =ds;

            exlgridview.DataBind();

 

            if(exlgridview.Columns.Count < 22)

            {

                Utility.MessageBox.ShowAlert(this,"导入失败,数据表列缺失。");

                return;

            }

            phResult.Visible = true;

 

            stringerror = "";

            intrcount = exlgridview.Rows.Count;

            for(int i = 0; i < rcount; i++)

            {

                DBAccess.Model.MassageOrg org = null;

                string msg = "";

                string mes = "";

 

 

 

                string name =exlgridview.Rows[i].Cells[0].Text.Trim();

                if (name != " ")

                {

                    org =orgbll.GetModelByName(name);

                    if (org == null)

                        org = new DBAccess.Model.MassageOrg();

                    org.Name = name;

                }

                else

                {

                    msg += "单位名称:不能为空!";

                }

。。

。。

。。

if (org.ID > 0)

                    {

                       orgbll.Update(org);

                        error += "第" + (i + 2) + "行:" + name + ",导入成功更新!" + mes + System.Environment.NewLine;

                    }

                    else

                    {

                       orgbll.Add(org);

                        error += "第" + (i + 2) + "行:" + name + ",导入成功添加!" + mes + System.Environment.NewLine;

                    }

}


 

 

导出:

 

    

  Utility.ExcelHelper.GridView2Excel(reportview,"名称", "GB2312");


 

 

 

报错:必须放在runat=”server”的标记下

 

public override void VerifyRenderingInServerForm(Control control)

        {

 

        }



你可能感兴趣的:(数据导入与导出)