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 = 0x00000001,
wdUIDisalbeNew = 0x00000002,
wdUIDisalbeOpen = 0x00000004,
wdUIDisalbeUpgradeDocument = 0x00000008,
wdUIDisalbeSave = 0x00000010,
wdUIDisalbeSaveAs = 0x00000020,
wdUIDisalbeSendAsAttachment = 0x00000040,
wdUIDisalbeClose = 0x00000100,
wdUIDisalbePrint = 0x00000200,
wdUIDisalbePrintQuick = 0x00000400,
wdUIDisalbePrintPreview = 0x00000800,
wdUIDisalbeSaveAsMenu = 0x00001000,
wdUIDisalbePrepareMenu = 0x00002000,
wdUIDisalbePermissionRestrictMenu = 0x00004000,
wdUIDisalbeSendMenu = 0x00008000,
wdUIDisalbePublishMenu = 0x00010000,
wdUIDisalbeServerTasksMenu = 0x00020000,
wdUIDisalbeCopyButton = 0x00040000,
wdUIDisalbeCutButton = 0x00080000,
wdUIHideMenuHome = 0x01000000,
wdUIHideMenuInsert = 0x02000000,
wdUIHideMenuPageLayout = 0x04000000,
wdUIHideMenuReferences = 0x08000000,
wdUIHideMenuMailings = 0x10000000,
wdUIHideMenuReview = 0x20000000,
wdUIHideMenuView = 0x40000000,
wdUIHideMenuDeveloper = 0x80000000,
wdUIHideMenuAddIns = 0x00100000,
wdUIHideMenuFormat = 0x00200000,
wdUIHideMenuEdit = 0x00400000,
wdUIHideMenuTool = 0x00800000,
}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

reading Excel data in excel viewer component

Have you seen a primary error in your component?

I’ve downloaded you OCX component and create a routine to use it reading Excel data. In a non-formatted cell, it read perfectly. In a formatted cell, with the currency simbol, it doesn’t read nothing.

How to verify whether the open document was modified

If you are developing the destop application with the office viewer component, you can use the “IsDirty” method to verify whether the open document is modified. When the open file has any modification, the IsDirty method return TRUE. After you save the document, the IsDirty return False again.

But if you are developing the web application, you need to add some extra codes. Because you are opening a file from remote server and the component can’t watch the file like destop application.

A good method is set another variable in your application. When you save the document, you set the variable true. Any time you can judge the dirty by the IsDirty method and your own variable.

BOOL GetIsDirty(){
if(OA.IsDirty()==Flase) return False;
else return m_bDirty;
}
event OnDocumentOpened()
{
m_bDirty = false;
}
function UploadFile()
{
……
m_bDirty = False;
}

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!

Print MS Word Document to the special printer

When you use the PrintOut method to print the word document with the  component, you maybe get the follow error.

This error can appear if a default printer has not been designated or if the application is unable to locate an existing default printer. To correct this problem, try one of the following in Microsoft Windows:
If a printer is not available in the Print dialog box, add a printer.
If the application cannot find an existing printer that is already installed, set the printer as the default printer.
If a default printer is installed but the application is unable to use it, uninstall the printer driver, and then install the latest version of the printer driver.
If the printer is on a print server, make sure the printer is available, the network is functioning, the server is not stalled, the printer is not out of paper, or the printer is not suspended by the administrator. Printing issues associated with a network printer are best handled by your local network administrator.
For more information about setting up and troubleshooting printer connections, see Windows Help and Support. (Click the Start button, and then click Help and Support.)

Word cannot print. There is no printer installed.

There are some solutions for it.

1. Call the ShowDialog 4 to use the default printer.

2. Word:
    CWordApplication app(m_wnd.get_Application()); 
    CString strOldPrinter = app.get_ActivePrinter();
    app.put_ActivePrinter(strPrinter); 
    app.PrintOut(varFalse, varOptional, varOptional, varOptional,
        varOptional, varOptional, varOptional, varOptional, varOptional,
        varOptional, varOptional, varOptional, varOptional, varOptional,
        varOptional, varOptional, varOptional, varOptional, varOptional); 
    app.put_ActivePrinter(strOldPrinter);

CreateNew word document not functional when running within Word VBA

Steps to recreate:

1) Open Word
2) Open VBA Editor
3) Create a new UserForm
4) Put the control on the user form
5) Select file -> new and choose word document

No document is created or displayed. Same with opening an existing word doc on local file system. This same procedure works when creating a VBA userform in MS EXcel. The control successfully displays the new or existing doc. and the related word toolbars etc.

Any ideas?
-Mike

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.

Install ActiveX Control

We would like to distribute the ActiveX control in our organization on several desktops. I understand we need to install the ocx and dll files. How do we install them and also what else needs to be done?
I do have the installation exe file but unfortunately we cannot push exe to desktops. Can you please help with this?