SVN r1058

SVN-Revision: r1058
This commit is contained in:
tdx
2025-11-28 06:35:42 +00:00
parent 5e7a2d5590
commit 66bb7ef8da
+20 -1
View File
@@ -1687,4 +1687,23 @@ namespace Lskj.AutoCreatWord
/// </summary>
/// <param name="objects"></param>
/// <param name="searchText"></param>
/// <param name="replaceText"></param>
private static void ReplaceTextRange(this Document document, string searchText, string replaceText, bool caseSensitive, bool wholeWord)
{
// 查找所有匹配
TextSelection[] results = document.FindAllString(searchText, caseSensitive, wholeWord);
if (results == null) return;
foreach (TextSelection selection in results)
{
TextRange textRange = selection.GetAsOneRange();
if (textRange != null)
{
textRange.Text = Regex.Replace(textRange.Text, Regex.Escape(searchText), replaceText, RegexOptions.IgnoreCase);
string text = textRange.Text;
string splitPattern = @"\r\n|\r|\n"; // 匹配 CRLF (\r\n), CR (\r), LF (\n)
string[] result = Regex.Split(text, splitPattern);
if (result.Length > 1 && textRange.OwnerParagraph != null)
{
Paragraph paragraph = textRange.OwnerParagraph;
CharacterFormat characterFormat = textRange.CharacterFormat;