Hi,
we are testing Aspose.Words for a project where we need to import existing HTML snippets into a Word template.
The word template is restricted with regions that accept input.
I can see DocumentBuilder
has some methods MoveToXXX
but not sure which to use to locate the editable regions?
In the document.xml inside the .dotx i can find the different sections. Example below, where content in a docx based on the template seem to end up under <w:permStart .. />
tag
<w:p w14:paraId="52667919" w14:textId="728761D1" w:rsidR="00DA2DA5" w:rsidRPr="00DA2DA5" w:rsidRDefault="00DA2DA5" w:rsidP="00DA2DA5">
<w:pPr>
<w:rPr>
<w:lang w:val="da-DK"/>
</w:rPr>
</w:pPr>
<w:permStart w:id="1271626912" w:edGrp="everyone"/>
</w:p>
Is this something Aspose.Words support, and how would we go about merging the dotx file with an html file per section?
I imagine something like (pseudo code but we will end up using C#)
Get document based on dotx template
Get document builder from template
Detect editable regions
foreach ( region in regions )
Get html snippet
Insert html snippet into region
Save as DOCX
Any suggestions or code samples for this would be greatly appreciated
Anders
@AndersRask You can use the following code to achieve this:
Document doc = new Document(@"C:\temp\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (EditableRangeEnd end in doc.GetChildNodes(NodeType.EditableRangeEnd, true))
{
builder.MoveTo(end);
builder.InsertHtml("<b>Bold text </b><i>Italic text</i>");
}
doc.Save(@"C:\Temp\out.docx");
Hi Alexey
thanx for a fast response!
It seems to work - well almost!
The data seem to end just after the region which looks a bit wonky:

Is it possible to get the data to end up inside the editable bracket?
Anders
@AndersRask Could you please attach your input document here for testing? On my side content is inserted between editable range start and end.
Instruks-RM.zip (17.7 KB)
Sure thing! I have zipped it up and attached it here
@AndersRask In your case EditableRangeEnd
in some cases is on block level (next to paragraph):
You can modify the code like this to get the expected output:
Document doc = new Document(@"C:\Temp\in.dotx");
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (EditableRangeEnd end in doc.GetChildNodes(NodeType.EditableRangeEnd, true))
{
if (end.PreviousSibling != null && end.PreviousSibling.NodeType == NodeType.Paragraph)
builder.MoveTo(end.PreviousSibling);
else
builder.MoveTo(end);
builder.InsertHtml("<b>Bold text </b><i>Italic text</i>");
}
doc.Save(@"C:\Temp\out.docx");
out.docx (18.3 KB)
Thanx for ultra fast reply! Works like a charm! 
That tool, Document Explorer, looks very useful.
I read elsewhere that it was included in installation, but I cant find it here
C:\Program Files (x86)\Aspose\Aspose.Words for .NET
Is there a way to download it?
thanx
Anders
@AndersRask You can get DocumentExplorer sources from our Github.
1 Like