Embed Word and excel program in Visual Basic project

How to add Edraw Excel Viewer Component or Word Viewer ActiveX Control to your Visual Basic 6.0 project

1. From the Project Menu select Components…
2. Select control “EDWord ActiveX Control Module” in the controls table.
3. Click the OK Button.
4. The control will now appear in your toolbox.
5. Drag and drop the control on your form.
6. Right click the control then choose the View Code… item.
7. Add the NotifyCtrlReady event and set the library file to load.
Private Sub EDWord1_NotifyCtrlReady()
EDWord1.LicenseName = “”
EDWord1.LicenseCode = “”
End Sub
8. Run the project.

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.

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

Office Component System Requirements

Edraw compnent system requirements

Hardware :
Minimum:
Pentium Based MMX processor 500 MHZ
256 MB of ram
SVGA Graphics card
64 MB HardDisk
Recommended:
Intel Celeron or AMD Duron 1 GHz and above
1 GB ram
SVGA Graphics card with some acceleration (1024x768x16bitsColor)
Software :
Minimum:
Windows 2000 with IE6 and above.
Recommended:
IE 6/7/8
Windows 2000/XP/2003/Vista/Windows 7
Office 2000/XP/2003/2007/2010
For web application: The component need IE Protection Mode was Turn Off.
You can added your site at the IE trusted site list to turn off the IE protection mode
automatically when the users visit your site with the component.
Please consider also your application’s requirements.

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

Play slideshow in the same window

Edraw Office Viewer Component provides a solution for opening then playing the slideshow file in the same window. Of course you can play it with full screen mode too.

Simply call the “SlideShowOpenAndPlay” method, you can get the follow effect immediately.

PowerPoint Viewer ActiveX Control

You can show or hide the titlebar, screenbar, toolbar too.

You can call it via javascript or vbscript in your html page as follow.

document.OA1.SlideShowOpenAndPlay(“http://www.ocxt.com/demo/samples/sample.ppt“, false, false, false, false);

OR:

OA1.Open(“http://www…./sample.pps“, “PowerPoint.Slide”);

OA1.SlideShowPlay(false, false, true, false);

[id(99), helpstring("Opens then plays the PowerPoint slide show file in the same window or full screen.")]
HRESULT SlideShowOpenAndPlay([in] VARIANT Document, [in] VARIANT_BOOL bFullScreen, [in] VARIANT_BOOL bShowWebToolbar, [in] VARIANT_BOOL bLoopUntilStopped, [in] VARIANT_BOOL bShowScrollBar, [in, optional] VARIANT WebUsername, [in, optional] VARIANT WebPassword);

[id(100), helpstring("Plays the PowerPoint slide show file in the same window or full screen.")]
HRESULT SlideShowPlay([in] VARIANT_BOOL bFullScreen, [in] VARIANT_BOOL bShowWebToolbar, [in] VARIANT_BOOL bLoopUntilStopped, [in] VARIANT_BOOL bShowScrollBar);

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;

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“);