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;

Open MS Word or Excel Stream in JSP Program

In order to avoid the temporary file in the server, edraw office  viewer component provided a httpopenfilefromstream method to open the office document from file stream directly. It works in the JSP environment.

For example:

Getfile.jsp example code:

String downloadDirName = request.getSession().getServletContext().getRealPath(DOWNLOAD_RELATIVE_PATH);
 String downloadFileName = downloadDirName + “/” + fileMap.get(PARAM_DOCUMENT_ID).getString();
 File downloadFile = new File(downloadFileName);
 if (downloadFile.exists()) {
  byte[] buffer = new byte[4096];
  BufferedOutputStream output = null;
  BufferedInputStream input = null;
  try {
   output = new BufferedOutputStream(response.getOutputStream());
   input = new BufferedInputStream(new FileInputStream(downloadFileName));
   output.write(”EDA_STREAMBOUNDARY”.getBytes());
   int n = -1;
   while ((n = input.read(buffer, 0, buffer.length)) > -1) {
    output.write(buffer, 0, n);
   }
   output.write(”EDA_STREAMBOUNDARY”.getBytes());
   output.flush();
  } catch(Exception e) {
   e.printStackTrace();
  } finally {
   if (output != null) output.close();
   if (input != null) input.close();
  }
 }
 else {
  System.out.println(”[OfficeViewer Error] 404 File not found!”);
  System.out.println(fileItemList.toString());
 }

Open example code:

$(”OA1″).HttpInit();
$(”OA1″).HttpAddpostString(”DocumentID”, “sample.doc”);
$(”OA1″).HttpOpenFileFromStream(”http://192.168.1.1:8020/path/getfile.jsp“);