|
@@ -11719,6 +11719,57 @@ FROM
|
|
|
tableOne.Rows.RemoveAt(1 + dtSource.Rows.Count);//(1+dtSource.Rows.Count + 1)-1
|
|
|
}
|
|
|
|
|
|
+ var targetTextList = new List<string>();
|
|
|
+
|
|
|
+ // 遍历文档中的表格
|
|
|
+ foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
|
|
|
+ {
|
|
|
+ foreach (Aspose.Words.Tables.Row row in table.Rows)
|
|
|
+ {
|
|
|
+ var cellIndex = 0;
|
|
|
+
|
|
|
+ foreach (Cell cell in row.Cells)
|
|
|
+ {
|
|
|
+ if (cellIndex == 1 && row.Cells.Count == 4)
|
|
|
+ {
|
|
|
+ foreach (var target in targetTextDic.Keys)
|
|
|
+ {
|
|
|
+ if (cell.GetText().Contains(target))
|
|
|
+ {
|
|
|
+ targetTextList = targetTextDic[target];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历单元格中的所有段落
|
|
|
+ foreach (Paragraph paragraph in cell.Paragraphs)
|
|
|
+ {
|
|
|
+ // 使用临时列表存储原始 Runs,避免修改时影响遍历
|
|
|
+ List<Run> runs = new List<Run>();
|
|
|
+ foreach (Run run in paragraph.Runs)
|
|
|
+ {
|
|
|
+ runs.Add(run);
|
|
|
+ }
|
|
|
+ foreach (Run run in runs)
|
|
|
+ {
|
|
|
+ foreach (var targetText in targetTextList)
|
|
|
+ {
|
|
|
+ // 检查文字是否包含指定文字
|
|
|
+ if (run.Text.Contains(targetText))
|
|
|
+ {
|
|
|
+ // 将包含的部分设置为红色
|
|
|
+ HighlightText(run, targetText, Color.Red);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ cellIndex++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
string savePath = AppSettingsHelper.Get("WordBasePath") + "Travel/export/";
|
|
|
if (!Directory.Exists(savePath))
|
|
|
{
|
|
@@ -11842,6 +11893,43 @@ FROM
|
|
|
}
|
|
|
return str;
|
|
|
}
|
|
|
+
|
|
|
+ // 高亮包含指定文字的部分
|
|
|
+ void HighlightText(Run run, string targetText, Color color)
|
|
|
+ {
|
|
|
+ string text = run.Text;
|
|
|
+ int startIndex = text.IndexOf(targetText, StringComparison.Ordinal);
|
|
|
+
|
|
|
+ if (startIndex >= 0)
|
|
|
+ {
|
|
|
+ Paragraph parentParagraph = (Paragraph)run.ParentNode;
|
|
|
+
|
|
|
+ // 前部分
|
|
|
+ if (startIndex > 0)
|
|
|
+ {
|
|
|
+ Run beforeRun = (Run)run.Clone(true);
|
|
|
+ beforeRun.Text = text.Substring(0, startIndex);
|
|
|
+ parentParagraph.InsertBefore(beforeRun, run);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 匹配部分
|
|
|
+ Run matchRun = (Run)run.Clone(true);
|
|
|
+ matchRun.Text = text.Substring(startIndex, targetText.Length);
|
|
|
+ matchRun.Font.Color = color;
|
|
|
+ parentParagraph.InsertBefore(matchRun, run);
|
|
|
+
|
|
|
+ // 后部分
|
|
|
+ if (startIndex + targetText.Length < text.Length)
|
|
|
+ {
|
|
|
+ Run afterRun = (Run)run.Clone(true);
|
|
|
+ afterRun.Text = text.Substring(startIndex + targetText.Length);
|
|
|
+ parentParagraph.InsertBefore(afterRun, run);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除原始Run
|
|
|
+ run.Remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
|