Free Support Forum - aspose.com

How may i retrieve all merge fields between one pair TableStart and TableEnd?

Please, help me: i want to build xml with all merge fields in document in parent-child view. For this i need to retrieve all merge fields between one pair TableStart and TableEnd as childs of the tag




How may i do this? Is any functins or way for this?

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Unfortunately, there is no direct way to populate nested regions using Aspsoe.Words. It is possible, however, to generate the above reports by performing mail merge several times and building up a resulting document from several documents or fragments. The Product Catalog and Sales Invoice samples in the demo project supplied with Aspose.Words demonstrate the suggested techniques.

http://www.aspose.com/demos/file-format-components/aspose.words/csharp/general/product-catalog.aspx

Hope this helps.

Best regards.

Unfortunately it a bit another:(

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Could you please provide me your template, sample data and desired output. I will investigate the issue and try to help you to find a solution.

Best regards.

I am sorry, maybe, I has not clearly asked a question, but you have not understood me.

I have a word file with merge fields. Example:

  • Fields “First Name”, “Last Name”
  • small table with next filelds: “TableStart:Orders” and “TableEnd:Orders” and 2 columns with 2 merge fields “Order Number” and "Order Sum"
  • just flow text with filelds: “TableStart:Product” and
    “TableEnd:Product” and 2 merge fields between them “Product Number” and “Product Sum”.
I want to receive (created instance of Document class from my word file by aspose.word: Document doc = new Document(System.IO.Path.Combine(DocPath, “myDoc.doc”));) a xml-structure of all merge fields in douments in next view:















Please, how can i do this?

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I think, you can try using code like the following:

// Open document

Document doc = new Document(@"Test001\in.doc");

// Get list of mergefields in the document

string[] names = doc.MailMerge.GetFieldNames();

// Create XML writer

using (XmlTextWriter xmlWriter = new XmlTextWriter(@"Test001\out.xml", Encoding.UTF8))

{

xmlWriter.Formatting = Formatting.Indented;

xmlWriter.WriteStartElement("Fields");

// Loop throught all mergefields and build structure of mergefields.

foreach (string name in names)

{

if (name.ToLower().StartsWith("tablestart"))

{

xmlWriter.WriteStartElement("Table");

xmlWriter.WriteAttributeString("name", name.Substring(name.IndexOf(":") + 1));

}

else if(name.ToLower().StartsWith("tableend"))

{

xmlWriter.WriteEndElement();

}

else

{

xmlWriter.WriteStartElement(name);

xmlWriter.WriteEndElement();

}

}

xmlWriter.WriteEndElement();

}

Sample documents are attached. I hope this could help you.

Best regards.

Thank you very much:slight_smile: This is i need:)For my purposes as I thought there are 2 variants of the decision:

1. That you have offered - but I have not been assured
up to the end, that fields inside of a file will always settle down in the necessary order. Especially, if in following versions will get support nested tables
2. transform doc file into xml and go on xml structure in searches of parent-child relations between merge fields

Thank you once again - your answer has dispelled all my doubts

Hello!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

The first approach will work for you. It gives the fields in the order in which they appear in the document, including possible repetitions. By the way, we don’t plan to implement nested mail merge in considerable future.

The second approach will lead to expensive computations if you think about building full document tree in XML and searching among its nodes. You can also convert your DOC file to WordprocessingML format since it is XML-based and contains all information from the source. But I don’t think it’s a good idea.

Regards,

The issues you have found earlier (filed as 39) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(16)