display data from database in ms.word?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ganesh22
    Banned
    New Member
    • Sep 2007
    • 81

    display data from database in ms.word?

    Hi,
    my requriment is i want to display data from database in ms.word? Iam using asp.net with C#
    bcoz iam inserting resume in sqlserver, so i want to display that resume in word
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Originally posted by ganesh22
    Hi,
    my requriment is i want to display data from database in ms.word? Iam using asp.net with C#
    bcoz iam inserting resume in sqlserver, so i want to display that resume in word
    This is a fun one. You need to add a reference to Microsoft.Offic e.Interop.Word. You can do this by clicking Website-->Add Reference from the menu bar. Make sure you are on the .NET tab and scroll to find Microsoft.Offic e.Interop.Word and click ok.

    This should tell you more, but here's a quick start:
    Code:
    //c# code
    object filename = @"c:\temp.doc";
    FileStream fs = new FileStream((string)filename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
    fs.Close();
    object missing = System.Reflection.Missing.Value;
    Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
    Microsoft.Office.Interop.Word.Document doc = null;
    DateTime today = DateTime.Now;
    object readOnly = false;
    object isVisible = false;
    doc = wordApp.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
    doc.Activate();
    doc.Content.InsertAfter("Text");
    doc.Save();
    wordApp.Visible = true;
    Line 13 is where the writing to the document happens. So, if you have already gotten all your data from the database, here is where you can write it.
    Have fun.

    Comment

    Working...