0
Good guys, I’m having a problem that is disturbing me a little, I’ve searched about and found nothing to help me.
I’m researching certain variables in one Word Template to be able to perform a substitution. The problem occurs when some variables are broken into several Runs, for example:
NT: In this image it is clear that the variable municipio_acronym is broken in two Runs, being the Run1 => munici, and the Run2 => pio_acronym, So when searching it complete (municipio_acronym) will not return any result.
Edit1: Here’s an example of the code:
//Pegando os cabeçalhos
SearchAndReplace(partLists: document.MainDocumentPart.HeaderParts, target: "<municipio_sigla>", replace: municipio.Sigla);
//Método que procura e substitui as variáveis:
private static void SearchAndReplace<T>(IEnumerable<T> partLists, string target, string replace) where T : OpenXmlPart
{
foreach (var part in partLists)
{
foreach (var currentParagraph in part.RootElement.Descendants<DocumentFormat.OpenXml.Wordprocessing.Paragraph>())
{
foreach (var currentRun in currentParagraph.Descendants<DocumentFormat.OpenXml.Wordprocessing.Run>())
{
foreach (var currentText in currentRun.Descendants<DocumentFormat.OpenXml.Wordprocessing.Text>())
{
if (currentText.Text.Contains(target))
{
currentText.Text = currentText.Text.ReplaceInsensitive(target, replace);
}
}
}
}
}
}
Has anyone ever faced such a thing? And if so, is there any solution?
It will be easier to help if you edit the question, including your code.
– Leandro Angelo
'Cause it’s kkkkkkk. One moment.
– Márcio Cristian
@Leandroangelo, ready. I added an example code.
– Márcio Cristian