Subversion Repositories DevTools

Rev

Rev 2128 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2128 Rev 2136
Line 1... Line 1...
1
using System;
1
using System;
2
using System.Collections;
2
using System.Collections;
3
using System.Text;
3
using System.Text;
4
using System.ComponentModel;
4
using System.ComponentModel;
5
using System.Windows.Forms;
5
using System.Windows.Forms;
6
using Word;
6
using Microsoft.Office.Interop.Word;
7
 
7
 
8
namespace EA_DocGen
8
namespace EA_DocGen
9
{
9
{
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 static Word.Range WordRange;
15
      private static Range WordRange;
16
      private static object startLocation;
16
      private static object startLocation;
17
      private static object endLocation;
17
      private static object endLocation;
18
 
18
 
19
		public static void initialise()
19
		public static void initialise()
20
		{
20
		{
Line 40... Line 40...
40
         endLocation = createWordDoc.WordDocument.Content.End;
40
         endLocation = createWordDoc.WordDocument.Content.End;
41
         WordRange = createWordDoc.WordDocument.Range(ref startLocation, ref endLocation);
41
         WordRange = createWordDoc.WordDocument.Range(ref startLocation, ref endLocation);
42
 
42
 
43
         object defaultTableBehaviour = Type.Missing;
43
         object defaultTableBehaviour = Type.Missing;
44
         object autofitBehaviour = Type.Missing;
44
         object autofitBehaviour = Type.Missing;
45
         Word.Table Table = createWordDoc.WordDocument.Tables.Add( WordRange, numRows, numCols, ref defaultTableBehaviour, ref autofitBehaviour );
45
         Table Table = createWordDoc.WordDocument.Tables.Add( WordRange, numRows, numCols, ref defaultTableBehaviour, ref autofitBehaviour );
46
 
46
 
47
         if (borders)
47
         if (borders)
48
         {
48
         {
49
            Table.Rows[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20;
49
            Table.Rows[1].Shading.BackgroundPatternColor = WdColor.wdColorGray20;
50
            Table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
50
            Table.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
51
            Table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
51
            Table.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle;
52
         }
52
         }
53
         else
53
         else
54
         {
54
         {
55
            Table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
55
            Table.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleNone;
56
            Table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
56
            Table.Borders.InsideLineStyle = WdLineStyle.wdLineStyleNone;
57
         }
57
         }
58
 
58
 
59
         Table.Select();
59
         Table.Select();
60
         object tableTextStyle = EA_Constants.styleName_TableText;
60
         object tableTextStyle = EA_Constants.styleName_TableText;
61
         Table.Range.set_Style( ref tableTextStyle );
61
         Table.Range.set_Style( ref tableTextStyle );
Line 63... Line 63...
63
         return createWordDoc.WordDocument.Tables.Count;
63
         return createWordDoc.WordDocument.Tables.Count;
64
      }
64
      }
65
 
65
 
66
 
66
 
67
 
67
 
68
      public static void Table_SetTableColumnTitle(Word.Table table, string title, int column)
68
      public static void Table_SetTableColumnTitle(Table table, string title, int column)
69
      {
69
      {
70
         table.Rows[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray10;
70
         table.Rows[1].Shading.BackgroundPatternColor = WdColor.wdColorGray10;
71
         table.Cell(1,column).Range.Text = title;
71
         table.Cell(1,column).Range.Text = title;
72
         table.Cell(1,column).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
72
         table.Cell(1,column).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
73
         table.Cell(1,column).Range.Font.Bold = 1;
73
         table.Cell(1,column).Range.Font.Bold = 1;
74
      }
74
      }
75
 
75
 
76
 
76
 
77
      public static void Table_SetTableCellTitle(Word.Table table, string title, int row, int column)
77
      public static void Table_SetTableCellTitle(Table table, string title, int row, int column)
78
      {
78
      {
79
         table.Cell(row,column).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20;
79
         table.Cell(row,column).Shading.BackgroundPatternColor = WdColor.wdColorGray20;
80
         table.Cell(row,column).Range.Text = title;
80
         table.Cell(row,column).Range.Text = title;
81
         table.Cell(row,column).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
81
         table.Cell(row,column).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
82
         table.Cell(row,column).Range.Font.Bold = 1;
82
         table.Cell(row,column).Range.Font.Bold = 1;
83
      }
83
      }
84
 
84
 
85
 
85
 
86
      public static int Table_InsertNewRowAfterThisRow(Word.Table table, int row)
86
      public static int Table_InsertNewRowAfterThisRow(Table table, int row)
87
      {
87
      {
88
         table.Rows[row].Select();
88
         table.Rows[row].Select();
89
         object rowC = 1;
89
         object rowC = 1;
90
         createWordDoc.WordApp.Selection.InsertRowsBelow(ref rowC);
90
         createWordDoc.WordApp.Selection.InsertRowsBelow(ref rowC);
91
         table.Rows[row+1].Shading.BackgroundPatternColor = Word.WdColor.wdColorWhite;
91
         table.Rows[row+1].Shading.BackgroundPatternColor = WdColor.wdColorWhite;
92
         return row+1;
92
         return row+1;
93
      }
93
      }
94
 
94
 
95
      public static void Table_DeleteThisRow(Word.Table table, int row)
95
      public static void Table_DeleteThisRow(Table table, int row)
96
      {
96
      {
97
         table.Rows[row].Delete();
97
         table.Rows[row].Delete();
98
      }
98
      }
99
 
99
 
100
      public static void Table_DeleteRows(Word.Table table, int row, int count)
100
      public static void Table_DeleteRows(Table table, int row, int count)
101
      {
101
      {
102
         for (int i=0; i<count; i++)
102
         for (int i=0; i<count; i++)
103
         {
103
         {
104
            table.Rows[row].Delete();
104
            table.Rows[row].Delete();
105
         }
105
         }
106
      }
106
      }
107
 
107
 
108
      public static int Table_AppendSeperatorAndNewRowAfterThisRow(Word.Table table, int row)
108
      public static int Table_AppendSeperatorAndNewRowAfterThisRow(Table table, int row)
109
      {
109
      {
110
         // add two more rows, the first being a seperator
110
         // add two more rows, the first being a seperator
111
         int seperatorRow = Table_InsertNewRowAfterThisRow(table, row);
111
         int seperatorRow = Table_InsertNewRowAfterThisRow(table, row);
112
         int newRow       = Table_InsertNewRowAfterThisRow(table, seperatorRow);
112
         int newRow       = Table_InsertNewRowAfterThisRow(table, seperatorRow);
113
 
113
 
114
         // Make seperator row, one cell wide, and remove its left & right borders
114
         // Make seperator row, one cell wide, and remove its left & right borders
115
         table.Rows[seperatorRow].Select();
115
         table.Rows[seperatorRow].Select();
116
         createWordDoc.WordApp.Selection.Cells.Merge();
116
         createWordDoc.WordApp.Selection.Cells.Merge();
117
         createWordDoc.WordApp.Selection.Borders[Word.WdBorderType.wdBorderLeft].LineStyle = Word.WdLineStyle.wdLineStyleNone;
117
         createWordDoc.WordApp.Selection.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleNone;
118
         createWordDoc.WordApp.Selection.Borders[Word.WdBorderType.wdBorderRight].LineStyle = Word.WdLineStyle.wdLineStyleNone;
118
         createWordDoc.WordApp.Selection.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleNone;
119
 
119
 
120
         return newRow;
120
         return newRow;
121
      }
121
      }
122
 
122
 
123
 
123
 
124
      public static void Table_MergeCellsInThisRow(Word.Table table, int row)
124
      public static void Table_MergeCellsInThisRow(Table table, int row)
125
      {
125
      {
126
         table.Rows[row].Select();
126
         table.Rows[row].Select();
127
         createWordDoc.WordApp.Selection.Cells.Merge();
127
         createWordDoc.WordApp.Selection.Cells.Merge();
128
      }
128
      }
129
 
129
 
Line 133... Line 133...
133
         if (captionText.Length > 0)
133
         if (captionText.Length > 0)
134
         {
134
         {
135
            object Label = "Table";
135
            object Label = "Table";
136
            object Title = Type.Missing;
136
            object Title = Type.Missing;
137
            object TitleAutoText = Type.Missing;
137
            object TitleAutoText = Type.Missing;
138
            object Position = Word.WdCaptionPosition.wdCaptionPositionAbove;
138
            object Position = WdCaptionPosition.wdCaptionPositionAbove;
139
            object ExcludeLabel = 0;
139
            object ExcludeLabel = 0;
140
            createWordDoc.WordApp.Selection.InsertCaption( ref Label, ref Title, ref TitleAutoText, ref Position, ref ExcludeLabel);
140
            createWordDoc.WordApp.Selection.InsertCaption( ref Label, ref Title, ref TitleAutoText, ref Position, ref ExcludeLabel);
141
            createWordDoc.WordApp.Selection.TypeText( ": " + captionText);
141
            createWordDoc.WordApp.Selection.TypeText( ": " + captionText);
142
            createWordDoc.WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
142
            createWordDoc.WordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
143
         }
143
         }
144
      }
144
      }
145
 
145
 
146
 
146
 
147
      private static void SelectInsertionPointAtEndOfDocument()
147
      private static void SelectInsertionPointAtEndOfDocument()
148
      {
148
      {
149
         object unit; 
149
         object unit; 
150
         object extend;
150
         object extend;
151
 
151
 
152
         unit = Word.WdUnits.wdStory; 
152
         unit = WdUnits.wdStory; 
153
         extend = Word.WdMovementType.wdMove;
153
         extend = WdMovementType.wdMove;
154
         createWordDoc.WordApp.Selection.EndKey(ref unit, ref extend);
154
         createWordDoc.WordApp.Selection.EndKey(ref unit, ref extend);
155
      }
155
      }
156
 
156
 
157
 
157
 
158
      /// <summary>
158
      /// <summary>
Line 279... Line 279...
279
            }
279
            }
280
            else
280
            else
281
            {
281
            {
282
               // create the table in the word doc
282
               // create the table in the word doc
283
               int tableNum = Table_Create( tableTitle, borders, rowCount, columnCount );
283
               int tableNum = Table_Create( tableTitle, borders, rowCount, columnCount );
284
               Word.Table table = createWordDoc.WordDocument.Tables[tableNum];
284
               Table table = createWordDoc.WordDocument.Tables[tableNum];
285
               object center = Word.WdParagraphAlignment.wdAlignParagraphCenter;
285
               object center = WdParagraphAlignment.wdAlignParagraphCenter;
286
 
286
 
287
               int col = 1;
287
               int col = 1;
288
               foreach (double d in colWidths)
288
               foreach (double d in colWidths)
289
               {
289
               {
290
                  if (col <= columnCount)
290
                  if (col <= columnCount)
291
                     table.Columns[col].SetWidth( createWordDoc.WordApp.CentimetersToPoints((float)d), Word.WdRulerStyle.wdAdjustNone );
291
                     table.Columns[col].SetWidth( createWordDoc.WordApp.CentimetersToPoints((float)d), WdRulerStyle.wdAdjustNone );
292
                  col++;
292
                  col++;
293
               }
293
               }
294
 
294
 
295
               if (indent > 0)
295
               if (indent > 0)
296
               {
296
               {
Line 338... Line 338...
338
                              table.Cell(row,col).Range.Text = cells[col-1];
338
                              table.Cell(row,col).Range.Text = cells[col-1];
339
 
339
 
340
                              // special handling for heading row
340
                              // special handling for heading row
341
                              if (row == 1)
341
                              if (row == 1)
342
                              {
342
                              {
343
                                 table.Cell(row,col).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
343
                                 table.Cell(row,col).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
344
                                 table.Cell(row,col).Range.Font.Bold = 1;
344
                                 table.Cell(row,col).Range.Font.Bold = 1;
345
                              }
345
                              }
346
                           }
346
                           }
347
                           row++;
347
                           row++;
348
                        }                     
348
                        }