Host multiple Excel and Word components in a form

You can host multiple office component in a form or you can open multiple office instance in your internet explore with Edraw Viewer Component version 7.

The new version 7 has no toolbar-locked issues with multiple instances of Word or excel opened in several tabs or even inside single form.

Note: you need set the Frame hook policy as SetOnFirstOpen and Component activation policy as KeepUIActiveOnAppDeactive in the previous version. But it doesn’t work for the IE7 or IE8.

Frame hook policy
To correctly handle activation when the host gains or loses foreground status, the ActiveX control uses a frame hook. By default, the hook is set when the control is created. In some situations, especially when the control is used from a multi-threaded UI host or when the control is nested in a container control like a Tab page in a .NET WinForm application, the parent of the control at create time may not be the correct window for the control to hook when it is running. In these situations, you can use the FrameHookPolicy property to reset the hook at a more suitable time. For example, if you build a .NET WinForm solution, set the FrameHookPolicy property to SetOnFirstOpen in the Properties window.

Component activation policy
The sample control can support more than one instance of itself in a given host application. However, only one control can be active at a given time. This is a requirement of ActiveX Document hosting. To handle multiple instances in a single host, the control registers itself with a component manager. This lets the component manager keep track of the active control. Use the ActivationPolicy property to control how the embedded object is handled during component changes. The ActivationPolicy property can be set to one or more of the bit flags that are defined by the ActivationPolicy enumeration.

Disable the Office Menu

Edraw Office Viewer Components can disable the office main button and protect the opened document was modified by the end users. Only call the DisableFileCommand method in the BeforeDocumentOpen event and set the different enumerates.

boolean DisableFileCommand([in] WdUIType UIType, [in]
boolean Disable);
UIType: The enum type need to disable in the UI. WdUIType.
Disable: True to disable the command button or menu item.
enum WdUIType
{
wdUIDisalbeOfficeButton = 0×00000001,
wdUIDisalbeNew = 0×00000002,
wdUIDisalbeOpen = 0×00000004,
wdUIDisalbeUpgradeDocument = 0×00000008,
wdUIDisalbeSave = 0×00000010,
wdUIDisalbeSaveAs = 0×00000020,
wdUIDisalbeSendAsAttachment = 0×00000040,
wdUIDisalbeClose = 0×00000100,
wdUIDisalbePrint = 0×00000200,
wdUIDisalbePrintQuick = 0×00000400,
wdUIDisalbePrintPreview = 0×00000800,
wdUIDisalbeSaveAsMenu = 0×00001000,
wdUIDisalbePrepareMenu = 0×00002000,
wdUIDisalbePermissionRestrictMenu = 0×00004000,
wdUIDisalbeSendMenu = 0×00008000,
wdUIDisalbePublishMenu = 0×00010000,
wdUIDisalbeServerTasksMenu = 0×00020000,
wdUIDisalbeCopyButton = 0×00040000,
wdUIDisalbeCutButton = 0×00080000,
wdUIHideMenuHome = 0×01000000,
wdUIHideMenuInsert = 0×02000000,
wdUIHideMenuPageLayout = 0×04000000,
wdUIHideMenuReferences = 0×08000000,
wdUIHideMenuMailings = 0×10000000,
wdUIHideMenuReview = 0×20000000,
wdUIHideMenuView = 0×40000000,
wdUIHideMenuDeveloper = 0×80000000,
wdUIHideMenuAddIns = 0×00100000,
wdUIHideMenuFormat = 0×00200000,
wdUIHideMenuEdit = 0×00400000,
wdUIHideMenuTool = 0×00800000,
}WdUIType;
Note: The component disabled the Office menu, New button and Open
button in default.
DWORD dwDisableCommand = wdUIDisalbeOfficeButton |
wdUIDisalbeNew| wdUIDisalbeOpen;
The function need be set in the BeforeDocumentOpened event.
If you want to enable the three button, follow the samples.
Example
The following vb script shows how to enable the office main menu, new button and open
button.
Sub DocumentOpenedEvent ()
Edword.DisableFileCommand 1 , false ‘wdUIDisalbeOfficeButton
Edword.DisableFileCommand 2 , false ‘wdUIDisalbeNew
Edword.DisableFileCommand 4 , false ‘wdUIDisalbeOpen
End Sub
SCRIPT FOR=OA1 EVENT= DocumentOpened ()
DocumentOpenedEvent()
SCRIPT
The following vb script shows how to diable the saveas and save button.
Sub DocumentOpenedEvent ()
Edword.DisableFileCommand 16 , true ‘wdUIDisalbeSave
Edword.DisableFileCommand 32 , true ‘wdUIDisalbeSaveAs
End Sub
SCRIPT FOR=OA1 EVENT= DocumentOpened ()
DocumentOpenedEvent()
SCRIPT

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;
     axOfficeViewer1.CreateNew(“Word.Document”);
     axOfficeViewer1.Activate();
     //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.

 

(Fixed) CloseDoc error in the V7.5.0.331

We are experiencing a problem with the Office Viewer component. We are using it embedded in a browser window (IE7). It is exhibiting some strange behavior under certain conditions.

These are the steps to reproduce:

If you open the browser window that has an instance of the office viewer on it, and use javascript to have the Office viewer open a word document
Have another instance of WORD open in “stand alone” mode and minimize it to the windows toolbar
While the first browser window is opening and loading the WORD document, press on the WORD toolbar icon, so it maximizes and displays on the desktop

If you get the timing exactly right, so you open the minimized document just before the browser embedded version of WORD paints itself, what you get is the two WORD documents are switched. The browser window displays the document that was in the minimized copy of WORD, and the stand alone version of WORD displays the document that should have been displayed in the browser instance.

The automation interface is still manipulating the correct document, even though the document is opened in the wrong container. For example, if you print the document using javascript in the browser, the document that gets printed is the one in the other window.

Have you ever come across this phenomenon?

I tried again, making absolutely sure that it was 7.5.0.331 installed, as you suggested. It is still happening. It is important that you follow the sequence precisely….if you open word before you open the OfficeViewer demo app then everything is OK. If you follow the following steps, it should occur:

1) Reboot your machine

2) Start the OfficeViewer HTML demo app by double clicking on officeviewer.htm in the samples folder. Enable the OCX by choosing: “allow blocked content”

3) Open an existing WORD document in the OfficeViewer App

4) Open a stand alone instance of word, and type a sentence in it.

5) Choose the “close doc” option on the OfficeViewer.htm menu. When the doc closes, instead of seeing an “empty” instance of WORD, you see the “blank” page. This is how you can tell it is going to happen. If you try the next test below, after hitting “Close doc” you will still see there is still an instance of word present with the toolbar, but no document..

6) Close the browser window (using the x). the stand alone instance of WORD will close, along with the browser window.

Clearly, in the above example, what has happened is the OfficeViewer has gotten mixed up, and is internally pointing to the stand alone instance of WORD, instead of the instance of word it was housing. So when the browser window closed, it shut down WORD as well.

If you try the following sequence, you will not see the stand alone instance of Office close:

Test 2:

1) Reboot your machine

2) Open a stand alone instance of word and minimize it to the task bar

3) Start the OfficeViewer HTML demo app by double clicking on officeviewer.htm in the samples folder. Enable the OCX by cohoosing: “allow blocked content”

4) Open an existing WORD document in the OffiveViewer App

5) Open a stand alone instance of word, and type a sentence in it.

6) Choose the “close doc” option on the OfficeViewer.htm menu. When the doc closes, unlike in the test above, you will still see WORD open with its toolbar, but no document.

7) Close the browser window (using the x). the browser window will close, but the stand alone instance of WORD will stay open

Clearly, having an instance of WORD open before you instantiate the OfficeViewer seems to keep the instance pointers correct. In fact, in some situations, “windowless” WINWORD.EXE processes are left running by OfficeViewer, and if one of those is running, then the problem will not occur. In fact, one of the possible work arounds I have considered is to actually start a copy of WINWORD.EXE if there is not one currently running…

Test 3:

After doing test 2, close both instances of WORD, and re-try test 1, without doing the reboot. Everything works correctly. As far as I can tell, once it works “correctly” it won’t happen again.

This is very reproducible on all of our corporate machines. Would it be possible for you to try again, following those instructions exactly? If you are absolutely sure it is not happening on your environments, then I will have to start looking at our machine configs….but I could literally spend weeks on it, and if it turns out that it in fact is happening on your machines as well, then it would be totally wasted time. So I would really appreciate it if you could try again, following that precise sequence above…it could same me hundreds of hours of effort!

Need Solution for Different Document Mode of IE browser to host office document

I have checked your demo site http://www.ocxt.com/officeviewer.htm, for displaying the office files (pdf,doc,xls,ppt,xlsx,docx) in the IE Browser for our web project Implementation.

It’s perfectly displaying all the file types of MS office in IE browser in Document Mode: Quirks only, but for other types of Document Mode (IE 7 Standards, IE 8 Standards, IE 9 Standards)

Your site is not working/displaying the MS office files in the IE browser.

Please give me yours feedback for this issue as soon as possible.

we need to open MS office files in all the types of IE Document mode (IE 7 Standards, IE 8 Standards, IE 9 Standards)

If your Control Help us then we can Buy license version for our Project.

Cannot save excel if cell is being edited

We have been using EDraw in our product for several months. During that time we have been quite happy, however there have been some complaining, that every now and then Excel stucks when content is saved.

The problem seems to be somehow related to the editing of Excel cell. If user is editing a cell and hasn’t accepted the value yet by pressing enter, the EDOffice methods cannot be called.

It may be demonstrated with following javascript code:

try

{

a = document.EDOffice.GetApplication();

alert(a.Name);

}

catch(err)

{

alert(“Error, cannot get the application type.”);

return;

}

If no cells are being edited, the messagebox shows “Microsoft Excel”. However, if a cell is being edited, the program either gives the error message in the catch statement, or gets totally stuck (must be killed with taskmanager).

Do you know any way to overcome this problem? The best way would be to somehow programmatically accept the cell value before saving. If that is not possible, it would be helpful if it was possible in some way to detect the erroneous situation before calling the EDOffice methods which cause the stuck.

host word document in IE using Aspx page

We are using the Edraw Office Viewer Component. If we host word document in IE(Internet Explorer) using Aspx page(ASP.NET) what is the communication mode between document and code. Is there a way to receive events from the document.

broken macros in the documents

we have big problems with the alert when there are broken macros in the documents.

The alert window opens in the background and the user can’t see it.

Could you try to give the alert box the focus and bring it to front?

Problem with office viewer component in PowerBuilder

Problem with version 7.1.0.303 in PowerBuilder 12.

I have this code in my application.

lb_DocumentOpened = ole_OfficeViewer.object.Open (“C:\Data\E2FTEMPGB50714\E2FEASSMPLVWGB5071420111018145647897.DOCX”, “Word.Document” )
lole_WordDocument = ole_OfficeViewer.object.ActiveDocument

lb_DocumentOpened is true so from the code it looks like the document is opened, but when I try to get the ActiveDocument it is null. The viewer is blank as well.

There used to be a couple settings in the old version that don’t work anymore such as

This.object.FrameHookPolicy = 1
this.object.ActivationPolicy = Parent.dsoKeepUIActiveOnAppDeactive

I don’t know if this has anything to do with it.

Prints all or part of the specified word document with settings

Edraw Word Viewer Component has the PrintOut method which support to print all or part of the specified document with settings.

boolean PrintOut( WdPrintOutRange PrintRange, [in, optional]
VARIANT FromPage, [in, optional] VARIANT ToPage, [in,
optional] VARIANT Pages, [in, optional] VARIANT Copies);
PrintRange: Optional Object. The page range. Can be any WdPrintOutRange constant.
FromPage: Optional Object. The starting page number when Range is set to wdPrintFromTo.
ToPage: Optional Object. The ending page number when Range is set to wdPrintFromTo.
Pages: Optional Object. The page numbers and page ranges to be printed, separated by
commas. For example, “2, 6-10″ prints page 2 and pages 6 through 10.
Copies: Optional Object. The number of copies to be printed.
enum WdPrintOutRange
{
wdPrintAllDocument = 0,
wdPrintSelection = 1,
wdPrintCurrentPage = 2,
wdPrintFromTo = 3,
wdPrintRangeOfPages = 4
};
Example
The following vb script shows how to print the 3-6 page in a document.
Sub PrintOut_Example()
edword.PrintOut 3, 3, 6
End Sub