Hi,
I have a windows form and I want to open a word document from the form and fill some fields in the word documents with the data from the text and date controls on the windows form.
Can anybody help me please, if somebody has an idea, how to do this?
Thanks in advance.
Loading
selva kumarPosted Jun 19, 2013, 9:52 AM
take this reference....
1. using System.Drawing.Printing;
2. using System.Drawing;
3. using System.IO;
4.
5. namespace WindowsApplication1
6. {
7.
8. public partial class Form3 : Form
9. {
10. private System.ComponentModel.Container components;
11. private System.Windows.Forms.Button printButton;
12. private Font printFont;
13. private StreamReader streamToPrint;
14. PrintDocument printDocument1 = new PrintDocument();
15.
16.
17. public Form3()
18. {
19. InitializeComponent();
20.
21. printDocument1.PrintPage += printDocument1_PrintPage;
22. }
23.
24. private void printButton_Click(object sender, EventArgs e)
25. {
26. using (PrintDialog pd = new PrintDialog())
27. {
28. if (pd.ShowDialog() == DialogResult.OK)
29. printDocument1.PrinterSettings = pd.PrinterSettings;
30. printDocument1.Print();
31. }
32.
33.
34. void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
35. {
36. Font objFont=new Font ("Microsoft Sans Serif", 10F);//sets the font type and size
37. float fTopMargin = e.MarginBounds.Top;
38. float fLeftMargin = 50;//sets left margin
39. float fRightMargin = e.MarginBounds.Right - 150;//sets right margin
40.string employee_id = String.Concat("EMPLOYEE ID:- ", comboBox2.Text);//prints EMPLOYEE ID:- and text in combobox2
41. string employee_name = String.Concat("EMPLOYEE NAME:- ", textBox8.Text);
42.
43.e.Graphics.DrawString(employee_id, objFont, Brushes.Black, fLeftMargin, fTopMargin);
44.
45. fTopMargin += objFont.GetHeight() * 2;//skip two lines
46.
47. e.Graphics.DrawString(employee_name, objFont, Brushes.Black, fLeftMargin, fTopMargin);
48.
49. objFont.Dispose();
50.
51. e.HasMorePages = false;
52. }
selva kumarPosted Jun 27, 2013, 5:40 AM
NelPosted Jun 26, 2013, 2:27 AM