SVN r1058
SVN-Revision: r1058
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user