locked
Datatable To Ms word RRS feed

  • Question

  • User-1562835235 posted

      i hav a datatable.datatable contain Name,FirstName,LastName,Address,Phone No of a person..i hav form made in Ms word document contain all fields liki table(it just like a form).i want fill data table value in word document form then take print out of that word document(not want to save)

    plz reply

    Wednesday, November 11, 2009 3:39 AM

All replies

  • User-1252206308 posted

    protected void ibtnExport_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
    DataTable dtMail = new DataTable();
    dtMail = dtMail;//Assuming that datatable is there

    StringBuilder sbContent = new StringBuilder();

    for (int i = 0; i <= dtMail.Rows.Count - 1; i++)
    {

    for (int j = 0; j <= dtMail.Columns.Count - 1; j++)
    {

    sbContent .Append(" " + dtMail.Rows[i][j].ToString()+ " ");

    }

    sbContent .Append("\n");
    }

    Response.Clear();
    Response.AddHeader("content-disposition", "attachment;filename=FileName.doc");

    Response.Charset = "";

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    Response.ContentType = "application/vnd.word";
    Response.Write(sbContent .ToString());

    Response.End();

    }


    Hope this helps.

    Wednesday, November 11, 2009 7:26 AM
  • User-1562835235 posted

    hello...

    firstly i will fill data in .net aspx page from sql table

    then i want to fill  that aspx page data into existing microsft word document and print

    when user  click on print button that is on .net aspx page then automatically data insert into existng microsoft word document(this document have f same design like aspx page)  and print

    Thursday, November 12, 2009 3:20 AM
  • User-319574463 posted

    There is a Mime type that allows an aspx page with a GridView to be made into an OLE excel spread sheet.  Possibly there is a Word equivalent.

    Thursday, November 12, 2009 5:06 AM
  • User-1562835235 posted

    visit this link http://blogs.techrepublic.com.com/howdoi/?p=190 

    all the best

    Monday, November 16, 2009 1:42 AM