locked
How to copy pest data in excel sheet in textbox asp.net RRS feed

  • Question

  • User-1832003983 posted

    Hi,

    I have try to copy pest data excel sheet to textbox but not supported. how to drow table format in textbox and save in asp.net normal mvc.

    this is my desigen code

    <asp:TextBox ID="txtEmail_Message" CssClass="Contact_Input" Textmode="MultiLine" lines="10" cols="10" runat="server" ></asp:TextBox>
    <textarea name="txtEmail_Message" class="editor" id="txtEmail_Message" cols="80" rows="50" ></textarea>

    asp.net code

    DFD.Massege = txtEmail_Message.Text;

    But Text property not supported.
     

    How to sloved and this type output.

    BUY_4084474376 BUY_1930470977 Dattatray ACMPH5112J
    BUY_4084474376 BUY_1930470977 Dattatray ACMPH5112J
    BUY_4084474376 BUY_1930470977 Dattatray ACMPH5112J
    BUY_4084474376 BUY_1930470977 Dattatray ACMPH5112J
    Tuesday, December 18, 2018 5:12 AM

All replies

  • User646131187 posted

    I think if you are using <asp:____> controls, you are using Web Forms, not MVC.

    If you are using Web Forms, consider using RichTextBox instead of TextBox, or adding an extension like TinyMCE.  I'm not at home right now, so I'm not sure exactly how much of an Excel copied table will work in a RichTextBox, but I'm pretty sure a TextBox is never going to give you anything but text.

    In past experiences, I found I sometimes got nicer results by pasting copied Excel information into Word first, then re-copying the Word table before pasting on my site. 

    Tuesday, December 18, 2018 9:29 AM
  • User-893317190 posted

    Hi Universal Enterprises,

    It seems you want to paste a table into textbox.

    If so , I suggest you could use ckeditor.

    There is a quick start of it , you only need to add a js reference and write little js.

    Below is the code.Please don't forget to add ValidateRequestMode="Disabled"  or you couldn't pass the text to server

    <form id="form1" runat="server">
            <asp:TextBox runat="server" ID="mainTextBox"
                ValidateRequestMode="Disabled"  TextMode="MultiLine"
     ></asp:TextBox>
    
            <script>
    
        ClassicEditor
            .create( document.querySelector( '#mainTextBox' ) )
            .catch( error => {
                console.error( error );
            } );
    </script>
        </form>

    You could get the text as before

      if (IsPostBack)
                {
                   string text  = mainTextBox.Text;
                }

    The result.

    For full feature of ckeditor,you could refer to https://github.com/ckeditor/

    Best regards,

    Ackerly Xu

    Wednesday, December 19, 2018 5:56 AM
  • User-1832003983 posted

    I have try this solution but not working pls. give me another solution

    Friday, December 21, 2018 9:17 AM
  • User-893317190 posted

    Hi Universal Enterprises,

    You could also use ajaxToolkie HtmlEditor.Below is my code.It could extend Textbox. 

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HtmlEditorExe.aspx.cs" Inherits="MyWebFormCases.ExtraControls3.HtmlEditorExe" %>
    
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
                    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <ajaxToolkit:HtmlEditorExtender ID="HtmlEditorExtender1" runat="server" TargetControlID="TextBox1"></ajaxToolkit:HtmlEditorExtender>
            <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Width="300px" Height="400px"></asp:TextBox>
    
        </form>

    If you paste your excel in the textbox ,it may be unaligned, please click  Justify full,but it has no border.

    You should install ajaxtoolkit first.

    https://docs.microsoft.com/en-us/aspnet/web-forms/overview/ajax-control-toolkit/getting-started/get-started-with-the-ajax-control-toolkit-cs

    If it shows error  when you use HtmlEditor.Sanitizer,please try to install Sanitizer using nuget.

    Best regards,

    Ackerly Xu

    Monday, December 24, 2018 1:26 AM
  • User-1832003983 posted

    I have try this but not save to textbox value in sql Server.

    Textbox is null Value.or Empty save in database.

    Monday, December 24, 2018 8:27 AM
  • User-893317190 posted

    Hi Universal Enterprises,

    I'm sorry. The simplest way to solve your problem is to add EnableSanitization="false" to your htmleditorextendor.

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

    For more information about how to configure htmleditorextender , you could refer to https://www.aspsnippets.com/Articles/ASPNet-AJAX-Control-Toolkit-HtmlEditorExtender-Example.aspx 

    https://www.aspsnippets.com/Articles/AJAX-Control-Toolkit-HtmlEditorExtender-Sanitizer-provider-is-not-configured-in-the-WebConfig-file.aspx

    Best  regards,

    Ackerly Xu

    Tuesday, December 25, 2018 1:28 AM
  • User-1832003983 posted

    Hi Sir,

    I have try this solution but actual textbox value not save in database .(Save in table formatted value as per html code ).

    Data save in this type in sql server

    <table border="0" cellpadding="0" cellspacing="0" width="256" style="width: 192pt;"> <colgroup><col width="64" span="4" style="width:48pt"> </colgroup><tbody><tr height="52" style="height:39.0pt"> <td height="52" class="xl63" width="64" style="height:39.0pt;width:48pt">BUY_4084474376</td> <td class="xl63" width="64" style="border-left:none;width:48pt">BUY_1930470977</td> <td class="xl63" width="64" style="border-left:none;width:48pt">Dattatray</td> <td class="xl63" width="64" style="border-left:none;width:48pt">ACMPH5112J</td> </tr> <tr height="52" style="height:39.0pt"> <td height="52" class="xl63" width="64" style="height:39.0pt;border-top:none; width:48pt">BUY_4084474376</td> <td class="xl63" width="64" style="border-top:none;border-left:none;width:48pt">BUY_1930470977</td> <td class="xl63" width="64" style="border-top:none;border-left:none;width:48pt">Dattatray</td> <td class="xl63" width="64" style="border-top:none;border-left:none;width:48pt">AC

    Thursday, December 27, 2018 5:57 AM
  • User-893317190 posted

    Hi Universal Enterprises,

    This is what HtmlEdior does,it save the html data of the table in sqlserver.

    If you want to get the data of it , I suggest you could upload the excel file and use excel library to read data from it and then save into database

    https://www.aspsnippets.com/Articles/Read-Excel-file-using-OLEDB-Data-Provider-in-C-Net.aspx

    If you meet Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine, you could refer to 

    https://www.codeproject.com/Questions/464072/The-Microsoft-Jet-OLEDB-provider-is-not-regist

    Or just use xslx to upload. 

    Best regards,

    Ackerly Xu
     

    Thursday, December 27, 2018 6:57 AM
  • User-1832003983 posted

    Dear 

    I Have use your Solution but stored in value in database.

    database in sql server 2012 using Stored producer.

    Input in TextBox

    3 BUY_4587009075 KALPANA 1
    4 BUY_2487792999 SHAILAJA 1

    And 

    Output in Database

    <table cellspacing="0" style="width:192pt" class=" cke_show_border"><tbody><tr><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap; width:48pt">3</td><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap; width:48pt">BUY_4587009075</td><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap; width:48pt">KALPANA</td><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap; width:48pt">1</td></tr><tr><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap">4</td><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap">BUY_2487792999</td><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap">SHAILAJA</td><td style="height:15.0pt; vertical-align:bottom; white-space:nowrap">1</td></tr></tbody></table>

    Monday, March 11, 2019 12:03 PM
  • User-893317190 posted

    Hi Universal Enterprises,

    This is what this kind of control does , if you want to save data in a table , please refer to the link I provided above Read-Excel-file-using-OLEDB-Data-Provider-in-C-Net.

    When you get a datatable, you could consider using Sqlbulcopy to insert into database.

    https://programmingwithmosh.com/csharp/using-sqlbulkcopy-for-fast-inserts/

    Best regards,

    Ackerly Xu

    Tuesday, March 12, 2019 1:06 AM