Guest User

Untitled

a guest
May 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.71 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Runtime.InteropServices;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Globalization;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. using System.Reflection;
  13. using System.Diagnostics;
  14. using Word = Microsoft.Office.Interop.Word;
  15.  
  16. namespace test
  17. {
  18. public partial class Form2 : Form
  19. {
  20. BindingList<Person> people = new BindingList<Person>();
  21.  
  22. public Form2()
  23. {
  24. InitializeComponent();
  25. }
  26.  
  27. private void btn_Click(object sender, EventArgs e)
  28. {
  29. TextBox[] TxtArray_d = new TextBox[] { this.TBox_d1, this.TBox_d2, this.TBox_d3, this.TBox_d4, this.TBox_d5, this.TBox_d6,
  30. this.TBox_d7, this.TBox_d8, this.TBox_d9, this.TBox_d10, this.TBox_d11,
  31. this.TBox_d12, this.TBox_d13, this.TBox_d14, this.TBox_d15 };
  32.  
  33. people = new BindingList<Person>();
  34. foreach (var item in CheckedListBox1.Items)
  35. {
  36. Person p = new Person
  37. {
  38. Id = CheckedListBox1.Items.IndexOf(item),
  39. Name = item.ToString(),
  40. Value1 = TBox_d1.Text,
  41. Value2 = TBox_d2.Text,
  42. Value3 = TBox_d3.Text,
  43. Value4 = TBox_d4.Text,
  44. Value5 = TBox_d5.Text,
  45. Value6 = TBox_d6.Text,
  46. Value7 = TBox_d7.Text,
  47. Value8 = TBox_d8.Text,
  48. Value9 = TBox_d9.Text,
  49. Value10 = TBox_d10.Text,
  50. Value11 = TBox_d11.Text,
  51. Value12 = TBox_d12.Text,
  52. Value13 = TBox_d13.Text,
  53. Value14 = TBox_d14.Text,
  54. Value15 = TBox_d15.Text,
  55. };
  56. people.Add(p);
  57. }
  58.  
  59. var listBox = ((ListBox)CheckedListBox1);
  60. listBox.DataSource = people;
  61. listBox.DisplayMember = "Name";
  62.  
  63. for (int num = 0; num < 15; ++num)
  64. {
  65. TxtArray_d[num].DataBindings.Clear();
  66. }
  67.  
  68. for (int num = 0; num < 15; ++num)
  69. {
  70. int num1;
  71. num1 = num + 1;
  72. TxtArray_d[num].DataBindings.Add("Text", people, "Value" + num1, false, DataSourceUpdateMode.OnPropertyChanged);
  73. }
  74. }
  75.  
  76. private void btn1_Click(object sender, EventArgs e)
  77. {
  78. Word.Application oWord;
  79.  
  80. try
  81. {
  82. if (Process.GetProcessesByName("WINWORD").Length == 0)
  83. {
  84. oWord = new Word.Application();
  85. }
  86. else
  87. {
  88. oWord = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
  89. }
  90. }
  91. catch
  92. {
  93. MessageBox.Show("Остановлено");
  94. return;
  95. }
  96.  
  97. Form4 waitForm = new Form4();
  98. waitForm.TopMost = true;
  99. waitForm.StartPosition = FormStartPosition.CenterParent;
  100. waitForm.Show();
  101. if (waitForm.StartPosition == FormStartPosition.CenterParent)
  102. {
  103. var x = Location.X + (Width - waitForm.Width) / 2;
  104. var y = Location.Y + (Height - waitForm.Height) / 2;
  105. waitForm.Location = new Point(Math.Max(x, 0), Math.Max(y, 0));
  106. }
  107. waitForm.Refresh();
  108.  
  109. object oTemplate = @"c:a3.dot";
  110.  
  111. object oMissing = System.Reflection.Missing.Value;
  112.  
  113. oWord.Visible = true;
  114. oWord.WindowState = Word.WdWindowState.wdWindowStateMinimize;
  115.  
  116. Word.Document doc;
  117. doc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
  118. doc.ActiveWindow.WindowState = Word.WdWindowState.wdWindowStateMinimize;
  119.  
  120. foreach (Person p in people)
  121. {
  122. oTable = doc.Tables[p.Id + 3];
  123.  
  124. string[] Values = new string[] { p.Value1, p.Value2, p.Value3, p.Value4, p.Value5, p.Value6, p.Value7, p.Value8, p.Value9, p.Value10,
  125. p.Value11, p.Value12, p.Value13, p.Value14, p.Value15 };
  126.  
  127. for (int t1 = 0; t1 < 15; t1++)
  128. {
  129. if (Values[t1] != String.Empty)
  130. {
  131. int poz2 = t1 + 4;
  132. oTable.Cell(2, poz2).Range.Text = Values[t1];
  133. }
  134. }
  135. }
  136.  
  137. Word.Paragraph oPara2;
  138. object oRngEnd = oWord.Selection.GoTo(Word.WdGoToItem.wdGoToLine, Word.WdGoToDirection.wdGoToLast);
  139. object oAutoText = "Tabel_down_table";
  140. object objTrue = true;
  141. Word.Template oTpl = (Word.Template)doc.get_AttachedTemplate();
  142. oPara2 = doc.Paragraphs.Add(oRngEnd);
  143. oPara2.Range.Text = "";
  144. oPara2.Range.Font.Size = 11;
  145. doc.Paragraphs.Add(oRngEnd);
  146. doc.Paragraphs.Add(oRngEnd);
  147. doc.Paragraphs.Add(oRngEnd);
  148. doc.Paragraphs.Add(oRngEnd);
  149. oPara2.Range.Select();
  150. oTpl.AutoTextEntries.get_Item(ref oAutoText).Insert(oWord.Selection.Range, ref objTrue);
  151.  
  152. oWord.Selection.GoTo(Word.WdGoToItem.wdGoToLine, Word.WdGoToDirection.wdGoToFirst);
  153.  
  154. object oTemplate_null = "";
  155. doc.set_AttachedTemplate(oTemplate_null);
  156.  
  157. doc.ActiveWindow.View.DisplayPageBoundaries = true;
  158.  
  159. doc.ActiveWindow.ActivePane.View.Zoom.PageFit = Word.WdPageFit.wdPageFitBestFit;
  160.  
  161. doc.ActiveWindow.WindowState = Word.WdWindowState.wdWindowStateMaximize;
  162.  
  163. waitForm.Close();
  164.  
  165. doc.Activate();
  166. oWord.Activate();
  167. }
  168.  
  169. }
  170. }
  171.  
  172. public class Person
  173. {
  174. public int Id { get; set; }
  175. public string Name { get; set; }
  176.  
  177. public string Value1 { get; set; }
  178. public string Value2 { get; set; }
  179. public string Value3 { get; set; }
  180. public string Value4 { get; set; }
  181. public string Value5 { get; set; }
  182. public string Value6 { get; set; }
  183. public string Value7 { get; set; }
  184. public string Value8 { get; set; }
  185. public string Value9 { get; set; }
  186. public string Value10 { get; set; }
  187. public string Value11 { get; set; }
  188. public string Value12 { get; set; }
  189. public string Value13 { get; set; }
  190. public string Value14 { get; set; }
  191. public string Value15 { get; set; }
  192. }
Add Comment
Please, Sign In to add comment