/// <summary> /// Insert a content controls and maps Customer details to it. /// </summary> /// <param name="document">Word document instance.</param> /// <param name="customerNode">CustomXMLNode of customer.</param> /// <param name="docIOxmlPart">CustomXMLPart instance.</param> /// <param name="empPath">Current employee index.</param> /// <param name="custIndex">Current customer index.</param> private void InsertAndMapCustomer(WordDocument document, CustomXMLNode customerNode, CustomXMLPart docIOxmlPart, string empPath, int custIndex) { //Column names of Customer element. string[] customersDetails = { "Customer ID", "Employee ID", "Company Name", "Contact Name", "City", "Country" }; document.LastSection.AddParagraph(); //Adds new paragraph to the section IWParagraph paragraph = document.LastSection.AddParagraph(); paragraph.ParagraphFormat.BackColor = Syncfusion.Drawing.Color.Green; paragraph.ParagraphFormat.LeftIndent = 72; IWTextRange textrange = paragraph.AppendText("Customers"); textrange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.White; textrange.CharacterFormat.Bold = true; textrange.CharacterFormat.FontSize = 14; int orderIndex = 1; int custChild = 0; bool isFirstOrder = true; string customerXpath = empPath + "Customers[" + custIndex + "]/"; foreach (CustomXMLNode customerChild in customerNode.ChildNodes) { if (customerChild.HasChildNodes()) { //Insert a content controls and maps Orders details to it. InsertAndMapOrders(document, customerChild, docIOxmlPart, customerXpath, orderIndex, isFirstOrder); document.LastSection.AddParagraph(); isFirstOrder = false; orderIndex++; } else { //Insert a content controls and maps Customer details other than Order details to it. paragraph = document.LastSection.AddParagraph(); paragraph.ParagraphFormat.LeftIndent = 72; paragraph.AppendText(customersDetails[custChild] + ": "); MapCustomXMLPart(paragraph, customerXpath + customersDetails[custChild].Replace(" ", ""), docIOxmlPart); } custChild++; } }
private static XmlNode GetSpecificCustomXmlRootNode(CustomXMLPart xmlPart) { if (xmlPart == null) { throw new ArgumentNullException(); } CustomXMLNode xmlNode = xmlPart.SelectSingleNode(XmlPartContentNodePath); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlNode.Text); XmlNode root = xmlDoc.SelectNodes("/*")[0]; return(root); }
/// <summary> /// Inserts content control and maps the employee details to it. /// </summary> /// <param name="document">Word document instance.</param> /// <param name="employeesNode">CustomXMLNode of employee.</param> /// <param name="rootXmlPath">Custom XML root Xpath.</param> /// <param name="docIOxmlPart">CustomXMLPart instance.</param> /// <param name="empIndex">Current employee index.</param> private void InsertAndMapEmployee(WordDocument document, CustomXMLNode employeesNode, string rootXmlPath, CustomXMLPart docIOxmlPart, int empIndex) { //Column names of Employee element. string[] employeesDetails = { "FirstName", "LastName", "Employee ID", "Extension", "Address", "City", "Country" }; int empChildIndex = 0; int customerIndex = 1; // Append current empolyee XPath with root XPath. string empPath = "/" + rootXmlPath + "/Employees[" + empIndex + "]/"; // Iterating child elements of Employee foreach (CustomXMLNode employeeChild in employeesNode.ChildNodes) { IWParagraph paragraph = document.LastParagraph; if (employeeChild.HasChildNodes()) { //Insert a content controls and maps Customer details to it. InsertAndMapCustomer(document, employeeChild, docIOxmlPart, empPath, customerIndex); customerIndex++; } else { if (empChildIndex != 1) { //Insert a content controls and maps Employee details other than Customer details to it. paragraph = document.LastSection.AddParagraph(); if (empChildIndex == 0) { paragraph.AppendText("Name: "); } else { paragraph.AppendText(employeesDetails[empChildIndex] + ": "); } } else { paragraph.AppendText(" "); } MapCustomXMLPart(paragraph, empPath + employeesDetails[empChildIndex].Replace(" ", ""), docIOxmlPart); } empChildIndex++; } }
public ContentControls SelectLinkedControls(CustomXMLNode Node) { throw new System.NotImplementedException(); }