Skip to content

Commit e75409b

Browse files
committed
code refacturing
1 parent 4d2a59a commit e75409b

1 file changed

Lines changed: 9 additions & 28 deletions

File tree

src/MiniWord/MiniWord.Implment.cs

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using DocumentFormat.OpenXml;
44
using DocumentFormat.OpenXml.Packaging;
55
using DocumentFormat.OpenXml.Wordprocessing;
6-
using MiniSoftware.Utility;
76
using System;
87
using System.Collections;
98
using System.Collections.Generic;
@@ -103,7 +102,7 @@ private static void Generate(this OpenXmlElement xmlElement, WordprocessingDocum
103102

104103
foreach (var tr in trs)
105104
{
106-
105+
107106
var matchs = (Regex.Matches(tr.InnerText, "(?<={{).*?\\..*?(?=}})")
108107
.Cast<Match>().GroupBy(x => x.Value).Select(varGroup => varGroup.First().Value)).ToArray();
109108
if (matchs.Length > 0)
@@ -130,7 +129,7 @@ private static void Generate(this OpenXmlElement xmlElement, WordprocessingDocum
130129
dic.Add(dicKey, e.Value);
131130
}
132131

133-
ReplaceText(newTr, docx, tags : dic);
132+
ReplaceText(newTr, docx, tags: dic);
134133
table.Append(newTr);
135134
}
136135
tr.Remove();
@@ -194,7 +193,7 @@ private static void ReplaceText(OpenXmlElement xmlElement, WordprocessingDocumen
194193
}
195194

196195
var mainPart = docx.MainDocumentPart;
197-
196+
198197
var imagePart = mainPart.AddImagePart(pic.GetImagePartType);
199198
using (var stream = new MemoryStream(l_Data))
200199
{
@@ -204,20 +203,14 @@ private static void ReplaceText(OpenXmlElement xmlElement, WordprocessingDocumen
204203
}
205204
t.Remove();
206205
}
207-
else if(tag.Value is MiniWorHyperLink){
206+
else if (tag.Value is MiniWorHyperLink)
207+
{
208208
var mainPart = docx.MainDocumentPart;
209209
var linkInfo = (MiniWorHyperLink)tag.Value;
210-
var hyperlink = GetHyperLink(mainPart,linkInfo);
210+
var hyperlink = GetHyperLink(mainPart, linkInfo);
211211
run.Append(hyperlink);
212212
t.Remove();
213213
}
214-
else if (tag.Value is MiniWordColorText)
215-
{
216-
var miniWordColorText = (MiniWordColorText)tag.Value;
217-
var colorText = AddColorText(miniWordColorText);
218-
run.Append(colorText);
219-
t.Remove();
220-
}
221214
else
222215
{
223216
var newText = string.Empty;
@@ -261,9 +254,9 @@ private static void ReplaceText(OpenXmlElement xmlElement, WordprocessingDocumen
261254
}
262255
}
263256

264-
private static Hyperlink GetHyperLink(MainDocumentPart mainPart,MiniWorHyperLink linkInfo)
257+
private static Hyperlink GetHyperLink(MainDocumentPart mainPart, MiniWorHyperLink linkInfo)
265258
{
266-
var hr = mainPart.AddHyperlinkRelationship(new Uri(linkInfo.Url),true);
259+
var hr = mainPart.AddHyperlinkRelationship(new Uri(linkInfo.Url), true);
267260
Hyperlink xmlHyperLink = new Hyperlink(new RunProperties(
268261
new RunStyle { Val = "Hyperlink", },
269262
new Underline { Val = linkInfo.UnderLineValue },
@@ -275,21 +268,9 @@ private static Hyperlink GetHyperLink(MainDocumentPart mainPart,MiniWorHyperLink
275268
Id = hr.Id,
276269
TargetFrame = linkInfo.GetTargetFrame()
277270
};
278-
return xmlHyperLink;
271+
return xmlHyperLink;
279272
}
280-
private static RunProperties AddColorText(MiniWordColorText miniWordColorText)
281-
{
282273

283-
RunProperties runPro = new RunProperties();
284-
Text text = new Text(miniWordColorText.Text);
285-
Color color = new Color() { Val = miniWordColorText.ForeColor?.Replace("#", "") };
286-
Shading shading = new Shading() { Fill = miniWordColorText.BackColor?.Replace("#", "") };
287-
runPro.Append(shading);
288-
runPro.Append(color);
289-
runPro.Append(text);
290-
291-
return runPro;
292-
}
293274
private static void AddPicture(OpenXmlElement appendElement, string relationshipId, MiniWordPicture pic)
294275
{
295276
// Define the reference of the image.

0 commit comments

Comments
 (0)