Note that there are some explanatory texts on larger screens.

plurals
  1. POData being inputted at end of line of the bookmark in MS Word not where it should be
    text
    copied!<p>I'm inputting data from the database to bookmarks in MS Word, every data is inputted right but the problem is that the data's location is inputted - for each related bookmark - at the end of the line and not where I added the bookmark, and I don't know why it's doing that! I'm using opemXml on C#</p> <h2><strong>Update</strong></h2> <pre><code> // Get the main document part (document.xml). foreach (System.IO.Packaging.PackageRelationship documentRelationship in package.GetRelationshipsByType(documentRelationshipType)) { NameTable nt = new NameTable(); nsManager = new XmlNamespaceManager(nt); nsManager.AddNamespace("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"); Uri documentUri = PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative), documentRelationship.TargetUri); documentPart = package.GetPart(documentUri); #region Update Document Bookmarks //Get document xml XmlDocument xdoc = new XmlDocument(); //xdoc.Load(documentPart.GetStream()); xdoc.Load(documentPart.GetStream(FileMode.Open, FileAccess.Read)); //Select all bookmark nodes XmlNodeList nodeList = xdoc.SelectNodes("//w:bookmarkStart", nsManager); foreach (XmlNode node in nodeList) { if (this.SetBookmarkText(xdoc, node, "DepositNO", GetDepositNO(DepositNo))) continue; if (this.SetBookmarkText(xdoc, node, "AppDate", FormFunctions.Get_Application_Date(DepositNo).ToShortDateString())) continue; if (this.SetBookmarkText(xdoc, node, "Title", FormFunctions.Get_Application_Title(DepositNo, 0))) continue; if (this.SetBookmarkText(xdoc, node, "ApplicantName", Get_Application_CV_Name(AppID, 6))) continue; if (this.SetBookmarkText(xdoc, node, "AgentName", Get_Application_CV_Name(AppID, 7))) continue; if (this.SetBookmarkText(xdoc, node, "Address", Address)) continue; if (this.SetBookmarkText(xdoc, node, "AgentName01", Get_Application_CV_Name(AppID, 7))) continue; if (this.SetBookmarkText(xdoc, node, "Times", Times)) continue; if (this.SetBookmarkText(xdoc, node, "A", A)) continue; if (this.SetBookmarkText(xdoc, node, "B", B)) continue; if (this.SetBookmarkText(xdoc, node, "Approve", Approve)) continue; if (this.SetBookmarkText(xdoc, node, "RequestArabic", RequestArabic)) continue; if (this.SetBookmarkText(xdoc, node, "ExamTime", ExamTime)) continue; if (this.SetBookmarkText(xdoc, node, "Mark", Mark)) continue; if (this.SetBookmarkText(xdoc, node, "Fees", Fees)) continue; if (this.SetBookmarkText(xdoc, node, "Objection", Objection)) continue; if (this.SetBookmarkText(xdoc, node, "Rejection", Rejection)) continue; if (this.SetBookmarkText(xdoc, node, "ExamTime01", ExamTime)) continue; if (this.SetBookmarkText(xdoc, node, "DepositNO01", GetDepositNO(DepositNo))) continue; } #endregion StreamWriter streamPart = new StreamWriter(documentPart.GetStream(FileMode.Open, FileAccess.Write)); xdoc.Save(streamPart); streamPart.Close(); } package.Flush(); package.Close(); //send response to browser string File_Name = destenation + docFileName; //string popupScript = "&lt;script language='javascript'&gt;" + "window.open('" + File_Name + "', 'Document', " + "'width=700, height=600, menubar=yes, resizable=yes')" + "&lt;/script&gt;"; //ClientScript.RegisterClientScriptBlock(this.GetType(), "PopupScriptOffer", popupScript); Response.AddHeader("Content-Disposition", "attachment; filename=" + docFileName); Response.WriteFile(File_Name); Response.End(); </code></pre> <h2>SetBookmarkText function</h2> <pre><code>private bool SetBookmarkText(XmlDocument xdoc, XmlNode node, string bookmarkName, string bookmarkValue) { if (node.NextSibling.Name.ToString() == "w:bookmarkEnd") { if (node.Attributes["w:name"].Value == bookmarkName) { //get the node previous sibling style ("w:rPr") to apply to the bookmark text XmlNode nodeStyle = node.PreviousSibling.CloneNode(true); //parent node "w:p" XmlNode bookmrkParent = node.ParentNode; XmlElement tagRun; tagRun = xdoc.CreateElement("w:r", nsManager.LookupNamespace("w")); bookmrkParent.AppendChild(tagRun); if (nodeStyle.SelectSingleNode("//w:rPr", nsManager) != null) tagRun.AppendChild(nodeStyle.SelectSingleNode("//w:rPr", nsManager)); XmlElement tagText; tagText = xdoc.CreateElement("w:t", nsManager.LookupNamespace("w")); tagRun.AppendChild(tagText); //*** insert text into part as a Text node XmlNode nodeText; nodeText = xdoc.CreateNode(XmlNodeType.Text, "w:t", nsManager.LookupNamespace("w")); nodeText.Value = bookmarkValue; tagText.AppendChild(nodeText); return true; } } return false; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload