Subversion Repositories DevTools

Rev

Rev 2094 | Rev 2104 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2094 ghuddy 1
using System;
2
using Word;
3
using Microsoft.Office.Core;
4
 
5
 
6
namespace EA_DocGen
7
{
8
	/// <summary>
9
	/// Summary description for StyleContent.
10
	/// </summary>
11
	public class StyleContent
12
	{
13
      private Word.Application WordApp = null;
14
      private Word.Document WordDocument = null;
15
 
16
		public StyleContent(Word.Application wordApp, Word.Document wordDocument)
17
		{
18
         WordApp = wordApp;
19
         WordDocument = wordDocument;
20
		}
21
 
22
      public void AcceptWordAppAndDoc(Word.Application wordApp, Word.Document wordDocument)
23
      {
24
         WordApp = wordApp;
25
         WordDocument = wordDocument;
26
      }
27
 
28
      /// <summary>
29
      /// Creates a wdStyleTypeParagraph based style
30
      /// </summary>
31
      /// <param name="newStyleName"></param>
32
      /// <param name="followingStyleName"></param>
33
      /// <param name="baseStyle"></param>
34
      /// <returns></returns>
35
      public Word.Style createParagrapghStyle(string newStyleName, 
36
         string followingStyleName, 
37
         Word.Style baseStyle)
38
      {
39
         Word.Style s = getStyle(newStyleName);
40
         if (s == null)
41
         {
42
            object o_styleType = Word.WdStyleType.wdStyleTypeParagraph;
43
            s = WordDocument.Styles.Add(newStyleName, ref o_styleType);
44
 
45
            object o_baseStyle = baseStyle.NameLocal;
46
            object o_followingStyle = followingStyleName;
47
            s.set_BaseStyle(ref o_baseStyle);
48
            s.set_NextParagraphStyle(ref o_followingStyle);
49
 
50
            s.Font = baseStyle.Font;
51
            s.ParagraphFormat = baseStyle.ParagraphFormat;
52
            s.LanguageID = Word.WdLanguageID.wdEnglishAUS;
53
            s.NoProofing = 0;
54
            s.Frame.Delete();
55
            s.NoSpaceBetweenParagraphsOfSameStyle = false;
56
 
57
         }
58
         return s;
59
      }
60
 
61
      /// <summary>
62
      /// Creates a wdStyleTypeCharacter based style
63
      /// </summary>
64
      /// <param name="newStyleName"></param>
65
      /// <param name="baseStyle"></param>
66
      /// <returns></returns>
67
      public Word.Style createCharacterStyle(string newStyleName, Word.Style baseStyle)
68
      {
69
         Word.Style s = getStyle(newStyleName);
70
         if (s == null)
71
         {
72
            object o_styleType = Word.WdStyleType.wdStyleTypeCharacter;
73
            s = WordDocument.Styles.Add(newStyleName, ref o_styleType);
74
            object o_baseStyle = baseStyle.NameLocal;
75
            s.set_BaseStyle(ref o_baseStyle);
76
            s.Font = baseStyle.Font;
77
            s.LanguageID = Word.WdLanguageID.wdEnglishAUS;
78
            s.NoProofing = 0;
79
         }
80
         return s;
81
      }
82
 
83
 
2098 ghuddy 84
      public void createElementDetailsStyles()
85
      {
86
         Word.Style s_Body1 = getStyle(EA_Constants.styleName_Body1);
87
         if (s_Body1 != null)
88
         {
89
            // A couple of indented body 1 styles
90
            Word.Style s_B1_3_5 = createParagrapghStyle(EA_Constants.styleName_Body1_Left_3_5cm, EA_Constants.styleName_Body1_Left_3_5cm, s_Body1);
91
            s_B1_3_5.ParagraphFormat.LeftIndent = WordApp.CentimetersToPoints((float)3.5);
92
 
93
            Word.Style s_B1_4_5 = createParagrapghStyle(EA_Constants.styleName_Body1_Left_4_5cm, EA_Constants.styleName_Body1_Left_4_5cm, s_Body1);
94
            s_B1_4_5.ParagraphFormat.LeftIndent = WordApp.CentimetersToPoints((float)4.5);
95
 
96
            // A couple of pseudo-heading styles
97
            Word.Style s_B1_2_5_Italic = createParagrapghStyle(EA_Constants.styleName_Body1_Left_2_5cm_Italic, EA_Constants.styleName_Body1_Left_3_5cm, s_Body1);
98
            s_B1_2_5_Italic.ParagraphFormat.LeftIndent = WordApp.CentimetersToPoints((float)2.5);
99
            s_B1_2_5_Italic.Font.Italic = 1;
100
            s_B1_2_5_Italic.Font.Bold = 1;
101
 
102
            Word.Style s_B1_3_5_Italic = createParagrapghStyle(EA_Constants.styleName_Body1_Left_3_5cm_Italic, EA_Constants.styleName_Body1_Left_4_5cm, s_Body1);
103
            s_B1_3_5_Italic.ParagraphFormat.LeftIndent = WordApp.CentimetersToPoints((float)3.5);
104
            s_B1_3_5_Italic.Font.Italic = 1;
105
            s_B1_3_5_Italic.Font.Bold = 1;
106
 
107
            // Style for use when detailing parameter descriptions
108
            Word.Style s_ParamDesc = createParagrapghStyle(EA_Constants.stylename_Parameter_Description, EA_Constants.styleName_Body1, s_Body1);
109
            s_ParamDesc.ParagraphFormat.TabStops.ClearAll();
110
            object alignment = Word.WdTabAlignment.wdAlignTabLeft;
111
            object leader = Word.WdTabLeader.wdTabLeaderSpaces;
112
            s_ParamDesc.ParagraphFormat.LeftIndent = WordApp.CentimetersToPoints((float)9.0);
113
            s_ParamDesc.ParagraphFormat.TabStops.Add( WordApp.CentimetersToPoints((float)9.0), ref alignment, ref leader );
114
            s_ParamDesc.ParagraphFormat.FirstLineIndent = WordApp.CentimetersToPoints((float)-5.5);
115
         }
116
      }
117
 
2094 ghuddy 118
      /// <summary>
119
      /// Creates the styles needed for generating requirement documentation, if they do not
120
      /// already exist.
121
      /// </summary>
122
      public void createRequirementStylesIfNecessary()
123
      {
124
         Word.Style s_Body1 = getStyle(EA_Constants.styleName_Body1);
125
         if (s_Body1 != null)
126
         {
127
            // APPROVED ///////////////////////////////////////////////////////////////////////////////////////////////
128
            Word.Style s_ReqAppBody = createParagrapghStyle(EA_Constants.styleName_ReqAppBody, EA_Constants.styleName_ReqAppBody, s_Body1);
129
            if (s_ReqAppBody != null)
130
            {
131
               // No changes needed - this is just a copy of Body 1
132
            }
133
 
134
            Word.Style s_ReqAppHdr = null;
135
            if (s_ReqAppBody != null)
136
            {
137
               s_ReqAppHdr = createParagrapghStyle(EA_Constants.styleName_ReqAppHdr, EA_Constants.styleName_ReqAppBody, s_Body1);
138
               if (s_ReqAppHdr != null)
139
               {
140
                  // Indent:Hanging: 2.5cm, Space After: 3pt, Keep with next, Tabs: 16.5cm, Right
141
                  s_ReqAppHdr.ParagraphFormat.FirstLineIndent = WordApp.CentimetersToPoints((float)-2.5);
142
                  s_ReqAppHdr.ParagraphFormat.SpaceAfter = 3;
143
                  s_ReqAppHdr.ParagraphFormat.KeepWithNext = (int)MsoTriState.msoTrue;
144
                  s_ReqAppHdr.ParagraphFormat.TabStops.ClearAll();
145
                  object alignment = Word.WdTabAlignment.wdAlignTabRight;
146
                  object leader = Word.WdTabLeader.wdTabLeaderSpaces;
147
                  s_ReqAppHdr.ParagraphFormat.TabStops.Add( WordApp.CentimetersToPoints((float)16.5), ref alignment, ref leader );
148
               }
149
            }
150
 
151
            // PROPOSED ///////////////////////////////////////////////////////////////////////////////////////////////
152
            Word.Style s_ReqPropBody = null;
153
            if (s_ReqAppBody != null)
154
            {
155
               s_ReqPropBody = createParagrapghStyle(EA_Constants.styleName_ReqPropBody, EA_Constants.styleName_ReqPropBody, s_ReqAppBody );
156
               if (s_ReqPropBody != null)
157
               {
158
                  // Font: Italic
159
                  s_ReqPropBody.Font.Italic = (int)MsoTriState.msoTrue;
160
               }
161
            }
162
 
163
            if (s_ReqAppHdr != null && s_ReqPropBody != null)
164
            {
165
               Word.Style s_ReqPropHdr = createParagrapghStyle(EA_Constants.styleName_ReqPropHdr, EA_Constants.styleName_ReqPropBody, s_ReqAppHdr );
166
               if (s_ReqPropHdr != null)
167
               {
168
                  // Font: Italic
169
                  s_ReqPropHdr.Font.Italic = (int)MsoTriState.msoTrue;
170
               }
171
            }
172
 
173
            // REJECTED ///////////////////////////////////////////////////////////////////////////////////////////////
174
            Word.Style s_ReqRejBody = null;
175
            if (s_ReqAppBody != null)
176
            {
177
               s_ReqRejBody = createParagrapghStyle(EA_Constants.styleName_ReqRejBody, EA_Constants.styleName_ReqRejBody, s_ReqAppBody );
178
               if (s_ReqRejBody != null)
179
               {
180
                  // Font: Italic
181
                  s_ReqRejBody.Font.StrikeThrough = (int)MsoTriState.msoTrue;
182
               }
183
            }
184
 
185
            if (s_ReqAppHdr != null && s_ReqRejBody != null)
186
            {
187
               Word.Style s_ReqRejHdr = createParagrapghStyle(EA_Constants.styleName_ReqRejHdr, EA_Constants.styleName_ReqRejBody, s_ReqAppHdr );
188
               if (s_ReqRejHdr != null)
189
               {
190
                  // Font: Italic
191
                  s_ReqRejHdr.Font.StrikeThrough = (int)MsoTriState.msoTrue;
192
               }
193
            }
194
 
195
            // REQUIREMENT NAME ///////////////////////////////////////////////////////////////////////////////////////////////
196
            Word.Style s_DefParaFont = getStyle("Default Paragraph Font");
197
            if (s_DefParaFont != null)
198
            {
199
               Word.Style s_ReqName = createCharacterStyle(EA_Constants.styleName_ReqName, s_DefParaFont );
200
               if (s_ReqName != null)
201
               {
202
                  s_ReqName.Font.Bold = (int)MsoTriState.msoTrue;
203
               }
204
            }
205
         }
206
      }
207
 
208
      /// <summary>
209
      /// This function was the only way I could figure out how to obtain a style object for
210
      /// the style name given. Everything else I tried, didn't work, even code from Visual Basic
211
      /// examples failed to work or even compile (once converted) in C#.
212
      /// </summary>
213
      /// <param name="styleText"></param>
214
      /// <returns></returns>
215
      public Word.Style getStyle(string styleText)
216
      {
217
         foreach(Word.Style aStyle in WordDocument.Styles)
218
         {
219
            //MessageBox.Show( aStyle.NameLocal );
220
            if (aStyle.NameLocal.StartsWith(styleText))
221
            {
222
               return aStyle;
223
            }
224
         }
225
         return null;
226
      }
227
 
228
 
229
 
230
	}
231
}