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

Free Support Forum - aspose.com

Insert Text Files (.bat- .ini. txt) into Word Document

Hi,

Im currently playing about with a aspose in Demo Mode which I must say is great, but before I recommend purchasing this tour company I want to be 100% it will do what I need.

currently I have Word document that using VBA code basically does the following...

1. Search and replace < Tags > within the Document

2. Finds Bookmarks < bookmarkFilename > and inserts a file into the this bookmark
In VBA, its just a simple couple of lines......
ActiveDocument.Bookmarks("BookMarkName).Range.Text = _
CreateObject("scripting.filesystemobject").opentextfile(DIRPath + "\filename.txt").ReadAll()

Is there something similar within Aspose ?

Im currently trying to Migrate this VBA code to VB via Visual Studio which is working fine for the Search and replace.

But I'm struggling to find an relevant documentation on how to import plain text files (.bat, .txt., .ini) into the Bookmarks via aspose.

any help or guidance would be much appreciated


Hi there,

Thanks for your inquiry.

Aden:

1. Search and replace < Tags > within the Document

You can achieve this by using Find and Replace feature of Aspose.Words. Please read the detail from here:
http://www.aspose.com/docs/display/wordsnet/Find+and+Replace+Overview
Aden:

2. Finds Bookmarks < bookmarkFilename > and inserts a file into the this bookmark

Please use following code example to achieve your requirements. Hope this helps you.

<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>ZH-CN</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0pt 5.4pt 0pt 5.4pt; mso-para-margin-top:0pt; mso-para-margin-right:0pt; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0pt; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

<![endif]–>

//Load bat, ini, txt document into Aspose.Words DOM

LoadOptions options = new LoadOptions();

options.LoadFormat = LoadFormat.Text;

Document txtDoc = new Document(MyDir + "in.bat", options);

//Load Word document

Document doc = new Document(MyDir + "in.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

//Move cursor to the bookmark

builder.MoveToBookmark("bookmark");

//Insert .bat, .ini, txt document at the position of bookmark

builder.InsertDocument(txtDoc, ImportFormatMode.KeepSourceFormatting);

doc.Save(MyDir + "Out.docx");


I suggest you please read following documentation links for your kind reference.
http://www.aspose.com/docs/display/wordsnet/DocumentBuilder+Overview
http://www.aspose.com/docs/display/wordsnet/Moving+the+Cursor
http://www.aspose.com/docs/display/wordsnet/Inserting+Document+Elements
2) Load your document