当前位置:编程学习 > C#/ASP.NET >>

ASP.NET导出数据到Excel并输出

asp教程.net导出数据到excel并输出
public void import()

    {
        if (this.ddl_task.selectedvalue == "-1")
        {
            function.script.alert("请选择主题!");
            return;
        }
        string savepath = server.mappath("sql\");
     
       if(fileup1.hasfile)
       {
        excelengine excelengine = new excelengine();
        iapplication application = excelengine.excel;
        savepath += fileup1.filename;
        fileup1.saveas(savepath);
        iworkbook workbook = excelengine.excel.workbooks.open(savepath);
        iworksheet sheet1 = workbook.worksheets[0];
        for (int i = 0; i < sheet1.rows.length-1; i++)
        {

            if (!ifexistinblacklist(sheet1.range["e" + convert.tostring((i + 2))].value2.tostring(), sheet1.range["f" + convert.tostring((i + 2))].value2.tostring() ))
            {
                using (oracleconnection connection = new oracleconnection(configurationmanager.connectionstrings["dvteconnectionstring"].tostring()))
                {
                    string sql = " insert into dc_visituser(customerid,cust_name,cust_addr,addrcode,mobilephone,homephone,taskid)";
                    sql += " values('" + sheet1.range["a" + convert.tostring((i + 2))].value2 + "'";
                    sql += ",'" + sheet1.range["b" + convert.tostring((i + 2))].value2 + "'";
                    sql += ",'" + sheet1.range["c" + convert.tostring((i + 2))].value2 + "'";
                    sql += ",'" + sheet1.range["d" + convert.tostring((i + 2))].value2 + "'";
                    sql += ",'" + sheet1.range["e" + convert.tostring((i + 2))].value2 + "'";
                    sql += ",'" + sheet1.range["f" + convert.tostring((i + 2))].value2 + "'";
                    sql += "," + this.ddl_task.selectedvalue;
                    sql += ")";
                    oraclecommand command = new oraclecommand(sql, connection);
                    connection.open();
                    command.executenonquery();

                }
            }
        }

            excelengine.thrownotsavedondestroy = false;
        excelengine.dispose();
        this.bindgridview();
       }
   
    }

 

补充:asp.net教程,.Net开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,