Subversion Repositories DevTools

Rev

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

Rev 2094 Rev 2104
Line 1... Line 1...
1
using System;
1
using System;
-
 
2
using System.Collections;
-
 
3
using System.Text;
-
 
4
using System.ComponentModel;
-
 
5
using System.Windows.Forms;
2
using Word;
6
using Word;
3
 
7
 
4
namespace EA_DocGen
8
namespace EA_DocGen
5
{
9
{
6
	/// <summary>
10
	/// <summary>
Line 8... Line 12...
8
	/// </summary>
12
	/// </summary>
9
	public class TabularContent
13
	public class TabularContent
10
	{
14
	{
11
      private Word.Application WordApp = null;
15
      private Word.Application WordApp = null;
12
      private Word.Document WordDocument = null;
16
      private Word.Document WordDocument = null;
-
 
17
      private EA_Utilities EA_Utils = null;
13
 
18
 
14
      private Word.Range WordRange;
19
      private Word.Range WordRange;
15
      private object startLocation;
20
      private object startLocation;
16
      private object endLocation;
21
      private object endLocation;
17
 
22
 
18
		public TabularContent(Word.Application wordApp, Word.Document wordDocument)
23
		public TabularContent(Word.Application wordApp, Word.Document wordDocument, EA_Utilities utilsRef)
19
		{
24
		{
20
         WordApp = wordApp;
25
         WordApp = wordApp;
21
         WordDocument = wordDocument;
26
         WordDocument = wordDocument;
-
 
27
         EA_Utils = utilsRef;
22
			//
28
			//
23
			// TODO: Add constructor logic here
29
			// TODO: Add constructor logic here
24
			//
30
			//
25
		}
31
		}
26
 
32
 
Line 110... Line 116...
110
         WordApp.Selection.InsertRowsBelow(ref rowC);
116
         WordApp.Selection.InsertRowsBelow(ref rowC);
111
         table.Rows[row+1].Shading.BackgroundPatternColor = Word.WdColor.wdColorWhite;
117
         table.Rows[row+1].Shading.BackgroundPatternColor = Word.WdColor.wdColorWhite;
112
         return row+1;
118
         return row+1;
113
      }
119
      }
114
 
120
 
-
 
121
      public void Table_DeleteThisRow(Word.Table table, int row)
-
 
122
      {
-
 
123
         table.Rows[row].Delete();
-
 
124
      }
-
 
125
 
-
 
126
      public void Table_DeleteRows(Word.Table table, int row, int count)
-
 
127
      {
-
 
128
         for (int i=0; i<count; i++)
-
 
129
         {
-
 
130
            table.Rows[row].Delete();
-
 
131
         }
-
 
132
      }
115
 
133
 
116
      public int Table_AppendSeperatorAndNewRowAfterThisRow(Word.Table table, int row)
134
      public int Table_AppendSeperatorAndNewRowAfterThisRow(Word.Table table, int row)
117
      {
135
      {
118
         // add two more rows, the first being a seperator
136
         // add two more rows, the first being a seperator
119
         int seperatorRow = Table_InsertNewRowAfterThisRow(table, row);
137
         int seperatorRow = Table_InsertNewRowAfterThisRow(table, row);
Line 157... Line 175...
157
         unit = Word.WdUnits.wdStory; 
175
         unit = Word.WdUnits.wdStory; 
158
         extend = Word.WdMovementType.wdMove;
176
         extend = Word.WdMovementType.wdMove;
159
         WordApp.Selection.EndKey(ref unit, ref extend);
177
         WordApp.Selection.EndKey(ref unit, ref extend);
160
      }
178
      }
161
 
179
 
-
 
180
 
-
 
181
      public void processTableElement(EA.Element theElement, int recurse_level )
-
 
182
      {
-
 
183
         string [] EA_DocGenTable = null;
-
 
184
         string [] cells = null;
-
 
185
 
-
 
186
         string delimStr = "\r\n";
-
 
187
         char [] delim = delimStr.ToCharArray();
-
 
188
 
-
 
189
         string trimStr = " ";
-
 
190
         char [] trimChars = trimStr.ToCharArray();
-
 
191
 
-
 
192
         EA_DocGenTable = theElement.Notes.ToString().Split(delim,200);
-
 
193
 
-
 
194
         int columnCount = 0;
-
 
195
         int rowCount = 0;
-
 
196
         char seperator = ',';
-
 
197
         string tableTitle = "";
-
 
198
         bool gotSeperator = false;
-
 
199
         bool gotTitle = false;
-
 
200
        
-
 
201
         ArrayList colWidths = new ArrayList();
-
 
202
         int indent = 0;
-
 
203
 
-
 
204
         // Scan the notes content line by line looking for table parameters and counting
-
 
205
         // the number of table rows (which is not specified as an explicit table parameter).
-
 
206
         int s_ElementsConsumedByTableParams = 0;
-
 
207
         foreach(string s in EA_DocGenTable)
-
 
208
         {
-
 
209
            if (s.Length > 0 && s != "\n" && s != "\r" )
-
 
210
            {
-
 
211
               if (gotTitle == false && s.StartsWith("title"))
-
 
212
               {
-
 
213
                  s_ElementsConsumedByTableParams++;
-
 
214
                  tableTitle = EA_Utils.options.getOptionValue(s, tableTitle);
-
 
215
                  gotTitle = true;
-
 
216
                  if (tableTitle == "")
-
 
217
                  {
-
 
218
                     MessageBox.Show( "Table Element Serialisation Failed - Bad Title" );
-
 
219
                     break;
-
 
220
                  }
-
 
221
               }
-
 
222
            
-
 
223
               else if (columnCount == 0 && s.StartsWith("columns"))
-
 
224
               {
-
 
225
                  s_ElementsConsumedByTableParams++;
-
 
226
                  columnCount = EA_Utils.options.getOptionValue(s, columnCount);
-
 
227
                  if (columnCount == 0)
-
 
228
                  {
-
 
229
                     MessageBox.Show( "Table Element Serialisation Failed - bad column count" );
-
 
230
                     break;
-
 
231
                  }
-
 
232
               }
-
 
233
 
-
 
234
               else if (gotSeperator == false && s.StartsWith("seperator"))
-
 
235
               {
-
 
236
                  s_ElementsConsumedByTableParams++;
-
 
237
                  seperator = EA_Utils.options.getOptionValue(s, seperator);
-
 
238
                  gotSeperator = true;
-
 
239
               }
-
 
240
 
-
 
241
               else if (s.StartsWith("widths"))
-
 
242
               {
-
 
243
                  s_ElementsConsumedByTableParams++;
-
 
244
                  string optValStr = EA_Utils.options.getOptionValue(s, "");
-
 
245
 
-
 
246
                  string width_delimStr = ",";
-
 
247
                  char [] width_delim = width_delimStr.ToCharArray();
-
 
248
 
-
 
249
                  string [] width_strings = optValStr.Split(width_delim, 50);
-
 
250
 
-
 
251
                  foreach (string ws in width_strings)
-
 
252
                  {
-
 
253
                     if (ws.Length > 0 && ws != "\n" && ws != "\r" )
-
 
254
                     {
-
 
255
                        colWidths.Add( System.Convert.ToDouble(ws) );
-
 
256
                     }
-
 
257
                  }
-
 
258
               }
-
 
259
               else if (s.StartsWith("indent"))
-
 
260
               {
-
 
261
                  s_ElementsConsumedByTableParams++;
-
 
262
                  indent = EA_Utils.options.getOptionValue(s, 0);
-
 
263
               }
-
 
264
               else
-
 
265
               {
-
 
266
                  rowCount++;
-
 
267
               }
-
 
268
            }
-
 
269
         }
-
 
270
 
-
 
271
         if (gotTitle == true && gotSeperator == true && columnCount != 0)
-
 
272
         {
-
 
273
            if (rowCount < 2)
-
 
274
            {
-
 
275
               MessageBox.Show( "Table Element Serialisation Failed - Insufficient Rows" );
-
 
276
            }
-
 
277
            else
-
 
278
            {
-
 
279
               // create the table in the word doc
-
 
280
               int tableNum = Table_Create( tableTitle, rowCount, columnCount );
-
 
281
               Word.Table table = WordDocument.Tables[tableNum];
-
 
282
               object center = Word.WdParagraphAlignment.wdAlignParagraphCenter;
-
 
283
 
-
 
284
               int col = 1;
-
 
285
               foreach (double d in colWidths)
-
 
286
               {
-
 
287
                  if (col <= columnCount)
-
 
288
                     table.Columns[col].SetWidth( WordApp.CentimetersToPoints((float)d), Word.WdRulerStyle.wdAdjustNone );
-
 
289
                  col++;
-
 
290
               }
-
 
291
 
-
 
292
               if (indent > 0)
-
 
293
               {
-
 
294
                  table.Select();
-
 
295
                  while (indent > 0)
-
 
296
                  {
-
 
297
                     WordApp.Selection.Paragraphs.Indent();
-
 
298
                     indent--;
-
 
299
                  }
-
 
300
               }
-
 
301
 
-
 
302
               // scan the element notes again to extract the cell content and add it to the
-
 
303
               // table we just created.
-
 
304
               int row = 1;
-
 
305
               col = 0;
-
 
306
               foreach(string s in EA_DocGenTable)
-
 
307
               {
-
 
308
                  if (s.Length > 0 && s != "\n" && s != "\r" )
-
 
309
                  {
-
 
310
                     if (s_ElementsConsumedByTableParams > 0)
-
 
311
                     {
-
 
312
                        s_ElementsConsumedByTableParams--;
-
 
313
                     }
-
 
314
                     else
-
 
315
                     {
-
 
316
                        delimStr = seperator.ToString();
-
 
317
                        delim = delimStr.ToCharArray();
-
 
318
                        cells = s.Split(delim,columnCount);
-
 
319
 
-
 
320
                        if (cells.Length != columnCount)
-
 
321
                        {
-
 
322
                           MessageBox.Show( "Table Element Serialisation Failed - Bad Row" );
-
 
323
                           break;
-
 
324
                        }
-
 
325
                        else
-
 
326
                        {
-
 
327
                           // serialise table row
-
 
328
                           for(col=1; col<=columnCount; col++)
-
 
329
                           {
-
 
330
                              cells[col-1].TrimStart( trimChars );
-
 
331
                              cells[col-1].TrimEnd( trimChars );
-
 
332
 
-
 
333
                              table.Cell(row,col).Range.Text = cells[col-1];
-
 
334
 
-
 
335
                              // special handling for heading row
-
 
336
                              if (row == 1)
-
 
337
                              {
-
 
338
                                 table.Cell(row,col).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
-
 
339
                                 table.Cell(row,col).Range.Font.Bold = 1;
-
 
340
                              }
-
 
341
                           }
-
 
342
                           row++;
-
 
343
                        }                     
-
 
344
                     }
-
 
345
                  }
-
 
346
               }
-
 
347
            }
-
 
348
         }
-
 
349
         else
-
 
350
         {
-
 
351
            MessageBox.Show( "Table Element Serialisation Failed - Table Parameters Incomplete" );
-
 
352
         }
-
 
353
      }
-
 
354
 
162
	}
355
	}
163
}
356
}