Subversion Repositories DevTools

Rev

Rev 2104 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2094 ghuddy 1
using System;
2
using Word;
3
 
4
namespace EA_DocGen
5
{
6
	/// <summary>
7
	/// Summary description for TabularContent.
8
	/// </summary>
9
	public class TabularContent
10
	{
11
      private Word.Application WordApp = null;
12
      private Word.Document WordDocument = null;
13
 
14
      private Word.Range WordRange;
15
      private object startLocation;
16
      private object endLocation;
17
 
18
		public TabularContent(Word.Application wordApp, Word.Document wordDocument)
19
		{
20
         WordApp = wordApp;
21
         WordDocument = wordDocument;
22
			//
23
			// TODO: Add constructor logic here
24
			//
25
		}
26
 
27
 
28
      public void AcceptWordAppAndDoc(Word.Application wordApp, Word.Document wordDocument)
29
      {
30
         WordApp = wordApp;
31
         WordDocument = wordDocument;
32
      }
33
 
34
 
35
      public int Table_Create(string tableTitle, int numRows, int numCols)
36
      {
37
         WordDocument.Content.InsertParagraphAfter();
38
         SelectInsertionPointAtEndOfDocument();
39
 
40
         Table_InsertCaption(tableTitle);
41
 
42
         startLocation = WordDocument.Content.End;
43
         WordDocument.Content.InsertParagraphAfter();
44
         endLocation = WordDocument.Content.End;
45
         WordRange = WordDocument.Range(ref startLocation, ref endLocation);
46
 
47
         object defaultTableBehaviour = Type.Missing;
48
         object autofitBehaviour = Type.Missing;
49
         Word.Table Table = WordDocument.Tables.Add( WordRange, numRows, numCols, ref defaultTableBehaviour, ref autofitBehaviour );
50
 
51
         Table.Rows[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20;
52
         Table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
53
         Table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
54
 
55
         Table.Select();
56
         object tableTextStyle = EA_Constants.styleName_TableText;
57
         Table.Range.set_Style( ref tableTextStyle );
58
 
59
         return WordDocument.Tables.Count;
60
      }
61
 
62
 
63
      public int Table_CreateInvisible(int numRows, int numCols)
64
      {
65
         WordDocument.Content.InsertParagraphAfter();
66
         SelectInsertionPointAtEndOfDocument();
67
 
68
         startLocation = WordDocument.Content.End;
69
         WordDocument.Content.InsertParagraphAfter();
70
         endLocation = WordDocument.Content.End;
71
         WordRange = WordDocument.Range(ref startLocation, ref endLocation);
72
 
73
         object defaultTableBehaviour = Type.Missing;
74
         object autofitBehaviour = Type.Missing;
75
         Word.Table Table = WordDocument.Tables.Add( WordRange, numRows, numCols, ref defaultTableBehaviour, ref autofitBehaviour );
76
 
77
         Table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
78
         Table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
79
 
80
         Table.Select();
81
         object tableTextStyle = EA_Constants.styleName_TableText;
82
         Table.Range.set_Style( ref tableTextStyle );
83
 
84
         return WordDocument.Tables.Count;
85
      }
86
 
87
 
88
      public void Table_SetTableColumnTitle(Word.Table table, string title, int column)
89
      {
90
         table.Rows[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray10;
91
         table.Cell(1,column).Range.Text = title;
92
         table.Cell(1,column).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
93
         table.Cell(1,column).Range.Font.Bold = 1;
94
      }
95
 
96
 
97
      public void Table_SetTableCellTitle(Word.Table table, string title, int row, int column)
98
      {
99
         table.Cell(row,column).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20;
100
         table.Cell(row,column).Range.Text = title;
101
         table.Cell(row,column).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
102
         table.Cell(row,column).Range.Font.Bold = 1;
103
      }
104
 
105
 
106
      public int Table_InsertNewRowAfterThisRow(Word.Table table, int row)
107
      {
108
         table.Rows[row].Select();
109
         object rowC = 1;
110
         WordApp.Selection.InsertRowsBelow(ref rowC);
111
         table.Rows[row+1].Shading.BackgroundPatternColor = Word.WdColor.wdColorWhite;
112
         return row+1;
113
      }
114
 
115
 
116
      public int Table_AppendSeperatorAndNewRowAfterThisRow(Word.Table table, int row)
117
      {
118
         // add two more rows, the first being a seperator
119
         int seperatorRow = Table_InsertNewRowAfterThisRow(table, row);
120
         int newRow       = Table_InsertNewRowAfterThisRow(table, seperatorRow);
121
 
122
         // Make seperator row, one cell wide, and remove its left & right borders
123
         table.Rows[seperatorRow].Select();
124
         WordApp.Selection.Cells.Merge();
125
         WordApp.Selection.Borders[Word.WdBorderType.wdBorderLeft].LineStyle = Word.WdLineStyle.wdLineStyleNone;
126
         WordApp.Selection.Borders[Word.WdBorderType.wdBorderRight].LineStyle = Word.WdLineStyle.wdLineStyleNone;
127
 
128
         return newRow;
129
      }
130
 
131
 
132
      public void Table_MergeCellsInThisRow(Word.Table table, int row)
133
      {
134
         table.Rows[row].Select();
135
         WordApp.Selection.Cells.Merge();
136
      }
137
 
138
 
139
      public void Table_InsertCaption(string captionText)
140
      {
141
         object Label = "Table";
142
         object Title = Type.Missing;
143
         object TitleAutoText = Type.Missing;
144
         object Position = Word.WdCaptionPosition.wdCaptionPositionAbove;
145
         object ExcludeLabel = 0;
146
         WordApp.Selection.InsertCaption( ref Label, ref Title, ref TitleAutoText, ref Position, ref ExcludeLabel);
147
         WordApp.Selection.TypeText( ": " + captionText);
148
         WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
149
      }
150
 
151
 
152
      private void SelectInsertionPointAtEndOfDocument()
153
      {
154
         object unit; 
155
         object extend;
156
 
157
         unit = Word.WdUnits.wdStory; 
158
         extend = Word.WdMovementType.wdMove;
159
         WordApp.Selection.EndKey(ref unit, ref extend);
160
      }
161
 
162
	}
163
}