locked
GRIDVIEW QR CODE EXPORT TO EXCEL QR CODE MISSING RRS feed

  • Question

  • User-807418713 posted

    Hello

    This is my complete 

    aspx code

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="QRAPI.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
          <script src="js/jquery.classyqr.js"></script>
        <script>
            $(function () {
                $('#<%=gvCustomers.ClientID%> tr').filter(':not(:first)').filter(':not(:last)').each(function () {
                    $(this).find("td:nth(0)").ClassyQR({
                        create: true,// signals the library to create the image tag inside the container div.
                        type: 'text',// text/url/sms/email/call/locatithe text to encode in the QR. on/wifi/contact, default is TEXT
                        text: $(this).find("td:nth(1)").html()// the text to encode in the QR.
                    });
                    
                })
            })
        </script>  
     </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button2" runat="server" AccessKey="R" BackColor="#FFFF66" BorderColor="Transparent"
                BorderStyle="Dashed" BorderWidth="1px" Font-Bold="True" Font-Names="Palatino Linotype"
                Font-Size="10pt" ForeColor="Black" Height="60px" OnClick="Button3_Click" Style="background-image: url(images/Excel-2007.png)"
                TabIndex="7" Text="Excel" Width="65px" /><br />
        <asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" CssClass="Grid"
                    ShowFooter="true">
                    <Columns>
                        <asp:BoundField ItemStyle-Width="150px" HeaderText="Order No" />
                        <asp:BoundField ItemStyle-Width="150px" DataField="OrderNo" HeaderText="Order No" Visible="false" />
                        <asp:BoundField ItemStyle-Width="150px" DataField="Item_Name" HeaderText="Item_Name" />
                        <asp:BoundField ItemStyle-Width="150px" DataField="ORder_Quantity" HeaderText="Order Quantity" />
                    </Columns>
                </asp:GridView>
         </div>
        </form>
    </body>
    </html>
    

    C#

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Collections.Specialized;
    using System.Text;
    using System.Drawing;
    using System.IO;
    using System.Net;
    using System.Net.Mail;
    using System.Net.Configuration;
    
    public partial class _Default : System.Web.UI.Page
    {
    
        private DataTable BindGridview()
        {
            DataTable dt = new DataTable();
            SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ChemConnectionString"].ConnectionString);
            con1.Open();
            SqlCommand cmd1 = new SqlCommand("select * from Orders", con1);
            SqlDataAdapter ada1 = new SqlDataAdapter(cmd1);
            ada1.Fill(dt);
            return dt;
            con1.Close();
    
        }
    
    
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable dtz = BindGridview();
                gvCustomers.DataSource = dtz;
                gvCustomers.DataBind();
    
                
    
            }
        }
        protected void gvOrders_RowDataBound(object sender, GridViewRowEventArgs e)
        { 
        }
        public string gridviewData(GridView grid)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            gvCustomers.RenderControl(htw);
    
            return sb.ToString();
        }
    
        protected void ExportToExcel()
        {
    
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=Master Report.xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            using (StringWriter sw = new StringWriter())
            {
                HtmlTextWriter hw = new HtmlTextWriter(sw);
    
                //To Export all pages
                gvCustomers.AllowPaging = false;
                this.BindGridview();
    
    
                gvCustomers.RenderControl(hw);
    
                //style to format numbers to string
                string style = @"<style> .textmode { } </style>";
                Response.Write(style);
                Response.Output.Write(sw.ToString());
                Response.Flush();
                Response.End();
            }
    
    
        }
    
        public override void VerifyRenderingInServerForm(Control control)
        {
            /* Verifies that the control is rendered */
        }
    
    
        protected void Button3_Click(object sender, EventArgs e)
        {
            ExportToExcel();
        }
    }
    

    when I click export to excel button its not showing qr code in excel.. 

    Tuesday, December 15, 2020 6:47 AM

Answers

  • User1535942433 posted

    Hi Gopi.MCA,

    Any code using jquery or javascript.. 

    There's no way to use jquery or javascript to export data to excel. Because these:

    1.There's no plugin for free to export QR code to image.

    2.The  SheetJS plugin affect your effect because when you use jquery to export data to excel from server side,it will reload again.

    So,I suggest you could generate QR code and export QR code and data in the code-behind.And then you could use ajax fetch excel from server side. If you have problems of code-behind,you could post your problems.We are willing to help you.

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 21, 2020 8:14 AM

All replies

  • User1535942433 posted

    Hi Gopi.MCA,

    Accroding to your description,as far as I think,while you use StringWriter  to RenderControl,you don't get the QR code. Beacuse QR code is generated using jquery. So,there are three methods to export QR code to excel:

    1.Export image and gridview with jquery  using  SheetJS. However,it isn't for free.

    2.Pass your QR code image to code-behind using base64. Then you could use  Epplus to insert image to the excel.

    3.I suggest you could use this way.You could generate QR code in the code-behind.And then you could use Epplus.

    More details,you could refer to below articles:

    https://stackoverflow.com/questions/11588704/adding-images-into-excel-using-epplus

    https://forums.asp.net/t/2071710.aspx?Export+Images+From+A+Directory+To+Excel+Using+EPplus

    Best regards,

    Yijing Sun

    Wednesday, December 16, 2020 6:33 AM
  • User-807418713 posted

    Hello

    Any code using jquery or javascript.. 

    Thanking You

    Sunday, December 20, 2020 7:17 PM
  • User1535942433 posted

    Hi Gopi.MCA,

    Any code using jquery or javascript.. 

    There's no way to use jquery or javascript to export data to excel. Because these:

    1.There's no plugin for free to export QR code to image.

    2.The  SheetJS plugin affect your effect because when you use jquery to export data to excel from server side,it will reload again.

    So,I suggest you could generate QR code and export QR code and data in the code-behind.And then you could use ajax fetch excel from server side. If you have problems of code-behind,you could post your problems.We are willing to help you.

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 21, 2020 8:14 AM
  • User-1369959483 posted

    Get dotnet job support and join the dotnet community to read blogs, tutorials, watch videos and interact on forums http://www.dotnet.idn-kxchange.com/forums/recent_topics

    Tuesday, January 5, 2021 6:17 PM