ReplaceToTable signatures

This commit is contained in:
melekhin
2026-09-02 13:06:47 +07:00
parent 458436c4c3
commit e5d291713a
2 changed files with 29 additions and 2 deletions
+2 -1
View File
@@ -20,7 +20,8 @@ public interface IWordWriter : IWordReader
void ReplaceString(IEnumerable<KeyValuePair<string, string>> replacements); void ReplaceString(IEnumerable<KeyValuePair<string, string>> replacements);
void ReplaceString(string oldValue, IEnumerable<string> newValues); void ReplaceString(string oldValue, IEnumerable<string> newValues);
void ReplaceString(string oldValue, params string[] newValues); void ReplaceString(string oldValue, params string[] newValues);
void ReplaceToTable(string oldValue, Action<ITable> buildTable, FontProps? baseFont = null); void ReplaceToTable(string oldValue, Action<ITable> buildTable);
void ReplaceToTable(string oldValue, FontProps baseFont, Action<ITable> buildTable);
void ReplaceToText(string oldValue, Action<IText> buildText); void ReplaceToText(string oldValue, Action<IText> buildText);
void Save(); void Save();
void SaveTo(string path); void SaveTo(string path);
+27 -1
View File
@@ -382,7 +382,7 @@ internal sealed class WordWriter : WordReader, IWordWriter
/// </summary> /// </summary>
/// <param name="oldValue">Текст для поиска в параграфах</param> /// <param name="oldValue">Текст для поиска в параграфах</param>
/// <param name="buildTable">Действие для настройки таблицы через TableBuilder</param> /// <param name="buildTable">Действие для настройки таблицы через TableBuilder</param>
public void ReplaceToTable(string oldValue, Action<ITable> buildTable, FontProps? baseFont = null) public void ReplaceToTable(string oldValue, FontProps baseFont, Action<ITable> buildTable)
{ {
ThrowIfDisposed(); ThrowIfDisposed();
@@ -403,6 +403,32 @@ internal sealed class WordWriter : WordReader, IWordWriter
} }
} }
/// <summary>
/// Заменяет параграф, содержащий указанный текст, на таблицу, созданную с помощью TableBuilder
/// </summary>
/// <param name="oldValue">Текст для поиска в параграфах</param>
/// <param name="buildTable">Действие для настройки таблицы через TableBuilder</param>
public void ReplaceToTable(string oldValue, Action<ITable> buildTable)
{
ThrowIfDisposed();
if (string.IsNullOrEmpty(oldValue))
throw new ArgumentException("Old value cannot be null or empty", nameof(oldValue));
if (buildTable is null) return;
#if DEBUG
Debug.WriteLine($"[DEBUG] [WordProcessor.ReplaceToTable] Looking for '{oldValue}' to replace with custom table");
#endif
lock (_syncLock)
{
// Используем метод расширения для Body с TableBuilder
ReplaceToTableExt.ReplaceParagraphsContainingTextToTable(_body, oldValue, buildTable);
_isModified = true;
}
}
#endregion #endregion
#region Replace to text #region Replace to text