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

Free Support Forum - aspose.com

Code to modify word document in asp.net 2.0 c#

regarding modifying word document

i.e. adding some value in place of merge field

also to add watermark,header/footer

adding logo

etc

i got some information that aspose provide sol for thisregarding modifying word document

i.e. adding some value in place of merge field

also to add watermark,header/footer

adding logo

etc

i got some information that aspose provide sol for this.Please help.

Hi there,

Thanks for your inquiry. 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/Inserting+Document+Elements
http://www.aspose.com/docs/display/wordsnet/Moving+the+Cursor

ddbhutada:

also to add watermark,header/footer

How to Create Headers Footers using DocumentBuilder
How to Add a Watermark to a Document
ddbhutada:

i.e. adding some value in place of merge field

Please read following documentation links about mail merge.
http://www.aspose.com/docs/display/wordsnet/About+Mail+Merge+in+Aspose.Words
http://www.aspose.com/docs/display/wordsnet/Simple+Mail+Merge+Explained
http://www.aspose.com/docs/display/wordsnet/How+to++Execute+Simple+Mail+Merge

Hope this answers your query. Please let us know if you have any more queries.

Dear Tahir ,

Thanks for ypur reply ,can u please provide sample code in c# for finding and replacing merge field in word document.

Hi there,

Thanks for your inquiry. Following code example perform a simple insertion of data into merge fields.


// Open an existing document.

Document doc = new Document(MyDir + "MailMerge.ExecuteArray.doc");

// Fill the fields in the document with user data.

doc.MailMerge.Execute(

new string[] { "FullName", "Company", "Address", "Address2", "City" },

new object[] { "James Bond", "MI5 Headquarters", "Milbank", "", "London" });

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


<!–[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>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>AR-SA</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</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:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; 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]–>If you do not want to use mail merge execute method, please use the DocumentBuilder.MoveToMergeField
method to move the cursor to a position just beyond the specified
merge field and removes the merge field. After moving the cursor, please
write the contents using DocumentBuilder.Write method.


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

DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToMergeField("FullName");

builder.Write("James Bond");

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


Following code example iterate through all
fields and replace the mail merge fields with mail merge field name. You can insert the contents according to your requirements at the position of mail merge field.


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

DocumentBuilder builder = new DocumentBuilder(doc);

foreach (Field field in doc.Range.Fields)

{

if (field.Type == FieldType.FieldMergeField)

{

String[] fieldcodes = field.GetFieldCode().Trim().Split(new Char[] { ' ' });

if (fieldcodes[2] != "")

{

builder.MoveToMergeField(fieldcodes[2], false, false);

builder.Write(fieldcodes[2]);

}

}

}

doc.MailMerge.DeleteFields();

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



Hope this answers your query. Please let us know if you have any more queries.