одиночные замены с параметром

This commit is contained in:
melekhin
2026-09-10 10:17:33 +07:00
parent e120439681
commit eb3055a2e8
3 changed files with 599 additions and 0 deletions
+129
View File
@@ -337,6 +337,135 @@ internal sealed class WordWriter : WordReader, IWordWriter
#endregion
public void ReplaceString(string oldValue, Func<string, string> newValues)
{
ThrowIfDisposed();
if (string.IsNullOrEmpty(oldValue))
throw new ArgumentException("Old value cannot be null or empty", nameof(oldValue));
if (newValues is null) return;
#if DEBUG
Debug.WriteLine($"[DEBUG] [WordProcessor.ReplaceString(dynamic)] START: '{oldValue}'");
#endif
lock (_syncLock)
{
// 1. Основной текст
DynamicReplaceExt.ReplaceStringInBody(_body, oldValue, newValues, StringComparison.OrdinalIgnoreCase);
// 2. Таблицы в основном тексте
DynamicReplaceExt.ReplaceStringInTables(_body, oldValue, newValues, StringComparison.OrdinalIgnoreCase);
// 3. Колонтитулы
DynamicReplaceExt.ReplaceStringInHeadersFooters(_doc, oldValue, newValues, StringComparison.OrdinalIgnoreCase);
_isModified = true;
}
}
public void ReplaceItem(string oldValue, Func<string, ReplaceItem> newValues)
{
ThrowIfDisposed();
if (string.IsNullOrEmpty(oldValue))
throw new ArgumentException("Old value cannot be null or empty", nameof(oldValue));
if (newValues is null) return;
#if DEBUG
Debug.WriteLine($"[DEBUG] [WordProcessor.ReplaceItem(dynamic)] START: '{oldValue}'");
#endif
lock (_syncLock)
{
// 1. Основной текст
DynamicReplaceExt.ReplaceItemInBody(_body, oldValue, newValues, StringComparison.OrdinalIgnoreCase);
// 2. Таблицы в основном тексте
DynamicReplaceExt.ReplaceItemInTables(_body, oldValue, newValues, StringComparison.OrdinalIgnoreCase);
// 3. Колонтитулы
DynamicReplaceExt.ReplaceItemInHeadersFooters(_doc, oldValue, newValues, StringComparison.OrdinalIgnoreCase);
_isModified = true;
}
}
public void ReplaceToText(string oldValue, Action<string, IText> buildText)
{
ThrowIfDisposed();
if (string.IsNullOrEmpty(oldValue))
throw new ArgumentException("Old value cannot be null or empty", nameof(oldValue));
if (buildText is null) return;
#if DEBUG
Debug.WriteLine($"[DEBUG] [WordProcessor.ReplaceToText(dynamic)] START: '{oldValue}'");
#endif
lock (_syncLock)
{
DynamicReplaceToTextExt.ReplaceParagraphsContainingTextToTextDynamic(_body, oldValue, buildText);
_isModified = true;
}
}
public void ReplaceString(string oldValue, Func<string, IEnumerable<string>> newValues)
{
throw new NotImplementedException();
}
public void ReplaceString(string oldValue, Func<string, string[]> newValues)
{
throw new NotImplementedException();
}
public void ReplaceItem(string oldValue, Func<string, IEnumerable<ReplaceItem>> newValues)
{
throw new NotImplementedException();
}
public void ReplaceItem(string oldValue, Func<string, ReplaceItem[]> newValues)
{
throw new NotImplementedException();
}
public void ReplaceToTable(string oldValue, Action<string, ITable> buildTable)
{
throw new NotImplementedException();
}
public void ReplaceToTable(string oldValue, FontProps baseFont, Action<string, ITable> buildTable)
{
throw new NotImplementedException();
}
/// <summary>
/// Добавляет новый параграф с указанным текстом в конец документа.
/// </summary>