| 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 |
|
|
|
84 |
/// <summary>
|
|
|
85 |
/// Creates the styles needed for generating requirement documentation, if they do not
|
|
|
86 |
/// already exist.
|
|
|
87 |
/// </summary>
|
|
|
88 |
public void createRequirementStylesIfNecessary()
|
|
|
89 |
{
|
|
|
90 |
Word.Style s_Body1 = getStyle(EA_Constants.styleName_Body1);
|
|
|
91 |
if (s_Body1 != null)
|
|
|
92 |
{
|
|
|
93 |
// APPROVED ///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
94 |
Word.Style s_ReqAppBody = createParagrapghStyle(EA_Constants.styleName_ReqAppBody, EA_Constants.styleName_ReqAppBody, s_Body1);
|
|
|
95 |
if (s_ReqAppBody != null)
|
|
|
96 |
{
|
|
|
97 |
// No changes needed - this is just a copy of Body 1
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
Word.Style s_ReqAppHdr = null;
|
|
|
101 |
if (s_ReqAppBody != null)
|
|
|
102 |
{
|
|
|
103 |
s_ReqAppHdr = createParagrapghStyle(EA_Constants.styleName_ReqAppHdr, EA_Constants.styleName_ReqAppBody, s_Body1);
|
|
|
104 |
if (s_ReqAppHdr != null)
|
|
|
105 |
{
|
|
|
106 |
// Indent:Hanging: 2.5cm, Space After: 3pt, Keep with next, Tabs: 16.5cm, Right
|
|
|
107 |
s_ReqAppHdr.ParagraphFormat.FirstLineIndent = WordApp.CentimetersToPoints((float)-2.5);
|
|
|
108 |
s_ReqAppHdr.ParagraphFormat.SpaceAfter = 3;
|
|
|
109 |
s_ReqAppHdr.ParagraphFormat.KeepWithNext = (int)MsoTriState.msoTrue;
|
|
|
110 |
s_ReqAppHdr.ParagraphFormat.TabStops.ClearAll();
|
|
|
111 |
object alignment = Word.WdTabAlignment.wdAlignTabRight;
|
|
|
112 |
object leader = Word.WdTabLeader.wdTabLeaderSpaces;
|
|
|
113 |
s_ReqAppHdr.ParagraphFormat.TabStops.Add( WordApp.CentimetersToPoints((float)16.5), ref alignment, ref leader );
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
// PROPOSED ///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
118 |
Word.Style s_ReqPropBody = null;
|
|
|
119 |
if (s_ReqAppBody != null)
|
|
|
120 |
{
|
|
|
121 |
s_ReqPropBody = createParagrapghStyle(EA_Constants.styleName_ReqPropBody, EA_Constants.styleName_ReqPropBody, s_ReqAppBody );
|
|
|
122 |
if (s_ReqPropBody != null)
|
|
|
123 |
{
|
|
|
124 |
// Font: Italic
|
|
|
125 |
s_ReqPropBody.Font.Italic = (int)MsoTriState.msoTrue;
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
if (s_ReqAppHdr != null && s_ReqPropBody != null)
|
|
|
130 |
{
|
|
|
131 |
Word.Style s_ReqPropHdr = createParagrapghStyle(EA_Constants.styleName_ReqPropHdr, EA_Constants.styleName_ReqPropBody, s_ReqAppHdr );
|
|
|
132 |
if (s_ReqPropHdr != null)
|
|
|
133 |
{
|
|
|
134 |
// Font: Italic
|
|
|
135 |
s_ReqPropHdr.Font.Italic = (int)MsoTriState.msoTrue;
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
// REJECTED ///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
140 |
Word.Style s_ReqRejBody = null;
|
|
|
141 |
if (s_ReqAppBody != null)
|
|
|
142 |
{
|
|
|
143 |
s_ReqRejBody = createParagrapghStyle(EA_Constants.styleName_ReqRejBody, EA_Constants.styleName_ReqRejBody, s_ReqAppBody );
|
|
|
144 |
if (s_ReqRejBody != null)
|
|
|
145 |
{
|
|
|
146 |
// Font: Italic
|
|
|
147 |
s_ReqRejBody.Font.StrikeThrough = (int)MsoTriState.msoTrue;
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
if (s_ReqAppHdr != null && s_ReqRejBody != null)
|
|
|
152 |
{
|
|
|
153 |
Word.Style s_ReqRejHdr = createParagrapghStyle(EA_Constants.styleName_ReqRejHdr, EA_Constants.styleName_ReqRejBody, s_ReqAppHdr );
|
|
|
154 |
if (s_ReqRejHdr != null)
|
|
|
155 |
{
|
|
|
156 |
// Font: Italic
|
|
|
157 |
s_ReqRejHdr.Font.StrikeThrough = (int)MsoTriState.msoTrue;
|
|
|
158 |
}
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
// REQUIREMENT NAME ///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
162 |
Word.Style s_DefParaFont = getStyle("Default Paragraph Font");
|
|
|
163 |
if (s_DefParaFont != null)
|
|
|
164 |
{
|
|
|
165 |
Word.Style s_ReqName = createCharacterStyle(EA_Constants.styleName_ReqName, s_DefParaFont );
|
|
|
166 |
if (s_ReqName != null)
|
|
|
167 |
{
|
|
|
168 |
s_ReqName.Font.Bold = (int)MsoTriState.msoTrue;
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
}
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
/// <summary>
|
|
|
175 |
/// This function was the only way I could figure out how to obtain a style object for
|
|
|
176 |
/// the style name given. Everything else I tried, didn't work, even code from Visual Basic
|
|
|
177 |
/// examples failed to work or even compile (once converted) in C#.
|
|
|
178 |
/// </summary>
|
|
|
179 |
/// <param name="styleText"></param>
|
|
|
180 |
/// <returns></returns>
|
|
|
181 |
public Word.Style getStyle(string styleText)
|
|
|
182 |
{
|
|
|
183 |
foreach(Word.Style aStyle in WordDocument.Styles)
|
|
|
184 |
{
|
|
|
185 |
//MessageBox.Show( aStyle.NameLocal );
|
|
|
186 |
if (aStyle.NameLocal.StartsWith(styleText))
|
|
|
187 |
{
|
|
|
188 |
return aStyle;
|
|
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
return null;
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
}
|
|
|
197 |
}
|