浏览代码

修改切割方式为通过英文#来切割word文件

tangs 7 年之前
父节点
当前提交
4cbcca0e72
共有 6 个文件被更改,包括 37 次插入8 次删除
  1. 二进制
      .vs/WindowsFormsApp1/v15/.suo
  2. 二进制
      .vs/WindowsFormsApp1/v15/sqlite3/storage.ide
  3. 4 2
      WindowsFormsApp1/Form1.cs
  4. 33 6
      WindowsFormsApp1/WordAnalyze.cs
  5. 二进制
      build/WindowsFormsApp1.exe
  6. 二进制
      build/wordSplit.exe

二进制
.vs/WindowsFormsApp1/v15/.suo


二进制
.vs/WindowsFormsApp1/v15/sqlite3/storage.ide


+ 4 - 2
WindowsFormsApp1/Form1.cs

@@ -103,11 +103,13 @@ namespace WindowsFormsApp1
                 if (result != "")
                 {
                     status = "失败";
+                    Logger.E("analyze with filename({0}) error ({1})", fileNames[i], result);
+                } else
+                {
+                    Logger.D("analyze with filename({0}) success ", fileNames[i]);
                 }
-
                 listView1.Items[i].SubItems[1].Text = status;
                 listView1.Items[i].SubItems[2].Text = result;
-                Logger.D("analyze with filename({0}) success with result({1})", fileNames[i], result);
             }
             button1.Enabled = true;
         }

+ 33 - 6
WindowsFormsApp1/WordAnalyze.cs

@@ -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)

二进制
build/WindowsFormsApp1.exe


二进制
build/wordSplit.exe