Work in a WPF application with Office Viewer Component

You need add a UserControl.

Then inser the Com Component in it.

There is a Edraw Office Viewer Component WPF sample project. You can referent it at the following install folder.

How do i use InsertBreak and ReplaceText in Office Viewer Component

The ReplaceText method can not do it.

You maybe use the ms word automation to realize it.

The component can get the msword::_Application interface. Then you can do the automation.

For examples in VC:

word::_Application wd;
wd.AttachDispatch(app, FALSE);
if(wd == 0){
return FALSE;
BOOL bFindHeader = FALSE;
BOOL bFindBody = FALSE;
BOOL bFindFooter = FALSE;
word::Window win = wd.GetActiveWindow();
word::Pane pane =  win.GetActivePane();
word::View vw = pane.GetView();
vw.SetSeekView(9);//wdSeekCurrentPageHeader =9
word::Selection sel = wd.GetSelection();
word::Find fd = sel.GetFind();
vText.vt = VT_BSTR; vText.bstrVal = strText.AllocSysString();
VARIANT vMatchCase;
vMatchCase.vt = VT_BOOL; vMatchCase.boolVal = MatchCase?VARIANT_TRUE:VARIANT_FALSE;
VARIANT vMatchWholeWord;
vMatchWholeWord.vt = VT_BOOL; vMatchWholeWord.boolVal = MatchWholeWord?VARIANT_TRUE:VARIANT_FALSE;
vFalse.vt = VT_BOOL; vFalse.boolVal = VARIANT_FALSE;
vTrue.vt = VT_BOOL; vTrue.boolVal = VARIANT_TRUE;
vWrap.vt = VT_I4; vWrap.lVal = long(1);
VARIANT vRelpaceAll;
vRelpaceAll.vt = VT_I4; vRelpaceAll.lVal = long(2);
VARIANT vReplaceText;
vReplaceText.vt = VT_BSTR; vReplaceText.bstrVal = strReplaceText.AllocSysString();
bFindHeader = fd.Execute(&vText, &vMatchCase, &vMatchWholeWord, &vFalse, &vFalse, &vFalse, &vTrue,
&vWrap, &vFalse, &vReplaceText, &vRelpaceAll);

How to disable the buttons in the QAT

There are not methods to disable the icons at the quick ribbon bar.

You maybe hide the whole ribbon title bar with the following setting.

AxEDOffice1.ShowRibbonTitlebar (false)

Or you need use the macro to hide the quick ribbon bar in the ms office 2013.

Protect word document from changes

Edraw Word Viewer Component added the ProtectDoc method which helps to protect the specified document from changes. When a document is protected, users can make only limited changes, such as adding annotations, making revisions, or completing a form.

boolean ProtectDoc(WdProtectType ProtectType, [in, optional]
VARIANT Password);
ProtectType: The protection type for the specified document. WdProtectionType.
Password: Optional Object. The password required to remove protection from the specified
enum WdProtectType
wdAllowOnlyRevisions = 0,
wdAllowOnlyComments = 1,
wdAllowOnlyFormFields = 2,
wdAllowOnlyReading = 3,
wdNoProtection = -1,
The following vb script shows how to protect a document for only revisions.
Sub ProtectDoc_Example()
edword.ProtectDoc 0
End Sub

Add some text at the end of Word document

How to add some text at the end of document that is opened in Edraw office viewer, Kindly send me java script code so that i can enter signatures in my document. Please reply as soon as possible and send my java script Example.

Play slideshow in the same window

Edraw Office Viewer Component provides a solution for opening then playing the slideshow file in the same window. Of course you can play it with full screen mode too.

Simply call the “SlideShowOpenAndPlay” method, you can get the follow effect immediately.

PowerPoint Viewer ActiveX Control

You can show or hide the titlebar, screenbar, toolbar too.

You can call it via javascript or vbscript in your html page as follow.

document.OA1.SlideShowOpenAndPlay(““, false, false, false, false);


OA1.Open(“http://www…./sample.pps“, “PowerPoint.Slide”);

OA1.SlideShowPlay(false, false, true, false);

[id(99), helpstring("Opens then plays the PowerPoint slide show file in the same window or full screen.")]
HRESULT SlideShowOpenAndPlay([in] VARIANT Document, [in] VARIANT_BOOL bFullScreen, [in] VARIANT_BOOL bShowWebToolbar, [in] VARIANT_BOOL bLoopUntilStopped, [in] VARIANT_BOOL bShowScrollBar, [in, optional] VARIANT WebUsername, [in, optional] VARIANT WebPassword);

[id(100), helpstring("Plays the PowerPoint slide show file in the same window or full screen.")]
HRESULT SlideShowPlay([in] VARIANT_BOOL bFullScreen, [in] VARIANT_BOOL bShowWebToolbar, [in] VARIANT_BOOL bLoopUntilStopped, [in] VARIANT_BOOL bShowScrollBar);

Replace words in Office ActiveX Control

In my ASPX page I want to find and replace some predefined words. I am
using the following code, but it say objWord.Selection is not there. (
where as this is supported by word )
Set objWord = document.OA1.GetApplication
Set objSelection = objWord.Selection
objSelection.Find.Text = varFind
objSelection.Find.Replacement.Text = varReplace
objSelection.Find.Forward = True
objSelection.Find.Wrap = wdFindContinue
objSelection.Find.Format = False
objSelection.Find.MatchCase = False
objSelection.Find.MatchWholeWord = False
objSelection.Find.MatchWildcards = False
objSelection.Find.MatchSoundsLike = False
objSelection.Find.MatchAllWordForms = False
Please let me know how can I find and replace word in the client side
word with OA1 activeX.

Inserts text content to opened Word file programmatically

boolean InsertText([in] BSTR Text, [in, optional] VARIANT
Inserts text content to opened Word file.
Text: The text string need to be inserted.
InDocPos: The insert position. WdInPocPos.
enum WdInDocPos
wdInDocumentPosCursor = 1,
wdInDocumentPosStart = 2,
wdInDocumentPosEnd = 3 ,

How to insert HTML table into Word doc using Javascript?

Use Edraw Office Viewer Component or Word Viewer Component to get the Document interface, then you can do it by the office automation.

var objWord = document.OA1.ActiveDocument;
var range = objWord.Range(0,0);
var WTable = objWord.Tables.Add(range, 3,3);
WTable.Cell(1,1).Range.Font.Name = “Times New Roman”;

WTable.Cell(1,1).Range.Text = “examples 1″;
WTable.Cell(1,2).Range.Font.Size = 18;
WTable.Cell(1,2).Range.Bold = true;
WTable.Cell(1,2).Range.Font.Italic = true;
WTable.Cell(1,2).Range.Text = “examples 2″;
WTable.Cell(2,1).Range.ParagraphFormat.Alignment = 1; // 0= Left, 1=Center, 2=Right
WTable.Cell(2,1).Range.Font.Name = “Arial”;
WTable.Cell(2,1).Range.Font.Size = 12;
WTable.Cell(2,1).Range.Bold = false;
WTable.Cell(2,1).Range.ParagraphFormat.Alignment = 2;
WTable.Cell(3,3).Range.Font.Name = “Times New Roman”;
WTable.Cell(3,3).Range.Font.Size = 14;
WTable.Cell(3,3).Range.Bold = true;
WTable.Cell(3,3).Range.Font.Underline = true;
WTable.Cell(3,3).Range.ParagraphFormat.Alignment = 0;
WTable.Cell(3,2).Range.Text = “examples 3″

Embedding ms office in C# Forms

With Edraw Office Viewer Component, it’s easy to embed the ms office program in c# froms or html pages. Only drag it to your form, you can call some method to do the office automation directly such create a Word document or initialize an Excel sheet.

1. Download Edraw Office Viewer Component then install it. Or you can register the officeviewer.ocx using regsvr32 command.
  C:\\WINNT\System32\regsvr32 OfficeVidewer.ocx
2. On successful registration you would get message dialog.
3. Add Office Viewer Active-X control on your form through customize toolbox window.
4. Drag and drop component from toolbox on your form and resize as per requirement.
5. Now add reference for “Microsoft Word Object Library 11.0″ from add reference on solution explorer. Here I am using Word 2003, so object library version is 11.0.
6. You can see all added reference on solution explorer as shown in figure. Two reference has been added for Edraw Office Viewer  Component (AxOfficeViewer and OfficeViewer) and three libraries for Office & Word (Microsoft.Office.Core and Office and Word).
7. Define a variable for word document in public section of form as
   public Word.Document oDoc;
8. Add following code for button click event
private void button1_Click(object sender, System.EventArgs e)
     //Remove Office Viewer Component Title Bar and create a new Word document
     axOfficeViewer1.Titlebar = false;
     //Invoke Word properties
     oDoc = (Word.Document)axOfficeViewer1.ActiveDocument;
     oDoc.ActiveWindow.View.Type = Word.WdViewType.wdOutlineView;
     oDoc.ActiveWindow.DisplayRulers = false;
     oDoc.ActiveWindow.DisplayScreenTips = false;
     oDoc.ActiveWindow.DisplayHorizontalScrollBar = false;
     oDoc.ActiveWindow.DisplayVerticalRuler = false;
     oDoc.ActiveWindow.DisplayVerticalScrollBar = true;
10. Now you can add text, format it, send mail do all functionalities.
11. You can control all word functionalities to be made available or unavailable programmatically through code with all available objects, properties & Methods of word.