update 20260303
This commit is contained in:
@@ -50,6 +50,7 @@ using Logging;
|
||||
|
||||
|
||||
|
||||
|
||||
namespace DOCGEN.Klassen
|
||||
{
|
||||
public class SyncFWord
|
||||
@@ -212,7 +213,34 @@ namespace DOCGEN.Klassen
|
||||
|
||||
switch (item.type.ToString())
|
||||
{
|
||||
|
||||
case "2":
|
||||
foreach (WSection section in document.Sections)
|
||||
foreach (WTextBody textBody in section.ChildEntities)
|
||||
{
|
||||
foreach (WFormField formField in textBody.FormFields)
|
||||
{
|
||||
if (formField.Name == item.field.ToString())
|
||||
{
|
||||
string type = formField.FieldType.ToString();
|
||||
if (type == "FieldFormDropDown")
|
||||
{
|
||||
WDropDownFormField cb = (WDropDownFormField)formField;
|
||||
if (item.itemvalue.ToString().ToUpper() != "")
|
||||
{
|
||||
int i = 0;
|
||||
foreach (WDropDownItem wd in cb.DropDownItems)
|
||||
{
|
||||
wd.Text = "";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
ReplaceBookmarkContent(ref document, item.itemname, "", item.itemvalue, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "4":
|
||||
case "7":
|
||||
case "8":
|
||||
@@ -413,10 +441,19 @@ namespace DOCGEN.Klassen
|
||||
//Iterates through form fields
|
||||
foreach (WFormField formField in textBody.FormFields)
|
||||
{
|
||||
if (formField.Name.ToString().ToUpper() == item.field.ToString().ToUpper() || formField.Name.ToString().ToUpper() == item.bmstart.ToString().ToUpper())
|
||||
string name = formField.Name;
|
||||
if (name=="") { name = item.bmstart.ToString(); }
|
||||
if (name != "")
|
||||
{
|
||||
formField.Text = item.itemvalue;
|
||||
break;
|
||||
if (formField.Name.ToString().ToUpper() == item.field.ToString().ToUpper() || formField.Name.ToString().ToUpper() == item.bmstart.ToString().ToUpper())
|
||||
{
|
||||
if (item.itemvalue == "Heidi Muster")
|
||||
{
|
||||
string a = "1";
|
||||
}
|
||||
formField.Text = item.itemvalue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -424,6 +461,67 @@ namespace DOCGEN.Klassen
|
||||
|
||||
}
|
||||
|
||||
private IWTable CreateTableAtBookmark(BookmarksNavigator navigator, WordDocument document)
|
||||
|
||||
{
|
||||
|
||||
var bookmarkStart = navigator.CurrentBookmark?.BookmarkStart;
|
||||
|
||||
|
||||
|
||||
if (bookmarkStart != null)
|
||||
|
||||
{
|
||||
|
||||
var paragraph = bookmarkStart.OwnerParagraph;
|
||||
|
||||
|
||||
|
||||
if (paragraph != null)
|
||||
|
||||
{
|
||||
|
||||
if (paragraph.ChildEntities.Count > 0)
|
||||
|
||||
{
|
||||
|
||||
paragraph.ChildEntities.Clear(); // Remove existing content but keep the paragraph structure
|
||||
|
||||
}
|
||||
|
||||
//Get index of paragraph in the textBody which contains BookmarkStart
|
||||
|
||||
int index = paragraph.OwnerTextBody.ChildEntities.IndexOf(paragraph);
|
||||
|
||||
WTable table = new WTable(document);
|
||||
|
||||
//Insert table next to that paragraph
|
||||
// paragraph.OwnerTextBody.ChildEntities.RemoveAt(index+1);
|
||||
paragraph.OwnerTextBody.ChildEntities.Insert(index + 1 , table);
|
||||
|
||||
return table;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// If the bookmark's owner is a text body, add the table there
|
||||
|
||||
//if (bookmarkStart.Owner is IWTextBody textBodyFallback)
|
||||
|
||||
//{
|
||||
|
||||
// return textBodyFallback.AddTable();
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
private void Insert_CLMTable(CLMDocItem item, ref WordDocument document)
|
||||
{
|
||||
|
||||
@@ -484,8 +582,13 @@ namespace DOCGEN.Klassen
|
||||
|
||||
//Bookmark bookmark = document.Bookmarks.FindByName(bm);
|
||||
//WSection section = GetOwnerEntity(bookmark.BookmarkStart) as WSection;
|
||||
IWTable table = new WTable(document);
|
||||
//IWTable table = section.AddTable();
|
||||
TextBodyPart part = bookmarkNavigator.GetBookmarkContent();
|
||||
|
||||
part.Clear();
|
||||
//IWTable table = new WTable(document);
|
||||
IWTable table = CreateTableAtBookmark(bookmarkNavigator, document);
|
||||
|
||||
|
||||
|
||||
if (headers.Count > 0 && headers.Count == dt.Columns.Count)
|
||||
{
|
||||
@@ -590,7 +693,9 @@ namespace DOCGEN.Klassen
|
||||
|
||||
}
|
||||
catch { }
|
||||
bookmarkNavigator.InsertTable(table);
|
||||
// bookmarkNavigator.InsertTable(table);
|
||||
bookmarkNavigator = null;
|
||||
//IWTable table = section.AddTable();
|
||||
//bookmark = null;
|
||||
//section = null;
|
||||
table = null;
|
||||
|
||||
Reference in New Issue
Block a user