By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,741 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,741 IT Pros & Developers. It's quick & easy.

display data from database in ms.word?

P: 81
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
Apr 15 '08 #1
Share this Question
Share on Google+
1 Reply


Curtis Rutland
Expert 2.5K+
P: 3,256
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:
Expand|Select|Wrap|Line Numbers
  1. //c# code
  2. object filename = @"c:\temp.doc";
  3. FileStream fs = new FileStream((string)filename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
  4. fs.Close();
  5. object missing = System.Reflection.Missing.Value;
  6. Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
  7. Microsoft.Office.Interop.Word.Document doc = null;
  8. DateTime today = DateTime.Now;
  9. object readOnly = false;
  10. object isVisible = false;
  11. 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);
  12. doc.Activate();
  13. doc.Content.InsertAfter("Text");
  14. doc.Save();
  15. wordApp.Visible = true;
  16.  
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.
Apr 15 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.