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

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

Why do I fail to download the ActiveX control on the client

The failure of loading Office Viewer ActiveX control has the following possible causes:
1. The security settings of IE on the client machine are incorrect.
Please verify the following security settings of IE to “Prompt” or “Enabled”:
a) Download signed ActiveX controls
b) Run ActiveX Controls and plug-ins
c) Script ActiveX controls marked safe for scripting
The dialog box of the security setting can be launched from menu
Tools>Internet Options. Then select the security tab.

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.

 

Disable Popup Menu in MS Office

You can disable or delete the context menu item in MS Word or Excel by VBA programming.

Word:

OA1.CreateNew “Word.Document”
Set objWord = OA1.ActiveDocument
objWord.Application.CommandBars(“Text”).Controls(“Cu&t”).Enabled = False
objWord.Application.CommandBars(“Text”).Controls(“&Copy”).Enabled = False
objWord.Application.CommandBars(“Text”).Controls(“&Paste”).Enabled = False
‘delete item directly
‘objWord.Application.CommandBars(“Text”).Controls(1).Delete
‘objWord.Application.CommandBars(“Text”).Controls(2).Delete ….

Excel

OA1.Open “c:\text.xls”
Set objExcel = OA1.ActiveDocument
objExcel .Application.CommandBars(“Cell”).Controls(“Cu&t”).Enabled = False
objExcel .Application.CommandBars(“Cell”).Controls(“&Copy”).Enabled = False
objExcel .Application.CommandBars(“Cell”).Controls(“&Paste”).Enabled = False
‘delete item directly
‘objExcel .Application.CommandBars(“Cell”).Controls(1).Delete
‘objExcel .Application.CommandBars(“Cell”).Controls(2).Delete ….

Use the CAB file in your web application

The office word component can be used for web application. You can embed it at the
html Object tag.
<object classid=”clsid: 569EB2D6-161D-4AE0-9804-640E724A297A”
id=”edword” width=”100%” height=”100%”
codebase=”http://www.yoursite.com/download/edword.cab#5,0,0,131“>
</object>
Note: You should put the edword.cab file in your own site and change the
codebase url when you distribute the component.
You can view the html samples in the install folder\samples\html folder.
The edword.

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;
}

Open Excel From File Stream Using .NET

After installed the latest demo version,  you can open the excel from file stream using the following code:

objExcel.HttpInit();

objExcel.HttpAddPostFile(“”,”Evaluation.xlsx”);

objExcel.HttpOpenFileFromStream(“Evaluation/EvaluationReceiver.aspx”);

Before you call function HttpOpenFileFromStream, you should do two things, one is to initialize http for clearing all parameters and cookies in http, another thing is to appoint the file or database record. And then use HttpOpenFileFromStream to send the request to the destinated webpage. Before HttpOpenFileFromStream send request, it will add a couple of parameters automatically.
m_OAHttp.AddPostArgument(L”EDA_GETSTREAMDATA”, L”EDA_YES”); This couple of parameters tell the destinated webpage OfficeViewer will received file as stream.

At the web side, webpage will decide to read which file or database reacord accordding to the post parameters. And you should add boundary flag ‘EDA_STREAMBOUNDARY’ to file data, following is the asp.net demo.

if (Request.Params["EDA_GETSTREAMDATA"] == “EDA_YES”)
{
  String fullFileName = Server.MapPath(Request.Params["DocumentID"]);
  Byte[] fs = File.ReadAllBytes(fullFileName);

  Response.Write(“Get Stream Successfully!”);
  Response.Write(“EDA_STREAMBOUNDARY”);
  Response.BinaryWrite(fs);
  Response.Write(“EDA_STREAMBOUNDARY”);
}

HttpUpload word document to server

I m facing a problem to used at below code, please help me then i can purchase this component.
http://localhost:1833/test/filename for open to server

http://localhost:1833/test/UploadAction.aspx for save to server
 
then file is not saved and made a tmp file but i want to replace this new doc file
 
i have used this code for save to server
 
function

SavetoServer()
{
if(document.OA1.IsOpened)
{

document.OA1.HttpInit();
var today = new Date();

var myGuid = (today.getMonth()+1).toString();
myGuid += today.getDate().toString();

myGuid += today.getYear().toString();

myGuid += today.getHours().toString();

myGuid += today.getMinutes().toString();

myGuid += today.getSeconds().toString();
var sFileName = myGuid + “.tmp”;
document.OA1.HttpAddPostOpenedFile (sFileName);

document.OA1.HttpPost(

http://localhost:1833/test/UploadAction.aspx“);

if(document.OA1.GetErrorCode() == 0)
{
var sPath = “Save successfully! You can download it http://localhost/” + sFileName;
window.alert(sPath);

}

}
else{
window.alert(

“Please open a document firstly!”);
}

}

How to do the office automation in Delphi

We want to use this component to pilot Word and Visio documents, but we have certain problems and I would like to ask you some questions :

In Word, I use bookmarks to automatically insert data, like date, name of the user. To do this, in my code I use WordGotoItem function :

    OfficeViewer_1.WordGotoItem(wdGoToBookmark, wdGoToFirst, 1, ‘Name’);

but it doesn’t work, and I don’t know why.

Could you give me more information about this function and what’s wrong in my code ?

And I have another question :

How do I reach the header or footer of the word document ? Is there a function ?

 

Edraw Office Viewer Component can work in Delphi 2007/2009 for the office automation.

For example:
 
var
p1,p2: OleVariant;
OleAPP,OleDoc,MenuBar: OleVariant;
begin
  OfficeViewer.Toolbars:=FALSE; 
  OfficeViewer.Titlebar:=FALSE;
  p1:=DocFileName;
  p2:=TRUE;
  OfficeViewer.Open(DocFileName);
  OleDoc:=OfficeViewer.ActiveDocument; // IDispatch Document
  OleAPP:=OleDoc.application; // IDispatch Document.application
  // ——— WORD —————————————
  OleAPP.ActiveWindow.DisplayRulers := False;
  OleAPP.ActiveWindow.View.Type := 1; // wdNormalView=1
  // no popup
  oleDoc.CommandBars['Text'].Enabled := False;
  try
   OleDoc.Protect(1,Null,’ppkLock’);
  except
  end;
end;