Excel cell copy pest in asp.net textbox after save issue in textbox value in show html code pls suggest me RRS feed

  • Question

  • User-1832003983 posted

    dear sir/mam

    This is my asp.net desigenpage 

    <ajaxToolkit:HtmlEditorExtender ID="HtmlEditorExtender1" runat="server" TargetControlID="txtEmail_Message" EnableSanitization="false" ></ajaxToolkit:HtmlEditorExtender>

    <asp:TextBox ID="txtEmail_Message" runat="server" CssClass="auto-style10" TextMode="MultiLine" ValidateRequestMode="Disabled" Width="800" Height="200"></asp:TextBox>


    textbox  value 

    Into Bond BE Description of Goods
    BE No & Date  
    9944238/05.02.19 GUANINE
    9944260/05.02.19 Tetralone
    9974613.07.2.19 ADNINE
    9975677/07.02.19 Diethyl Phosphonate
    9992154/08.02.19 R-propylene Carbonate
    9975480/07.02.19 1,3 Di cyclohexyl
    9992515/8.02.19 N-heptane

    after save database value in

    <table cellspacing="0" style="width:96pt" class=" cke_show_border"><tbody><tr><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap; width:48pt">BE No &amp; Date</td><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap; width:48pt"><br></td></tr><tr><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap">9944238/05.02.19</td><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap">GUANINE</td></tr><tr><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap">9944260/05.02.19</td><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap">Tetralone</td></tr><tr><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap">9974613.07.2.19</td><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap">ADNINE</td></tr><tr><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap">9975677/07.02.19</td><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap">Diethyl Phosphonate</t

    how to resolved issue in asp.net 

    Friday, April 12, 2019 1:40 PM

All replies

  • User-1174608757 posted

    Hi Universal Enterprises,

    According to your code , it seems that you want to save the data of excel table in HtmlEditorExtender in database,however it just saves html code in you database.

    In fact , the table in  HtmlEditorExtender control is saved in a textarea in html  basically , you could  only save the html code in this textarea because program couldn't analyze the content.You should add codes to analyze the table in html which means you should clarify the header the table and the content of the table.So I suggest that you could directly save the excel files in database.You could use SQLBulkcopy. You could write as below,I hope it could help you.

    protected void Upload(object sender, EventArgs e)
        //Upload and save the file
        string excelPath = Server.MapPath("~/Files/") + Path.GetFileName(FileUpload1.PostedFile.FileName);
        string conString = string.Empty;
        string extension = Path.GetExtension(FileUpload1.PostedFile.FileName);
        switch (extension)
            case ".xls": //Excel 97-03
                conString = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
            case ".xlsx": //Excel 07 or higher
                conString = ConfigurationManager.ConnectionStrings["Excel07+ConString"].ConnectionString;
        conString = string.Format(conString, excelPath);
        using (OleDbConnection excel_con = new OleDbConnection(conString))
            string sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["TABLE_NAME"].ToString();
            DataTable dtExcelData = new DataTable();
            //[OPTIONAL]: It is recommended as otherwise the data will be considered as String by default.
            dtExcelData.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
                    new DataColumn("Name", typeof(string)),
                    new DataColumn("Salary",typeof(decimal)) });
            using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + sheet1 + "]", excel_con))
            string consString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
            using (SqlConnection con = new SqlConnection(consString))
                using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
                    //Set the database table name
                    sqlBulkCopy.DestinationTableName = "dbo.tblPersons";
                    //[OPTIONAL]: Map the Excel columns with that of the database table
                    sqlBulkCopy.ColumnMappings.Add("Id", "PersonId");
                    sqlBulkCopy.ColumnMappings.Add("Name", "Name");
                    sqlBulkCopy.ColumnMappings.Add("Salary", "Salary");

    Best Regards


    Monday, April 15, 2019 4:53 AM