|
@@ -11,7 +11,7 @@ namespace WordAnalyze
|
|
|
|
|
|
}
|
|
|
|
|
|
- public static string splitChar = "---";
|
|
|
+ public static string splitChar = "#";
|
|
|
public string path = "";
|
|
|
|
|
|
public void SetPath(string path)
|
|
@@ -43,13 +43,13 @@ namespace WordAnalyze
|
|
|
|
|
|
Word.Document newDoc = null;
|
|
|
newDoc = app.Documents.Add();
|
|
|
- // 遍历word,通过 --- 三个横线分割
|
|
|
+ // 遍历word,通过 每行开头 # 横线分割
|
|
|
for (int index = 1; index < garapraph.Count; index ++)
|
|
|
{
|
|
|
string text = garapraph[index].Range.Text.ToString();
|
|
|
// Logger.D("document parapraph with index({0}) get message ({1})", index, garapraph[index].Range.Text.ToString());
|
|
|
text = text.Trim();
|
|
|
- if (splitChar == text)
|
|
|
+ if (text.StartsWith(splitChar))
|
|
|
{
|
|
|
if (insert)
|
|
|
{
|
|
@@ -58,8 +58,27 @@ namespace WordAnalyze
|
|
|
}
|
|
|
newDoc.Close();
|
|
|
newDoc = app.Documents.Add();
|
|
|
- insert = false;
|
|
|
- continue;
|
|
|
+
|
|
|
+ object findText = splitChar;
|
|
|
+ object replace = "";
|
|
|
+ object missing = null;
|
|
|
+ object replaceOne = Word.WdReplace.wdReplaceOne;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var findObject = garapraph[index].Range.Find;
|
|
|
+ findObject.ClearFormatting();
|
|
|
+ findObject.Text = splitChar;
|
|
|
+ findObject.Replacement.ClearFormatting();
|
|
|
+ findObject.Replacement.Text = "";
|
|
|
+ findObject.Execute(findText, ref missing, ref missing, ref missing, ref missing,
|
|
|
+ ref missing, ref missing, ref missing, ref missing, ref missing,
|
|
|
+ ref replaceOne, ref missing, ref missing, ref missing, ref missing);
|
|
|
+ }
|
|
|
+ catch (System.Exception err)
|
|
|
+ {
|
|
|
+ Logger.E("analyze with file name({0}) replace {1} error ->({2})", fileName, splitChar, err.Message.ToString());
|
|
|
+ return err.Message.ToString();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
garapraph[index].Range.Select();
|
|
@@ -86,7 +105,15 @@ namespace WordAnalyze
|
|
|
finally
|
|
|
{
|
|
|
if (doc != null) {
|
|
|
- doc.Undo();
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ bool undo = doc.Undo();
|
|
|
+ if(!undo)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ doc.Save();
|
|
|
doc.Close();
|
|
|
}
|
|
|
if (app != null)
|