i have the need to put one or more customer's data on a document with the given template:
- Code: Select all
{CUSTOMERS_INFORMATION}
{CUSTOMER_NAME}
{CUSTOMER_DOCUMENT_ID}
{CUSTOMER_SPOUSE_INFORMATION}
{CUSTOMER_SPOUSE_NAME}
{CUSTOMER_SPOUSE_DOCUMENT_ID}
{/CUSTOMER_SPOUSE_INFORMATION}
{/CUSTOMERS_INFORMATION}
For this i need to do the following tasks:
1) Search for the first {CUSTOMERS_INFORMATION}(...){/CUSTOMERS_INFORMATION} block in the document;
This was done with the following code:
- Code: Select all
string strRegexTagGroup =
@"\{{(?<tagName>{0})\}}(?<tagContent>.+?)\{{/\k<tagName>\}}";
var regexTagGroup = new Regex(
string.Format(strRegexTagGroup, "CUSTOMERS_INFORMATION"),
RegexOptions.Singleline);
var selection = document.FindPattern(regexTagGroup);
2) Copy that block's content (without the {CUSTOMERS_INFORMATION} begin and end parts), in case there's more than one customer;
Question: This can be done with this line?
- Code: Select all
var copy = selection.GetAsOneRange().Clone()
3) Replace the tags {CUSTOMER_NAME} and {CUSTOMER_DOCUMENT_ID} within that block with their respective data;
Question: The previous "selection" variable doesn't expose a Replace method. How can i do the replace on that specific text block?
4) Search for the {CUSTOMER_SPOUSE_INFORMATION}(...){/CUSTOMER_SPOUSE_INFORMATION} inside the "selection" block and replace the respective tags;
If the customer doesn't have spouse information, delete that particular block from the document;
Question: Again, the "selection" variable don't have a FindPattern method. How this can be achieved?
5) If there's more than one customer, insert the "copy" at the end of the block (just before {/CUSTOMERS_INFORMATION});
Repeat the replacing process on steps 3 and 4;
Question: How is the "copy" data be appended at the end of the "selection" block?
Any help is welcome.
Thanks in advance.
EDIT: I'm currently using the Free version of Spire.Doc