Subversion Repositories DevTools

Rev

Rev 2104 | Rev 2116 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2104 Rev 2106
Line 10... Line 10...
10
	/// <summary>
10
	/// <summary>
11
	/// Summary description for TabularContent.
11
	/// Summary description for TabularContent.
12
	/// </summary>
12
	/// </summary>
13
	public class TabularContent
13
	public class TabularContent
14
	{
14
	{
15
      private Word.Application WordApp = null;
-
 
16
      private Word.Document WordDocument = null;
-
 
17
      private EA_Utilities EA_Utils = null;
-
 
18
 
-
 
19
      private Word.Range WordRange;
15
      private static Word.Range WordRange;
20
      private object startLocation;
16
      private static object startLocation;
21
      private object endLocation;
17
      private static object endLocation;
22
 
18
 
23
		public TabularContent(Word.Application wordApp, Word.Document wordDocument, EA_Utilities utilsRef)
19
		public static void initialise()
24
		{
20
		{
25
         WordApp = wordApp;
-
 
26
         WordDocument = wordDocument;
-
 
27
         EA_Utils = utilsRef;
-
 
28
			//
-
 
29
			// TODO: Add constructor logic here
-
 
30
			//
-
 
31
		}
21
		}
32
 
22
 
33
 
-
 
34
      public void AcceptWordAppAndDoc(Word.Application wordApp, Word.Document wordDocument)
-
 
35
      {
-
 
36
         WordApp = wordApp;
-
 
37
         WordDocument = wordDocument;
-
 
38
      }
-
 
39
 
-
 
40
 
-
 
41
      public int Table_Create(string tableTitle, int numRows, int numCols)
23
      public static int Table_Create(string tableTitle, bool borders, int numRows, int numCols)
42
      {
24
      {
43
         WordDocument.Content.InsertParagraphAfter();
25
         createWordDoc.WordDocument.Content.InsertParagraphAfter();
44
         SelectInsertionPointAtEndOfDocument();
26
         SelectInsertionPointAtEndOfDocument();
45
         
27
         
46
         Table_InsertCaption(tableTitle);
28
         Table_InsertCaption(tableTitle);
47
        
29
        
48
         startLocation = WordDocument.Content.End;
30
         startLocation = createWordDoc.WordDocument.Content.End;
49
         WordDocument.Content.InsertParagraphAfter();
31
         createWordDoc.WordDocument.Content.InsertParagraphAfter();
50
         endLocation = WordDocument.Content.End;
32
         endLocation = createWordDoc.WordDocument.Content.End;
51
         WordRange = WordDocument.Range(ref startLocation, ref endLocation);
33
         WordRange = createWordDoc.WordDocument.Range(ref startLocation, ref endLocation);
52
 
34
 
53
         object defaultTableBehaviour = Type.Missing;
35
         object defaultTableBehaviour = Type.Missing;
54
         object autofitBehaviour = Type.Missing;
36
         object autofitBehaviour = Type.Missing;
55
         Word.Table Table = WordDocument.Tables.Add( WordRange, numRows, numCols, ref defaultTableBehaviour, ref autofitBehaviour );
37
         Word.Table Table = createWordDoc.WordDocument.Tables.Add( WordRange, numRows, numCols, ref defaultTableBehaviour, ref autofitBehaviour );
56
 
38
 
-
 
39
         if (borders)
-
 
40
         {
57
         Table.Rows[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20;
41
            Table.Rows[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20;
58
         Table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
42
            Table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
59
         Table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
43
            Table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
-
 
44
         }
-
 
45
         else
-
 
46
         {
-
 
47
            Table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
-
 
48
            Table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
-
 
49
         }
60
 
50
 
61
         Table.Select();
51
         Table.Select();
62
         object tableTextStyle = EA_Constants.styleName_TableText;
52
         object tableTextStyle = EA_Constants.styleName_TableText;
63
         Table.Range.set_Style( ref tableTextStyle );
53
         Table.Range.set_Style( ref tableTextStyle );
64
 
54
 
65
         return WordDocument.Tables.Count;
55
         return createWordDoc.WordDocument.Tables.Count;
66
      }
56
      }
67
 
57
 
68
 
58
 
69
      public int Table_CreateInvisible(int numRows, int numCols)
-
 
70
      {
-
 
71
         WordDocument.Content.InsertParagraphAfter();
-
 
72
         SelectInsertionPointAtEndOfDocument();
-
 
73
         
-
 
74
         startLocation = WordDocument.Content.End;
-
 
75
         WordDocument.Content.InsertParagraphAfter();
-
 
76
         endLocation = WordDocument.Content.End;
-
 
77
         WordRange = WordDocument.Range(ref startLocation, ref endLocation);
-
 
78
 
-
 
79
         object defaultTableBehaviour = Type.Missing;
-
 
80
         object autofitBehaviour = Type.Missing;
-
 
81
         Word.Table Table = WordDocument.Tables.Add( WordRange, numRows, numCols, ref defaultTableBehaviour, ref autofitBehaviour );
-
 
82
 
-
 
83
         Table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
-
 
84
         Table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
-
 
85
 
-
 
86
         Table.Select();
-
 
87
         object tableTextStyle = EA_Constants.styleName_TableText;
-
 
88
         Table.Range.set_Style( ref tableTextStyle );
-
 
89
 
-
 
90
         return WordDocument.Tables.Count;
-
 
91
      }
-
 
92
 
-
 
93
 
59
 
94
      public void Table_SetTableColumnTitle(Word.Table table, string title, int column)
60
      public static void Table_SetTableColumnTitle(Word.Table table, string title, int column)
95
      {
61
      {
96
         table.Rows[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray10;
62
         table.Rows[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray10;
97
         table.Cell(1,column).Range.Text = title;
63
         table.Cell(1,column).Range.Text = title;
98
         table.Cell(1,column).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
64
         table.Cell(1,column).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
99
         table.Cell(1,column).Range.Font.Bold = 1;
65
         table.Cell(1,column).Range.Font.Bold = 1;
100
      }
66
      }
101
 
67
 
102
 
68
 
103
      public void Table_SetTableCellTitle(Word.Table table, string title, int row, int column)
69
      public static void Table_SetTableCellTitle(Word.Table table, string title, int row, int column)
104
      {
70
      {
105
         table.Cell(row,column).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20;
71
         table.Cell(row,column).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20;
106
         table.Cell(row,column).Range.Text = title;
72
         table.Cell(row,column).Range.Text = title;
107
         table.Cell(row,column).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
73
         table.Cell(row,column).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
108
         table.Cell(row,column).Range.Font.Bold = 1;
74
         table.Cell(row,column).Range.Font.Bold = 1;
109
      }
75
      }
110
 
76
 
111
 
77
 
112
      public int Table_InsertNewRowAfterThisRow(Word.Table table, int row)
78
      public static int Table_InsertNewRowAfterThisRow(Word.Table table, int row)
113
      {
79
      {
114
         table.Rows[row].Select();
80
         table.Rows[row].Select();
115
         object rowC = 1;
81
         object rowC = 1;
116
         WordApp.Selection.InsertRowsBelow(ref rowC);
82
         createWordDoc.WordApp.Selection.InsertRowsBelow(ref rowC);
117
         table.Rows[row+1].Shading.BackgroundPatternColor = Word.WdColor.wdColorWhite;
83
         table.Rows[row+1].Shading.BackgroundPatternColor = Word.WdColor.wdColorWhite;
118
         return row+1;
84
         return row+1;
119
      }
85
      }
120
 
86
 
121
      public void Table_DeleteThisRow(Word.Table table, int row)
87
      public static void Table_DeleteThisRow(Word.Table table, int row)
122
      {
88
      {
123
         table.Rows[row].Delete();
89
         table.Rows[row].Delete();
124
      }
90
      }
125
 
91
 
126
      public void Table_DeleteRows(Word.Table table, int row, int count)
92
      public static void Table_DeleteRows(Word.Table table, int row, int count)
127
      {
93
      {
128
         for (int i=0; i<count; i++)
94
         for (int i=0; i<count; i++)
129
         {
95
         {
130
            table.Rows[row].Delete();
96
            table.Rows[row].Delete();
131
         }
97
         }
132
      }
98
      }
133
 
99
 
134
      public int Table_AppendSeperatorAndNewRowAfterThisRow(Word.Table table, int row)
100
      public static int Table_AppendSeperatorAndNewRowAfterThisRow(Word.Table table, int row)
135
      {
101
      {
136
         // add two more rows, the first being a seperator
102
         // add two more rows, the first being a seperator
137
         int seperatorRow = Table_InsertNewRowAfterThisRow(table, row);
103
         int seperatorRow = Table_InsertNewRowAfterThisRow(table, row);
138
         int newRow       = Table_InsertNewRowAfterThisRow(table, seperatorRow);
104
         int newRow       = Table_InsertNewRowAfterThisRow(table, seperatorRow);
139
 
105
 
140
         // Make seperator row, one cell wide, and remove its left & right borders
106
         // Make seperator row, one cell wide, and remove its left & right borders
141
         table.Rows[seperatorRow].Select();
107
         table.Rows[seperatorRow].Select();
142
         WordApp.Selection.Cells.Merge();
108
         createWordDoc.WordApp.Selection.Cells.Merge();
143
         WordApp.Selection.Borders[Word.WdBorderType.wdBorderLeft].LineStyle = Word.WdLineStyle.wdLineStyleNone;
109
         createWordDoc.WordApp.Selection.Borders[Word.WdBorderType.wdBorderLeft].LineStyle = Word.WdLineStyle.wdLineStyleNone;
144
         WordApp.Selection.Borders[Word.WdBorderType.wdBorderRight].LineStyle = Word.WdLineStyle.wdLineStyleNone;
110
         createWordDoc.WordApp.Selection.Borders[Word.WdBorderType.wdBorderRight].LineStyle = Word.WdLineStyle.wdLineStyleNone;
145
 
111
 
146
         return newRow;
112
         return newRow;
147
      }
113
      }
148
 
114
 
149
 
115
 
150
      public void Table_MergeCellsInThisRow(Word.Table table, int row)
116
      public static void Table_MergeCellsInThisRow(Word.Table table, int row)
151
      {
117
      {
152
         table.Rows[row].Select();
118
         table.Rows[row].Select();
153
         WordApp.Selection.Cells.Merge();
119
         createWordDoc.WordApp.Selection.Cells.Merge();
154
      }
120
      }
155
 
121
 
156
 
122
 
157
      public void Table_InsertCaption(string captionText)
123
      public static void Table_InsertCaption(string captionText)
158
      {
124
      {
-
 
125
         if (captionText.Length > 0)
-
 
126
         {
159
         object Label = "Table";
127
            object Label = "Table";
160
         object Title = Type.Missing;
128
            object Title = Type.Missing;
161
         object TitleAutoText = Type.Missing;
129
            object TitleAutoText = Type.Missing;
162
         object Position = Word.WdCaptionPosition.wdCaptionPositionAbove;
130
            object Position = Word.WdCaptionPosition.wdCaptionPositionAbove;
163
         object ExcludeLabel = 0;
131
            object ExcludeLabel = 0;
164
         WordApp.Selection.InsertCaption( ref Label, ref Title, ref TitleAutoText, ref Position, ref ExcludeLabel);
132
            createWordDoc.WordApp.Selection.InsertCaption( ref Label, ref Title, ref TitleAutoText, ref Position, ref ExcludeLabel);
165
         WordApp.Selection.TypeText( ": " + captionText);
133
            createWordDoc.WordApp.Selection.TypeText( ": " + captionText);
166
         WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
134
            createWordDoc.WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
-
 
135
         }
167
      }
136
      }
168
 
137
 
169
 
138
 
170
      private void SelectInsertionPointAtEndOfDocument()
139
      private static void SelectInsertionPointAtEndOfDocument()
171
      {
140
      {
172
         object unit; 
141
         object unit; 
173
         object extend;
142
         object extend;
174
 
143
 
175
         unit = Word.WdUnits.wdStory; 
144
         unit = Word.WdUnits.wdStory; 
176
         extend = Word.WdMovementType.wdMove;
145
         extend = Word.WdMovementType.wdMove;
177
         WordApp.Selection.EndKey(ref unit, ref extend);
146
         createWordDoc.WordApp.Selection.EndKey(ref unit, ref extend);
178
      }
147
      }
179
 
148
 
180
 
149
 
181
      public void processTableElement(EA.Element theElement, int recurse_level )
150
      public static void processTableElement(EA.Element theElement, int recurse_level )
182
      {
151
      {
183
         string [] EA_DocGenTable = null;
152
         string [] EA_DocGenTable = null;
184
         string [] cells = null;
153
         string [] cells = null;
185
 
154
 
186
         string delimStr = "\r\n";
155
         string delimStr = "\r\n";
Line 193... Line 162...
193
 
162
 
194
         int columnCount = 0;
163
         int columnCount = 0;
195
         int rowCount = 0;
164
         int rowCount = 0;
196
         char seperator = ',';
165
         char seperator = ',';
197
         string tableTitle = "";
166
         string tableTitle = "";
-
 
167
         bool borders=true;
-
 
168
 
198
         bool gotSeperator = false;
169
         bool gotSeperator = false;
199
         bool gotTitle = false;
170
         bool gotTitle = false;
-
 
171
         bool gotBorders = false;
-
 
172
         bool gotWidths = false;
-
 
173
         bool gotIndent = false;
200
        
174
        
201
         ArrayList colWidths = new ArrayList();
175
         ArrayList colWidths = new ArrayList();
202
         int indent = 0;
176
         int indent = 0;
203
 
177
 
204
         // Scan the notes content line by line looking for table parameters and counting
178
         // Scan the notes content line by line looking for table parameters and counting
Line 206... Line 180...
206
         int s_ElementsConsumedByTableParams = 0;
180
         int s_ElementsConsumedByTableParams = 0;
207
         foreach(string s in EA_DocGenTable)
181
         foreach(string s in EA_DocGenTable)
208
         {
182
         {
209
            if (s.Length > 0 && s != "\n" && s != "\r" )
183
            if (s.Length > 0 && s != "\n" && s != "\r" )
210
            {
184
            {
211
               if (gotTitle == false && s.StartsWith("title"))
185
               if (gotTitle == false && s.StartsWith("title="))
212
               {
186
               {
213
                  s_ElementsConsumedByTableParams++;
187
                  s_ElementsConsumedByTableParams++;
214
                  tableTitle = EA_Utils.options.getOptionValue(s, tableTitle);
188
                  tableTitle = EA_DocGenOptions.getOptionValue(s, tableTitle);
215
                  gotTitle = true;
189
                  gotTitle = true;
216
                  if (tableTitle == "")
190
                  //if (tableTitle == "")
217
                  {
191
                  //{
218
                     MessageBox.Show( "Table Element Serialisation Failed - Bad Title" );
192
                  //   MessageBox.Show( "Table Element Serialisation Failed - Bad Title" );
219
                     break;
193
                  //   break;
220
                  }
194
                  //}
221
               }
195
               }
222
            
196
            
223
               else if (columnCount == 0 && s.StartsWith("columns"))
197
               else if (columnCount == 0 && s.StartsWith("columns="))
224
               {
198
               {
225
                  s_ElementsConsumedByTableParams++;
199
                  s_ElementsConsumedByTableParams++;
226
                  columnCount = EA_Utils.options.getOptionValue(s, columnCount);
200
                  columnCount = EA_DocGenOptions.getOptionValue(s, columnCount);
227
                  if (columnCount == 0)
201
                  if (columnCount == 0)
228
                  {
202
                  {
229
                     MessageBox.Show( "Table Element Serialisation Failed - bad column count" );
203
                     MessageBox.Show( "Table Element Serialisation Failed - bad column count" );
230
                     break;
204
                     break;
231
                  }
205
                  }
232
               }
206
               }
233
 
207
 
234
               else if (gotSeperator == false && s.StartsWith("seperator"))
208
               else if (gotSeperator == false && s.StartsWith("seperator="))
235
               {
209
               {
236
                  s_ElementsConsumedByTableParams++;
210
                  s_ElementsConsumedByTableParams++;
237
                  seperator = EA_Utils.options.getOptionValue(s, seperator);
211
                  seperator = EA_DocGenOptions.getOptionValue(s, seperator);
238
                  gotSeperator = true;
212
                  gotSeperator = true;
239
               }
213
               }
240
 
214
 
241
               else if (s.StartsWith("widths"))
215
               else if (gotWidths == false && s.StartsWith("widths="))
242
               {
216
               {
243
                  s_ElementsConsumedByTableParams++;
217
                  s_ElementsConsumedByTableParams++;
-
 
218
                  gotWidths = true;
244
                  string optValStr = EA_Utils.options.getOptionValue(s, "");
219
                  string optValStr = EA_DocGenOptions.getOptionValue(s, "");
245
 
220
 
246
                  string width_delimStr = ",";
221
                  string width_delimStr = ",";
247
                  char [] width_delim = width_delimStr.ToCharArray();
222
                  char [] width_delim = width_delimStr.ToCharArray();
248
 
223
 
249
                  string [] width_strings = optValStr.Split(width_delim, 50);
224
                  string [] width_strings = optValStr.Split(width_delim, 50);
Line 254... Line 229...
254
                     {
229
                     {
255
                        colWidths.Add( System.Convert.ToDouble(ws) );
230
                        colWidths.Add( System.Convert.ToDouble(ws) );
256
                     }
231
                     }
257
                  }
232
                  }
258
               }
233
               }
259
               else if (s.StartsWith("indent"))
234
               else if (gotIndent == false && s.StartsWith("indent="))
-
 
235
               {
-
 
236
                  s_ElementsConsumedByTableParams++;
-
 
237
                  gotIndent = true;
-
 
238
                  indent = EA_DocGenOptions.getOptionValue(s, 0);
-
 
239
               }
-
 
240
               else if (gotBorders == false && s.StartsWith("borders="))
260
               {
241
               {
261
                  s_ElementsConsumedByTableParams++;
242
                  s_ElementsConsumedByTableParams++;
-
 
243
                  gotBorders = true;
262
                  indent = EA_Utils.options.getOptionValue(s, 0);
244
                  borders = EA_DocGenOptions.getOptionValue(s, borders);
263
               }
245
               }
264
               else
246
               else
265
               {
247
               {
266
                  rowCount++;
248
                  rowCount++;
267
               }
249
               }
268
            }
250
            }
269
         }
251
         }
270
 
252
 
271
         if (gotTitle == true && gotSeperator == true && columnCount != 0)
253
         if (columnCount > 0 && rowCount > 0)
272
         {
254
         {
273
            if (rowCount < 2)
255
            if (rowCount < 2)
274
            {
256
            {
275
               MessageBox.Show( "Table Element Serialisation Failed - Insufficient Rows" );
257
               MessageBox.Show( "Table Element Serialisation Failed - Insufficient Rows" );
276
            }
258
            }
277
            else
259
            else
278
            {
260
            {
279
               // create the table in the word doc
261
               // create the table in the word doc
280
               int tableNum = Table_Create( tableTitle, rowCount, columnCount );
262
               int tableNum = Table_Create( tableTitle, borders, rowCount, columnCount );
281
               Word.Table table = WordDocument.Tables[tableNum];
263
               Word.Table table = createWordDoc.WordDocument.Tables[tableNum];
282
               object center = Word.WdParagraphAlignment.wdAlignParagraphCenter;
264
               object center = Word.WdParagraphAlignment.wdAlignParagraphCenter;
283
 
265
 
284
               int col = 1;
266
               int col = 1;
285
               foreach (double d in colWidths)
267
               foreach (double d in colWidths)
286
               {
268
               {
287
                  if (col <= columnCount)
269
                  if (col <= columnCount)
288
                     table.Columns[col].SetWidth( WordApp.CentimetersToPoints((float)d), Word.WdRulerStyle.wdAdjustNone );
270
                     table.Columns[col].SetWidth( createWordDoc.WordApp.CentimetersToPoints((float)d), Word.WdRulerStyle.wdAdjustNone );
289
                  col++;
271
                  col++;
290
               }
272
               }
291
 
273
 
292
               if (indent > 0)
274
               if (indent > 0)
293
               {
275
               {
294
                  table.Select();
276
                  table.Select();
295
                  while (indent > 0)
277
                  while (indent > 0)
296
                  {
278
                  {
297
                     WordApp.Selection.Paragraphs.Indent();
279
                     createWordDoc.WordApp.Selection.Paragraphs.Indent();
298
                     indent--;
280
                     indent--;
299
                  }
281
                  }
300
               }
282
               }
301
 
283
 
302
               // scan the element notes again to extract the cell content and add it to the
284
               // scan the element notes again to extract the cell content and add it to the