Disables the hotkeys in the MS Word programmatically

Edraw Viewer Component for Word provides some methods to disable the print, save and copy hotkeys.

boolean DisableSaveHotKey(boolean Disable);
Disables the Save keycodes.
Disalbe: Disables the CTRL+S, SHIFT+F12, Alt+SHIFT+F2, F12
boolean DisablePrintHotKey(boolean Disable);
Disables the Print keycodes.
Disalbe: Disables the CTRL+P, CTRL+SHIFT+F12, CTRL+F2, ALT+CTRL+I
boolean DisableCopyHotKey(boolean Disable);
Disables the Copy keycodes.
Disalbe: Disables the CTRL+C, CTRL+V, CTRL+X, SHIFT+DEL, SHIFT+INSERT, ALT+CTRL+V,
CTRL+SHIFT+C, CTRL+INSERT

You can call these methods at the DocumentOpened event.

About the Application method

The new version has the GetApplication method.  You can use it to replace the Application method.
 
If you want to call the print dialog, you can use the follow method.
 
EDOffice.PrintDialog

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;

Inserts a file to opened Word file programmatically

boolean InsertFile([in] BSTR FilePath, [in, optional] VARIANT
InDocPos);
Inserts a file to opened Word file.
FilePath: The file path need to be inserted.
InDocPos: The insert position. WdInPocPos.
enum WdInDocPos
{
wdInDocumentPosCursor = 1,
wdInDocumentPosStart = 2,
wdInDocumentPosEnd = 3 ,
}WdInDocPos;

Inserts a picture to opened Word file programmatically

boolean InsertPicture([in] BSTR FilePath, [in] boolean
InlineObject, [in, optional] VARIANT InDocPos);
Inserts a picture to opened Word file.
FilePath: The image path need to be inserted.
InDocPos: The insert position. WdInPocPos.
enum WdInDocPos
{
wdInDocumentPosCursor = 1,
wdInDocumentPosStart = 2,
wdInDocumentPosEnd = 3 ,
}WdInDocPos;

How to start MS Office Automation for my Web Application

How to start MS Office Automation for my Web Application?
How to call Office Automation methods from JavaScript code?
What are the input and the output parameters type for the Office Automation methods?

View the follow samples:

function WordAutomation()
{
document.OA1.CreateNew( “Word.Document”);
var objWord = document.OA1.ActiveDocument;
objWord.Content.Text = “You can do the office Automation with the Edraw Office Viewer Component.”;

 
more examples:

Use the follow Javascript to insert a file in the header of MS Word.
function WordAutomation()
{
document.OA1.CreateNew(”Word.Document”);
var objWord = document.OA1.ActiveDocument;
objWord.Sections(1).Headers(1).Range.InsertFile(”c:\\test.docx”);
}

Get the line counts from the Word Component

I am using ASP.NET, C# version 2.0

My concern is that, when the user will close the document on the web
browser, my code will get the line-count through your control and save
in the DB.

Please help me to get line count of the opened document in the component
in the IE.

If possible please send me the sample code to get the line-count using
Javascript.

How do I insert a page break in the function of Word Automation

How do I insert a page break in the function of Word Automation. The instructions that I have tried do not
work:
     Set objWord = OA1.ActiveDocument
     Set objApp = OA1.Application
     objApp.Selection.InsertBreak Type:=wdPageBreak
Can you help?

Solution:

Use the number to replace the emun.
 
Set objApp = OA1.Application
objApp.Selection.InsertBreak 7

Macro make Office Automation Easier

Automation is a process that allows applications that are written in languages such as Visual Basic .NET or C# to programmatically control other applications. Automation to Word allows you to perform actions such as creating new documents, adding text to documents, mail merge, and formatting documents. With Word and other Microsoft Office applications, virtually all of the actions that you can perform manually through the user interface can also be performed programmatically by using automation. Word exposes this programmatic functionality through an object model. The object model is a collection of classes and methods that serve as counterparts to the logical components of Word. For example, there is an Application object, a Document object, and a Paragraph object, each of which contain the functionality of those components in Word.

You can call the interesting methods and properties that Microsoft Word provides to you to manipulate documents in Word. The best way to learn how to navigate the object models of Word, Excel, and PowerPoint is to use the Macro Recorder in these Office applications:

1. Choose Record New Macro from the Macro option on the Tools menu and execute the task you’re interested in.
2. Choose Stop Recording from the Macro option on the Tools menu.
3. Once you are done recording, choose Macros from the Macro option on the Tools menu, select the macro you recorded, then click Edit.

This takes you to the generated VBA code that accomplishes the task you recorded. Keep in mind that the recorded macro will not be the best possible code in most cases, but it provides a quick and usable example.

For example to open an existing file and append some text:

object fileName = “c:\\test.doc”;
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
Word.ApplicationClass oWordApp = new Word.ApplicationClass();
EDrawOfficeViewer1.Open(ref fileName, ref missing, ref missing);
Word.ApplicationClass oWordApp = EDrawOfficeViewer1.GetApplication();
oWordApp.Selection.TypeText(“This is the text”);
oWordApp.Selection.TypeParagraph();

Start the Word Automation with VBScript in Office Viewer Component

EDraw Office Viewer Component also supports a property called Dispatch that allows you to obtain a reference to the IDispatch interface of the embedded object. From this interface you can automate the object to perform tasks, edit parts of the document, or gather information about what a user has added or removed. For example, if you have a Word document open, you can use code that resembles the following to add a line of text:

Sub OfficeAutomationDemo()
    WebOffice1.CreateNew “Word.Document”
    Set objWord = WebOffice1.GetActiveDocument
    objWord.Content.Text = “This was added by Automation”
End Sub