update 20260406
This commit is contained in:
@@ -236,7 +236,7 @@ namespace DOCGEN.Klassen
|
||||
}
|
||||
}
|
||||
}
|
||||
ReplaceBookmarkContent(ref document, item.itemname, "", item.itemvalue, false);
|
||||
CLMReplaceBookmarkContent(ref document, item.bmstart,"", item.itemvalue, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -254,7 +254,11 @@ namespace DOCGEN.Klassen
|
||||
case "18":
|
||||
try
|
||||
{
|
||||
ReplaceBookmarkContent(ref document, item.itemname, "", item.itemvalue, false);
|
||||
if (item.bmstart != "")
|
||||
{
|
||||
int a = 1;
|
||||
}
|
||||
CLMReplaceBookmarkContent(ref document, item.bmstart,item.bmstart, item.itemvalue, false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -2677,7 +2681,74 @@ namespace DOCGEN.Klassen
|
||||
}
|
||||
}
|
||||
|
||||
public void CLMReplaceBookmarkContent(ref WordDocument document, String bookmark1, String bookmark2, String replacementContent, bool serienbrief)
|
||||
{
|
||||
|
||||
if (bookmark2 == "")
|
||||
{
|
||||
BookmarksNavigator bookmarkNavigatorSingle = new BookmarksNavigator(document);
|
||||
//Move the virtual cursor to the location of the temp bookmark.
|
||||
bookmarkNavigatorSingle.MoveToBookmark(bookmark1);
|
||||
//Replace the bookmark content.
|
||||
bookmarkNavigatorSingle.ReplaceBookmarkContent(replacementContent, true);
|
||||
bookmarkNavigatorSingle = null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Temp Bookmark.
|
||||
String tempBookmarkName = "tempBookmark";
|
||||
|
||||
#region Insert bookmark start after bookmark1.
|
||||
//Get the bookmark instance by using FindByName method of BookmarkCollection with bookmark name.
|
||||
Bookmark firstBookmark = document.Bookmarks.FindByName(bookmark1);
|
||||
//Access the bookmark end’s owner paragraph by using bookmark.
|
||||
|
||||
//BookmarksNavigator bmn = new BookmarksNavigator(document);
|
||||
//bmn.MoveToBookmark(bookmark1);
|
||||
//TextBodyPart tbp = bmn.GetBookmarkContent();
|
||||
|
||||
////SHU
|
||||
//string bookmarkText = ((Syncfusion.DocIO.DLS.WParagraph)tbp.BodyItems.FirstItem).Text;
|
||||
//if (bookmarkText.Trim() == "" || bookmarkText.Trim()!=replacementContent.Trim()) { bmn.InsertText(replacementContent); return; }
|
||||
|
||||
WParagraph firstBookmarkOwnerPara = firstBookmark.BookmarkEnd.OwnerParagraph;
|
||||
//Get the index of bookmark end of bookmark1.
|
||||
int index = firstBookmarkOwnerPara.Items.IndexOf(firstBookmark.BookmarkEnd);
|
||||
//Create and add new bookmark start after bookmark1.
|
||||
BookmarkStart newBookmarkStart = new BookmarkStart(document, tempBookmarkName);
|
||||
firstBookmarkOwnerPara.ChildEntities.Insert(index + 1, newBookmarkStart);
|
||||
#endregion
|
||||
|
||||
#region Insert bookmark end before bookmark2.
|
||||
//Get the bookmark instance by using FindByName method of BookmarkCollection with bookmark name.
|
||||
Bookmark secondBookmark = document.Bookmarks.FindByName(bookmark2);
|
||||
//Access the bookmark start’s owner paragraph by using bookmark.
|
||||
WParagraph secondBookmarkOwnerPara = secondBookmark.BookmarkStart.OwnerParagraph;
|
||||
//Get the index of bookmark start of bookmark2.
|
||||
index = secondBookmarkOwnerPara.Items.IndexOf(secondBookmark.BookmarkStart);
|
||||
//Create and add new bookmark end before bookmark2.
|
||||
BookmarkEnd newBookmarkEnd = new BookmarkEnd(document, tempBookmarkName);
|
||||
secondBookmarkOwnerPara.ChildEntities.Insert(index, newBookmarkEnd);
|
||||
#endregion
|
||||
|
||||
#region Select bookmark content and replace.
|
||||
//Create the bookmark navigator instance to access the newly created bookmark.
|
||||
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
|
||||
//Move the virtual cursor to the location of the temp bookmark.
|
||||
bookmarkNavigator.MoveToBookmark(tempBookmarkName);
|
||||
//Replace the bookmark content.
|
||||
bookmarkNavigator.ReplaceBookmarkContent(replacementContent, true);
|
||||
#endregion
|
||||
|
||||
#region Remove that temporary bookmark.
|
||||
//Get the bookmark instance by using FindByName method of BookmarkCollection with bookmark name.
|
||||
Bookmark bookmark = document.Bookmarks.FindByName(tempBookmarkName);
|
||||
//Remove the temp bookmark named from Word document.
|
||||
document.Bookmarks.Remove(bookmark);
|
||||
bookmarkNavigator = null;
|
||||
#endregion
|
||||
}
|
||||
|
||||
public void ReplaceBookmarkContent(ref WordDocument document, String bookmark1, String bookmark2, String replacementContent, bool serienbrief)
|
||||
{
|
||||
@@ -2690,6 +2761,7 @@ namespace DOCGEN.Klassen
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Temp Bookmark.
|
||||
String tempBookmarkName = "tempBookmark";
|
||||
|
||||
Reference in New Issue
Block a user