Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Runtime.InteropServices;
- using System.Data;
- using System.Drawing;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Reflection;
- using System.Diagnostics;
- using Word = Microsoft.Office.Interop.Word;
- namespace test
- {
- public partial class Form2 : Form
- {
- BindingList<Person> people = new BindingList<Person>();
- public Form2()
- {
- InitializeComponent();
- }
- private void btn_Click(object sender, EventArgs e)
- {
- TextBox[] TxtArray_d = new TextBox[] { this.TBox_d1, this.TBox_d2, this.TBox_d3, this.TBox_d4, this.TBox_d5, this.TBox_d6,
- this.TBox_d7, this.TBox_d8, this.TBox_d9, this.TBox_d10, this.TBox_d11,
- this.TBox_d12, this.TBox_d13, this.TBox_d14, this.TBox_d15 };
- people = new BindingList<Person>();
- foreach (var item in CheckedListBox1.Items)
- {
- Person p = new Person
- {
- Id = CheckedListBox1.Items.IndexOf(item),
- Name = item.ToString(),
- Value1 = TBox_d1.Text,
- Value2 = TBox_d2.Text,
- Value3 = TBox_d3.Text,
- Value4 = TBox_d4.Text,
- Value5 = TBox_d5.Text,
- Value6 = TBox_d6.Text,
- Value7 = TBox_d7.Text,
- Value8 = TBox_d8.Text,
- Value9 = TBox_d9.Text,
- Value10 = TBox_d10.Text,
- Value11 = TBox_d11.Text,
- Value12 = TBox_d12.Text,
- Value13 = TBox_d13.Text,
- Value14 = TBox_d14.Text,
- Value15 = TBox_d15.Text,
- };
- people.Add(p);
- }
- var listBox = ((ListBox)CheckedListBox1);
- listBox.DataSource = people;
- listBox.DisplayMember = "Name";
- for (int num = 0; num < 15; ++num)
- {
- TxtArray_d[num].DataBindings.Clear();
- }
- for (int num = 0; num < 15; ++num)
- {
- int num1;
- num1 = num + 1;
- TxtArray_d[num].DataBindings.Add("Text", people, "Value" + num1, false, DataSourceUpdateMode.OnPropertyChanged);
- }
- }
- private void btn1_Click(object sender, EventArgs e)
- {
- Word.Application oWord;
- try
- {
- if (Process.GetProcessesByName("WINWORD").Length == 0)
- {
- oWord = new Word.Application();
- }
- else
- {
- oWord = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
- }
- }
- catch
- {
- MessageBox.Show("Остановлено");
- return;
- }
- Form4 waitForm = new Form4();
- waitForm.TopMost = true;
- waitForm.StartPosition = FormStartPosition.CenterParent;
- waitForm.Show();
- if (waitForm.StartPosition == FormStartPosition.CenterParent)
- {
- var x = Location.X + (Width - waitForm.Width) / 2;
- var y = Location.Y + (Height - waitForm.Height) / 2;
- waitForm.Location = new Point(Math.Max(x, 0), Math.Max(y, 0));
- }
- waitForm.Refresh();
- object oTemplate = @"c:a3.dot";
- object oMissing = System.Reflection.Missing.Value;
- oWord.Visible = true;
- oWord.WindowState = Word.WdWindowState.wdWindowStateMinimize;
- Word.Document doc;
- doc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
- doc.ActiveWindow.WindowState = Word.WdWindowState.wdWindowStateMinimize;
- foreach (Person p in people)
- {
- oTable = doc.Tables[p.Id + 3];
- string[] Values = new string[] { p.Value1, p.Value2, p.Value3, p.Value4, p.Value5, p.Value6, p.Value7, p.Value8, p.Value9, p.Value10,
- p.Value11, p.Value12, p.Value13, p.Value14, p.Value15 };
- for (int t1 = 0; t1 < 15; t1++)
- {
- if (Values[t1] != String.Empty)
- {
- int poz2 = t1 + 4;
- oTable.Cell(2, poz2).Range.Text = Values[t1];
- }
- }
- }
- Word.Paragraph oPara2;
- object oRngEnd = oWord.Selection.GoTo(Word.WdGoToItem.wdGoToLine, Word.WdGoToDirection.wdGoToLast);
- object oAutoText = "Tabel_down_table";
- object objTrue = true;
- Word.Template oTpl = (Word.Template)doc.get_AttachedTemplate();
- oPara2 = doc.Paragraphs.Add(oRngEnd);
- oPara2.Range.Text = "";
- oPara2.Range.Font.Size = 11;
- doc.Paragraphs.Add(oRngEnd);
- doc.Paragraphs.Add(oRngEnd);
- doc.Paragraphs.Add(oRngEnd);
- doc.Paragraphs.Add(oRngEnd);
- oPara2.Range.Select();
- oTpl.AutoTextEntries.get_Item(ref oAutoText).Insert(oWord.Selection.Range, ref objTrue);
- oWord.Selection.GoTo(Word.WdGoToItem.wdGoToLine, Word.WdGoToDirection.wdGoToFirst);
- object oTemplate_null = "";
- doc.set_AttachedTemplate(oTemplate_null);
- doc.ActiveWindow.View.DisplayPageBoundaries = true;
- doc.ActiveWindow.ActivePane.View.Zoom.PageFit = Word.WdPageFit.wdPageFitBestFit;
- doc.ActiveWindow.WindowState = Word.WdWindowState.wdWindowStateMaximize;
- waitForm.Close();
- doc.Activate();
- oWord.Activate();
- }
- }
- }
- public class Person
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public string Value1 { get; set; }
- public string Value2 { get; set; }
- public string Value3 { get; set; }
- public string Value4 { get; set; }
- public string Value5 { get; set; }
- public string Value6 { get; set; }
- public string Value7 { get; set; }
- public string Value8 { get; set; }
- public string Value9 { get; set; }
- public string Value10 { get; set; }
- public string Value11 { get; set; }
- public string Value12 { get; set; }
- public string Value13 { get; set; }
- public string Value14 { get; set; }
- public string Value15 { get; set; }
- }
Add Comment
Please, Sign In to add comment