We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Insert Structured Document Tag into Paragraph problem

Dear Aspose Team,


when I encountered a problem using aspose would like to ask your help to answer,
I would like to word a paragraph all replaced, and the replacement of a few words into the structured document tag,
but I looked up official file, only to see the need to have the whole structured document tag,
do not know whether we can just put some words into text within a paragraph like the controls, and then ask for your help.

Thank you

P.s1It is my code:

Dim m_strInputDir As String = HttpContext.Current.Server.MapPath("~\Report\Template\AsposeWordTestv1.docx")
Dim m_strOutputDir As String = HttpContext.Current.Server.MapPath("~\Report\AsposeWordTestv1.docx")
'1.get .doc temple
Dim doc As New Document(m_strInputDir)
'2.get Paragraph all node
Dim NodeCollection As NodeCollection = doc.GetChildNodes(NodeType.Paragraph, True)
'3.How can i into PlainText to Paragraph ?
For Each Paragraph As Paragraph In NodeCollection
If Paragraph.Range.Text.Trim.ToString = “[@INSERT_PARA_TEXT]” Then
Paragraph.RemoveAllChildren()

Dim sdtPlainText As New StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Block)
Dim run As New Run(doc)
run.Text = “NTD_________”
run.Font.Color = Color.Green
Paragraph.AppendChild(run)
sdtPlainText.AppendChild(Paragraph)
doc.AppendChild(sdtPlainText)
End If
Next

'Finally.save doc
doc.Save(m_strOutputDir)

please…Who can help?..

Hi there,

Thanks for your inquiry. Please use following code example to achieve your requirements. Hope this helps you. If you still face problem, please share your input and expected output documents here for our reference. We will then provide you more information about your query along with code.

Dim m_strInputDir As String = MyDir + "in.docx"

Dim m_strOutputDir As String = MyDir + "Out.docx"

'1.get .doc temple

Dim doc As New Document(m_strInputDir)

'2.get Paragraph all node

Dim NodeCollection As NodeCollection = doc.GetChildNodes(NodeType.Paragraph, True)

'3.How can i into PlainText to Paragraph ?

For Each Paragraph As Paragraph In NodeCollection

If Paragraph.Range.Text.Trim.ToString = "[@INSERT_PARA_TEXT]" Then

Paragraph.RemoveAllChildren()

Dim sdtPlainText As New StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline)

sdtPlainText.RemoveAllChildren()

Dim run As New Run(doc)

run.Text = "NTD_________"

run.Font.Color = Color.Green

sdtPlainText.AppendChild(run)

Paragraph.AppendChild(sdtPlainText)

End If

Next

'Finally.save doc

doc.Save(m_strOutputDir)

tahir.manzoor:

Dear tahir.manzoor,
Thank you so much!I did!!!!! :)