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.Office.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.Office.Interop.Word and click ok.
This should tell you more, but here's a quick start:
-
//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.