Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to generate Report in MS Word

How to generate Report in MS Word

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-netsql-serverwpf
12 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jay_se

    Hi, I am using asp.net 2.0 and working with creating reports. I have shown the Output (Report) in the web page using several GridView, Details view, etc. by binding with the database Sql Server. I wish to SAVE the entire (report) page, how I am seeing the page actually in the page, as MS WORD (.doc) format. Because I wish to send this file as a attachment to the client. Anyone can give me the clue for this? Thanks.

    Regards, Jay

    P Offline
    P Offline
    praveenanand
    wrote on last edited by
    #2

    hi use the code given below this will be usefull protected void word_Click(object sender, EventArgs e) { //string attachment = "attachment; filename=f.xls"; SqlDataAdapter da = new SqlDataAdapter("select * from empdata", cn); DataSet dsExport = new DataSet(); da.Fill(dsExport); System.IO.StringWriter tw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw); DataGrid dgGrid = new DataGrid(); dgGrid.DataSource = dsExport; // //Report Header hw.WriteLine("" + "Report for the Employee Information: " + ""); //hw.WriteLine("
    "); //// Response.AddHeader("emp info", attachment); // // Get the HTML for the control. dgGrid.HeaderStyle.Font.Bold = true; dgGrid.DataBind(); dgGrid.RenderControl(hw); // // Write the HTML back to the browser. Response.ContentType = "application/msword"; this.EnableViewState = false; Response.Write(tw.ToString()); Response.End(); }

    1 Reply Last reply
    0
    • J Jay_se

      Hi, I am using asp.net 2.0 and working with creating reports. I have shown the Output (Report) in the web page using several GridView, Details view, etc. by binding with the database Sql Server. I wish to SAVE the entire (report) page, how I am seeing the page actually in the page, as MS WORD (.doc) format. Because I wish to send this file as a attachment to the client. Anyone can give me the clue for this? Thanks.

      Regards, Jay

      P Offline
      P Offline
      praveenanand
      wrote on last edited by
      #3

      let me know the given really helps u or not? don't forget to reply

      J 1 Reply Last reply
      0
      • P praveenanand

        let me know the given really helps u or not? don't forget to reply

        J Offline
        J Offline
        Jay_se
        wrote on last edited by
        #4

        Hi, I hope, what you have given is correct. Can you please explain me or refer a article for this to understand. Because I am very new to this. Please help me. Thanks

        Regards, Jay

        P 1 Reply Last reply
        0
        • J Jay_se

          Hi, I hope, what you have given is correct. Can you please explain me or refer a article for this to understand. Because I am very new to this. Please help me. Thanks

          Regards, Jay

          P Offline
          P Offline
          praveenanand
          wrote on last edited by
          #5

          hi jay first u show me the coding u have done

          J 1 Reply Last reply
          0
          • P praveenanand

            hi jay first u show me the coding u have done

            J Offline
            J Offline
            Jay_se
            wrote on last edited by
            #6

            Hi, I dont know, where to start with. Because, 1. I neeed to create aroud 10 Table format information, which may be created in 6 web pages (aspx) NOT A SINGLE Web page. If I combine everything in one page, the page length is too long. 2. I wish to combine the all the page's output and WRITE in a single WORD file. 3. The WORD file has contains some output fron WebPage and also some Sataic contents like NOTE,Company address, etc. 4. what is word_Click in your code?? Whether after clicking the button, then only the web page is displayed and word file is wrote?

            Regards, Jay :)

            P 1 Reply Last reply
            0
            • J Jay_se

              Hi, I dont know, where to start with. Because, 1. I neeed to create aroud 10 Table format information, which may be created in 6 web pages (aspx) NOT A SINGLE Web page. If I combine everything in one page, the page length is too long. 2. I wish to combine the all the page's output and WRITE in a single WORD file. 3. The WORD file has contains some output fron WebPage and also some Sataic contents like NOTE,Company address, etc. 4. what is word_Click in your code?? Whether after clicking the button, then only the web page is displayed and word file is wrote?

              Regards, Jay :)

              P Offline
              P Offline
              praveenanand
              wrote on last edited by
              #7

              word_click is just list button_click.......ok here button text&id is word

              J 1 Reply Last reply
              0
              • P praveenanand

                word_click is just list button_click.......ok here button text&id is word

                J Offline
                J Offline
                Jay_se
                wrote on last edited by
                #8

                Hi, I have got the below error in the following line GridView1.RenderControl(hw); Http Exception: Control 'ctl00_ContentPlaceHolder1_GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

                Regards, Jay :)

                P J 2 Replies Last reply
                0
                • J Jay_se

                  Hi, I have got the below error in the following line GridView1.RenderControl(hw); Http Exception: Control 'ctl00_ContentPlaceHolder1_GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

                  Regards, Jay :)

                  P Offline
                  P Offline
                  praveenanand
                  wrote on last edited by
                  #9

                  as an example take a sample grid and populate with data from database and then press button here text and id of button is word protected void word_Click(object sender, EventArgs e) { //string attachment = "attachment; filename=f.xls"; SqlDataAdapter da = new SqlDataAdapter("select * from empdata", cn); DataSet dsExport = new DataSet(); da.Fill(dsExport); System.IO.StringWriter tw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw); //DataGrid dgGrid = new DataGrid(); //dgGrid.DataSource = dsExport; DataGrid1.DataSource = dsExport; // //Report Header hw.WriteLine("" + "Report for the Employee Information: " + ""); //hw.WriteLine("
                  "); //// Response.AddHeader("emp info", attachment); // // Get the HTML for the control. //dgGrid.HeaderStyle.Font.Bold = true; //dgGrid.DataBind(); //dgGrid.RenderControl(hw); DataGrid1.HeaderStyle.Font.Bold = true; DataGrid1.DataBind(); DataGrid1.RenderControl(hw); // // Write the HTML back to the browser. Response.ContentType = "application/msword"; this.EnableViewState = false; Response.Write(tw.ToString()); Response.End(); }

                  P 1 Reply Last reply
                  0
                  • P praveenanand

                    as an example take a sample grid and populate with data from database and then press button here text and id of button is word protected void word_Click(object sender, EventArgs e) { //string attachment = "attachment; filename=f.xls"; SqlDataAdapter da = new SqlDataAdapter("select * from empdata", cn); DataSet dsExport = new DataSet(); da.Fill(dsExport); System.IO.StringWriter tw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw); //DataGrid dgGrid = new DataGrid(); //dgGrid.DataSource = dsExport; DataGrid1.DataSource = dsExport; // //Report Header hw.WriteLine("" + "Report for the Employee Information: " + ""); //hw.WriteLine("
                    "); //// Response.AddHeader("emp info", attachment); // // Get the HTML for the control. //dgGrid.HeaderStyle.Font.Bold = true; //dgGrid.DataBind(); //dgGrid.RenderControl(hw); DataGrid1.HeaderStyle.Font.Bold = true; DataGrid1.DataBind(); DataGrid1.RenderControl(hw); // // Write the HTML back to the browser. Response.ContentType = "application/msword"; this.EnableViewState = false; Response.Write(tw.ToString()); Response.End(); }

                    P Offline
                    P Offline
                    praveenanand
                    wrote on last edited by
                    #10

                    it is working fine for me i tested again ok bye best of luck

                    J 1 Reply Last reply
                    0
                    • P praveenanand

                      it is working fine for me i tested again ok bye best of luck

                      J Offline
                      J Offline
                      Jay_se
                      wrote on last edited by
                      #11

                      Hi, Thanks for your guidance. I am working on this now. Hopefully it works for me also.

                      Regards, Jay :)

                      1 Reply Last reply
                      0
                      • J Jay_se

                        Hi, I have got the below error in the following line GridView1.RenderControl(hw); Http Exception: Control 'ctl00_ContentPlaceHolder1_GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

                        Regards, Jay :)

                        J Offline
                        J Offline
                        Jay_se
                        wrote on last edited by
                        #12

                        Hi, In order to avoid the above said error, I have addded the below code in my code behind. Now it works fine. THANKS public override void VerifyRenderingInServerForm(Control control) { }

                        Regards, Jay :)

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups