37
EDraw Office Viewer Component http://www.ocxt.com EDraw Office Viewer Component V4.1 Overview EDraw Office Viewer Component contains a standard ActiveX control that acts as an ActiveX document container for hosting Office documents (including Microsoft Word, Microsoft Excel, Microsoft PowerPoint, Microsoft Project, and Microsoft Visio documents) in a custom form or Web page. The control is lightweight and flexible, and gives developers new possibilities for using Office in a custom solution. The control is designed to handle specific issues that make using ActiveX documents from a non-top-level host window difficult, and serves as a starting place for constructing your own embedded object file viewer or editor as an ActiveX control. It is a great solution for companies wishing to display read-only Word document data and Excel sheet to their employees while restricting modifications to the underlying data. You can play the PowerPoint file in the same window. You can also display password protected Word documents without supplying passwords to your users - keep your confidential data safe and secure! With the office component it is easy to upload or download file between server and client via HTTP/FTP. Product Home: http://www.ocxt.com Company Home: http://www.edrawsoft.com Online Demo: http://www.ocxt.com/online-demo/ Support Mail: [email protected] Sales online: https://www.regnow.com/softsell/nph-softsell.cgi?item=14621-2 Requirement The Server: Windows or Unix Server. The Client: Office 97, Office 2000, Office XP, Office 2003 or Office 2007 It can be easily integrated into applications written in languages that support ActiveX control such as Visual C++, Visual Basic, Delphi, C++ Builder and .Net languages. Support Office automating client to custom your application. Include abundant sample codes in the install directory. You can also get the full c++ source codes. OCX Information Page 1 / 37

reference

Embed Size (px)

Citation preview

Page 1: reference

EDraw Office Viewer Component http://www.ocxt.com

EDraw Office Viewer Component V4.1

Overview

EDraw Office Viewer Component contains a standard ActiveX control that acts as an ActiveX document container for hosting Office documents (including Microsoft Word, Microsoft Excel, Microsoft PowerPoint, Microsoft Project, and Microsoft Visio documents) in a custom form or Web page. The control is lightweight and flexible, and gives developers new possibilities for using Office in a custom solution.

The control is designed to handle specific issues that make using ActiveX documents from a non-top-level host window difficult, and serves as a starting place for constructing your own embedded object file viewer or editor as an ActiveX control.

It is a great solution for companies wishing to display read-only Word document data and Excel sheet to their employees while restricting modifications to the underlying data. You can play the PowerPoint file in the same window. You can also display password protected Word documents without supplying passwords to your users - keep your confidential data safe and secure! With the office component it is easy to upload or download file between server and client via HTTP/FTP.

Product Home: http://www.ocxt.com

Company Home: http://www.edrawsoft.com

Online Demo: http://www.ocxt.com/online-demo/

Support Mail: [email protected] online: https://www.regnow.com/softsell/nph-softsell.cgi?item=14621-2

Requirement

The Server: Windows or Unix Server.The Client: Office 97, Office 2000, Office XP, Office 2003 or Office 2007

It can be easily integrated into applications written in languages that support ActiveX control such as Visual C++, Visual Basic, Delphi, C++ Builder and .Net languages. Support Office automating client to custom your application. Include abundant sample codes in the install directory. You can also get the full c++ source codes.

OCX Information

Name: EDraw Office Viewer ComponentFile Name: edrawofficeviewer.ocxCLSID: 053AFEBA-D968-435f-B557-19FF76372B1BVersion: 4,1,5,21

Page 1 / 35

Page 2: reference

EDraw Office Viewer Component http://www.ocxt.com

Release Date: 2007-5-20OCX Size: 916KB CAB Size: 350KB

How to add Office ActiveX Control to your Visual Basic 6.0 project 

1. From the Project Menu select Components…

2. Select control “EDraw Office Viewer Component” 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

How to add EDraw Office Viewer Component to your .NET project

1. Open .NET

2. Right-click on the toolbox and select "Choose Items…"

3. Select the COM Components Tab

4. Check EDraw Office Viewer Component and click OK Button

5. The control should appear in the toolbox as "EDraw Office Viewer Component"

6. Double-click on the control to add to your form

7. Resize and move the control on the form as desired

8. Add a button to the form

9. Double-click on the button to access code editor and enter the following code within the Click event:

'Note: Modify code to point to an existing office document file on your web server

EDrawOfficeViewer1.Open "http://www.ocxt.com/demo/sample.doc"

10. Change the anchor property of EDrawOfficeViewer1 to Top, Bottom, Left, Right

11. Run the application and click on the button. The Word Document should appear!

How to add EDraw Office Viewer Component to your Access Form

1. Open Access

2. Create a new blank database

3. Create a new form in Design View. You should now be in design mode

4. From the Insert Menu select "ActiveX Control..."

5. Select WordViewer.WordView and click the OK Button

6. The control should appear on the form

7. Resize and move the control on the form as desired

8. Add a button to the form. If the wizard appears cancel it

9. Right-click on the button to invoke the popup menu

Page 2 / 35

Page 3: reference

EDraw Office Viewer Component http://www.ocxt.com

10. Select "Build Event..." then select Code Builder and click OK Button

11. You should be inside the Visual Basic Development Environment

12. Within the Command_Click enter the following code:

'Note: Modify code to point to an existing Word Document file on your web server

EDrawOfficeViewer1.Open "http://www.ocxt.com/demo/sample.doc"

13. Save your changes and close Visual Basic

14. Save the form and close it

15. Double-click on the form to run it.

16. Click the button. The Word Document should appear!

17. Experiment by changing the file path to a local file such as:

EDrawOfficeViewer1.Open "c:\test.xls"

Visit http ://www.ocxt.com to view more information.

There are some methods and properties to operator the office control.

Code a solution using the control

The control is very customizable. You can change the color scheme of any of the control elements, as well as determine the border type and a custom caption. These can be set at run time or design time as needed. Methods

1. Create new documents

Function: boolean CreateNew([in] BSTR ProgIdOrTemplate);Description: Creates a new document based on the ProgId or Template file provided.Parameter: ProgIdOrTemplate: Program Id or Template ID. The following shows the possible values for this parameter.Excel Spreadsheet: progID is “Excel.Sheet”;Excel Chart: ProgID is “Excel.Chart”;PowerPoint Presentation: ProgID is “PowerPoint.Show”;Project: ProgID is “MSProject.Project”;Visio Drawing: ProgID is “Visio.Drawing”;Word Document: ProgID is “Word.Document”.Return Value: Nonzero if successful; otherwise 0.

The component allows you to create new documents for any ActiveX document type that is registered on the system. A user can use the custom function that you provide to create new documents.

Page 3 / 35

Page 4: reference

EDraw Office Viewer Component http://www.ocxt.com

Create a blank word document:

WebOffice1. CreateNew "Word.Document "

Create a blank excel sheet:

WebOffice1. CreateNew "Excel.Sheet "

2. Open documents

Function: boolean Open([in] VARIANT Document, [in, optional] VARIANT ProgId);Description: Opens a document from a file, URL.Parameters:Document: A full disk path or web url.ProgId: Described as “CreateNew” function.Return Value: Nonzero if successful; otherwise 0.

You can open and edit Office documents that exist on a local drive or a web url. You can call the Open method directly and give the control a specific file to open. If you haven’t specified the ProgId, the component will open the file with the default program. Otherwise it will open the file with the special program. Some sample codes to demo how to open a file:

VBScript:

<script language="vbscript">Sub OpenDoc()

WebOffice1.Open "c:\testfile.doc"‘WebOffice1.Open “c:\testfile.rtf”, “Word.Document” ‘WebOffice1.Open “http://www.ocxt.com/demo/sample.xls”‘WebOffice1.Open “http://www.ocx.com/demo/sample.mht”,

“Word.Document”End Sub </script>

JavaScript:

<script language="JavaScript">Function OpenDocument(){

WebOffice1. Open("http://www.ocx.com/demo/sample.mht", “Word.Document”);

//WebOffice1.Open(“c:\testfile.ppt”);

Page 4 / 35

Page 5: reference

EDraw Office Viewer Component http://www.ocxt.com

}

Visual C++

BOOL OpenDocument(CString sPath){

VARIANT varPath, varOpt; varPath.vt = VT_BSTR; varPath. boolVal = sPath. AllocSysString();varOpt.vt = VT_ERROR; varOpt.scode = DISP_E_PARAMNOTFOUND;WebOffice1.Open(varpath, varOpt);

}

3. Save Documents

Function: boolean Save([in, optional] VARIANT SaveAsDocument, [in, optional] VARIANT WebUsername, [in, optional] VARIANT WebPassword);Description: Saves the document to specified location or its original location.Parameters:SaveAsDocument: The file save path. If it’s NULL, the opened file will save to its original location.WebUsername: User name for uploading file to the web server.WebPassword: User password for uploading file to the web server.Return Value: Nonzero if successful; otherwise 0.

You can save the opened file to a local disk file without prompt message with the function. You can also save the opened file to a remote server via HTTP upload.VBScript:

<script language="vbscript">Sub OpenDoc()

WebOffice1.Save "c:\testfile.doc"‘WebOffice1.Save “c:\testfile.rtf”” ‘WebOffice1.Save “http://www.ocxt.com/demo/Uploadfile.php?

FileID=20070511&FileName=NewFileName.xls”‘WebOffice1.Save “https://www.ocxt.com/demo/Uploadfile.aspx?

FileID=20070511&FileName=NewFileName”, “UserName”, “Password”End Sub </script>

JavaScript:

Page 5 / 35

Page 6: reference

EDraw Office Viewer Component http://www.ocxt.com

<script language="JavaScript">Function OpenDocument(){

WebOffice1. Save ("https://www.ocxt.com/demo/Uploadfile.php?FileID=20070511", “UserName”, “Password”);

//WebOffice1. Save (“c:\testfile.ppt”);}

Visual C++

BOOL OpenDocument(CString sPath){

VARIANT varPath, varOpt; varPath.vt = VT_BSTR; varPath. boolVal = sPath. AllocSysString();varOpt.vt = VT_ERROR; varOpt.scode = DISP_E_PARAMNOTFOUND;WebOffice1.Save(varpath, varOpt, varOpt);

}

If you try to save the opened file to remote server with the “Save” method, you need write a receipt page in your web server. Because the component uploads the file by HTTP mode. The follow is some sample code.

ASP.NET:

//Default.aspx<script language="vbscript">Sub SavetoServer()

OfficeViewer1.Save "http://localhost:1320/UploadAction.aspx?author=name&Data=2”End Sub</script>

//UploadAction.aspx.cs fileusing System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.IO;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.HtmlControls;

Page 6 / 35

Page 7: reference

EDraw Office Viewer Component http://www.ocxt.com

using System.Xml;using System.Drawing.Imaging;using System.Text.RegularExpressions;

public partial class UploadAction : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (Request. QueryString["author"] == "name" && Request. QueryString["Data"] == "2") { Response.Write("0\n"); Response.Write("We have receipted the right param from Office ActiveX Control."); } if (Request.Files.Count == 0) { Response.Write("0\n"); Response.Write("There isn't file to upload."); Response.End(); } if (Request.Files[0].ContentLength == 0) { Response.Write("0\n"); Response.Write("Failed to receipt the data.\n\n"); Response.End(); } string fullFileName = Server.MapPath(Request.Files[0].FileName); Request.Files[0].SaveAs(fullFileName); Response.Write("Upload Successfully."); Response.End(); }}

PHP:

<?phpheader("http/1.1 200 OK");$user = iconv("UTF-8", "UNICODE", $_POST['user']);$passwd = iconv("UTF-8", "UNICODE", $_POST['passwd']);$sql = sprintf("username=%s passwd=%s", $user,$passwd);echo $sql;$sql = sprintf("file=%s size=%s error=%s tmp=%s", $_FILES['trackdata']['name'],$_FILES['trackdata']['size'],$_FILES['trackdata']['error'],$_FILES['trackdata']['tmp_name']);

Page 7 / 35

Page 8: reference

EDraw Office Viewer Component http://www.ocxt.com

echo $sql;$handle = fopen($_FILES['trackdata']['name'],"a");if($handle == FALSE){

exit("Create file error!");}$handle2 = fopen($_FILES['trackdata']['tmp_name'],"r");$data = fread($handle2,$_FILES['trackdata']['size']);echo $data;fwrite($handle,$data);fclose($handle2);fclose($handle);exit(0);?>

ASP:

<%@Language=VBScript %><!-- #include file="./include/upload.inc" --><!--#include file="./include/conn.asp"--><%Set Uploader = New UpFile_ClassUploader.NoAllowExt="cs;vb;js;exe" Uploader.GetData (Request.TotalBytes)Request.TotalBytesif Uploader.isErr then select case Uploader.isErr case 1 Response.Write "Fail to receipt the data." case 2 Response.Write "The file is too big to upload" End select 'Response.EndEnd ifDim id If "" <> Request.QueryString("id") then id = Request.QueryString("id")End ifif id<>0 then Sql="SELECT * from doc where doc.id = "&idelse Sql="SELECT * from doc"End ifrs.Open Sql,conn,1, 3for each formName in Uploader.file

Page 8 / 35

Page 9: reference

EDraw Office Viewer Component http://www.ocxt.com

set file=Uploader.file(formName) If id<>0 then If("" = Request.QueryString("isAip")) Then rs("DocContent") = Uploader.FileData(formname) rs("DocID") = Uploader.Form("DocID") rs("DocTitle") = Uploader.Form("DocTitle") rs("DocType") = Uploader.Form("DocType") Else rs("AipContent") = Uploader.FileData(formname) rs("state") = 2 End if Else rs.AddNew rs("DocID") = Uploader.Form("DocID") rs("DocTitle") = Uploader.Form("DocTitle") rs("DocContent") = Uploader.FileData(formname) rs("Docdate") = Now() rs("DocType") = Uploader.Form("DocType") rs("state") = 1 End Ifset file=nothingrs.Updateexit for nextrs.CloseSet rs=Nothingconn.closeset conn = NothingSet Uploader = Nothing%>

JSP:

jsp:<%@ page contentType="text/html; charset=UTF-8" %><%@ page language="java" import="com.jspsmart.upload.File><jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" /><%String sPath="C:\\"mySmartUpload.initialize(pageContext);mySmartUpload.upload();String TempName=mySmartUpload.getRequest().getParameter("TempName");mySmartUpload.save(sPath);File myFile =mySmartUpload.getFiles().getFile(0);%>

Page 9 / 35

Page 10: reference

EDraw Office Viewer Component http://www.ocxt.com

4. Save As

Function: boolean SaveAs([in] BSTR FilePath, [in, optional] VARIANT FileFormat);Description: Saves the document to specified location with the specified format.Parameters:FilePath: The file save path. FileFormat: You can referent the enum variable in the end of document. It can be a value of PpSaveAsFileType, XlSaveAsFileType or WdSaveFileType.Return Value: Nonzero if successful; otherwise 0.

If you haven’t specify the parameter of FileFormat, the SaveAs method will save the opened document with the default file format.

<script language="vbscript">Sub SaveAs()

‘Save the opened Word file to HTML formatWebOffice1.SaveAs "c:\testfile.html", 8 ‘Save the opened Word file to RTF format‘WebOffice1.SaveAs “c:\testfile.rtf”, 6‘Save the opened PowerPoint file to metafile.‘WebOffice1.SaveAs “c:\testfile.emf”, 15

End Sub </script>

5. Call the Standard Open Dialog

Function: boolean CallOpenFileDialog([in, optional] VARIANT Filter);Description: Call the standard file dialog to open the office document.Parameters:Filter: A series of string pairs that specify filters you can apply to the file. If you specify file filters, only selected files will appear in the Files list box. See the Remarks section for more information on how to work with file filters.Return Value: Nonzero if successful; otherwise 0.

If this parameter is NULL, the function uses "Office Files|*.doc;*.docx;*.xls;xlsx;*.ppt;pptx;*.vsd;*.mpp;*.rtf;*.csv;|All Files (*.*)|*.*||" as the filter.

<script language="vbscript">Sub OpenLocalFile()

WebOffice1. CallOpenFileDialog End Sub </script>

Page 10 / 35

Page 11: reference

EDraw Office Viewer Component http://www.ocxt.com

6. Call the Standard Save Dialog

Function: boolean CallSaveFileDialog([in, optional] VARIANT Filter);Description: Call the standard file dialog to save the office document.Parameters:Filter: A series of string pairs that specify filters you can apply to the file. If you specify file filters, only selected files will appear in the Files list box. See the Remarks section for more information on how to work with file filters.Return Value: Nonzero if successful; otherwise 0.

If this parameter is NULL, the function uses "Office Files|*.doc;*.docx;*.xls;xlsx;*.ppt;pptx;*.vsd;*.mpp;*.rtf;*.csv;|All Files (*.*)|*.*||" as the filter.

<script language="vbscript">Sub SaveLocalFile()

WebOffice1. CallSaveFileDialog End Sub </script>

7. Show Dialog

Function: boolean ShowDialog([in] ShowDialogType DlgType);Description: Displays a modal dialog of the given type for user action.Parameters:DlgType: It can be a value of ShowDialogType.Return Value: Nonzero if successful; otherwise 0.

With the function, you can call the New, Open, Save, Save Copy, Print, Page Setup or Properties dialog in the Microsoft Office.

typedef enum ShowDialogType{

DialogNew = 0,DialogOpen,DialogSave,DialogSaveCopy,DialogPrint,DialogPageSetup,DialogProperties

} ShowDialogType;<script language="vbscript">Sub SaveLocalFile()

WebOffice1. ShowDialog 6 ‘Show Properties Dialog‘WebOffice1.ShowDialog 5 ‘ShowPage Setup Dialog

End Sub

Page 11 / 35

Page 12: reference

EDraw Office Viewer Component http://www.ocxt.com

</script>

8. Print

Function: boolean PrintOut([in, optional] VARIANT PromptUser, [in, optional] VARIANT PrinterName, [in, optional] VARIANT Copies, [in, optional] VARIANT FromPage, [in, optional] VARIANT ToPage, [in, optional] VARIANT OutputFile);Description: Prints current document to specific printer with settings.Parameters:PromptUser: Indicates whether the user is prompted for the value of the parameter.PrinterName: Indicates the name of printer. Gets an empty string if the default printer is used.Copies: Sets the number of copies of the document to print.FromPage: Sets the page number of the first page to print.ToPage: Sets the number of the last page to print.OutputFile: Sets the name of an optional file to which trace replay output is streamed.Return Value: Nonzero if successful; otherwise 0.

With the function, you can print the document without user prompt.

<script language="vbscript">Sub PrintOut()

WebOffice1. PrintOut‘WebOffice1.PrintOut false, “PDF Virtual Printer”, 2, 1,10

End Sub </script>

9. Print Preview

Function: boolean PrintPreview();Description: Starts a print preview (if document supports it).Return Value: Nonzero if successful; otherwise 0.

Function: boolean EndPrintPreview();Description: Exits a current print preview.

With the function, you can preview the print.

<script language="vbscript">Sub PrintPreview()

If WebOffice1.IsOpen ThenDim bResult = WebOffice1. Printview

Page 12 / 35

Page 13: reference

EDraw Office Viewer Component http://www.ocxt.com

If bResult = False ThenWebOffice1.EndPrintPreviewMsgBox ”Fail to prview the document.”End If

End IfEnd Sub

10. Is Dirty

Function: boolean IsDirty();Description: Returns True/False if file has been altered or needs save.Return Value: Nonzero if the opened document has been modified; otherwise 0.

<script language="vbscript">Sub PrintOut()

If WebOffice1. IsDirty ThenMsgBox “The document has been modified.”

ELSE MsgBox “The document hasn’t been modified.”

End Sub </script>

11. Is Open

Function: boolean IsOpen();Description: Returns True/Fase if file has been opened.Return Value: Nonzero if a document has been opened; otherwise 0.

<script language="vbscript">Sub PrintOut()

If WebOffice1. IsOpen ThenWebOffice1.Close

End Sub </script>

12. Close Document

Function: boolean Close();Description: Closes the currently open document.Return Value: Nonzero if successful; otherwise 0.

Page 13 / 35

Page 14: reference

EDraw Office Viewer Component http://www.ocxt.com

13. HTTP Upload File

Function: boolean HttpInit();Description: Initializes the HTTP connection.

Function: boolean HttpAddpostString([in] BSTR Name, [in] BSTR Value);Description: Adds the post parameter.Parameters:Name: The parameter name.Value: The parameter value.

Function: boolean HttpAddPostFile([in] BSTR LocalFilePath, [in] BSTR NewFileName);Description: Adds the post file.Parameters:LocalFilePath: The full file path needs to upload to the server. It the parameter is NULL, the function will add the file which is opening in the component.NewFileName: The new file name for the upload file.

Function: boolean HttpPost([in] BSTR WebUrl,[in, optional] VARIANT WebUsername, [in, optional] VARIANT WebPassword);Description: Sends the specified request to the HTTP server.Parameters:WebUrl: A string containing the web url from which uploads data via HTTP.WebUsername: A string containing the user name.WebPassword: A string containing the access password.

Return Value: Nonzero if successful; otherwise 0.

The follow code is demo how to upload the opened file to server with the HTTP mode. It can also post multiple files in a post request.

<script language="vbscript">Sub UploadFile()

WebOffice1.HttpInitWebOffice1.HttpAddpostString "author", "anyname"WebOffice1.HttpAddpostString "Data", "2007-5-15"WebOffice1.HttpAddPostFile "", "newfilename.doc"WebOffice1.HttpPost "http://localhost:1320/Samples/UploadAction.aspx"

End Sub</script>

Note: You need write a receipt page to get the data.

Page 14 / 35

Page 15: reference

EDraw Office Viewer Component http://www.ocxt.com

14. HTTP Download File

Function: boolean HttpDownloadFile([in] BSTR WebUrl, [in] BSTR LocalFile);

Description: Downloads a file from a remote server then save it to local file with HTTP.

Parameters:WebUrl: A string containing the web url from which donwloads data via HTTP.LocalFile: Local file path to save the downloan file.Return Value: Nonzero if successful; otherwise 0.

The component provides the method to download file from a server then save to a local disk file.

<script language="vbscript">Sub DownloadFile()

WebOffice1.HttpDownloadFile “http://www.ocxt.com/demo/1.doc”, “c:\textfile.doc”End Sub</script>

Note: You should make sure you the file exists in the web site firstly. A simple method is to enter the WebUrl in the Internet Explore. If IE can download the file, the component can do it too.

FAQ: If you are using Windows 2003 as your server, you maybe need to add the mime types to Internet Information Server.

15. FTP Upload/Download File

Function: boolean FtpConnect([in] BSTR WebUrl, [in, optional] VARIANT WebUsername, [in, optional] VARIANT WebPassword);Description: Creates a FTP connect.

Function: boolean FtpDownloadFile([in] BSTR RemoteFile, [in] BSTR LocalFile);Description: Download a file from remote server then save it to local file with FTP.Parameters:RemoteFile: The remote file path which saves to FTP site.LocalFile: The full file path which downloads to the local disk.

Function: boolean FtpUploadFile([in] BSTR LocalFile, [in] BSTR RemoteFile, [in, optional] VARIANT OverWrite);Description: Uploads a local disk file to remote server with FTP.Parameters:LocalFilePath: The full file path needs to upload to the server. It the parameter is NULL, the function will add the file which is opening in the component.RemoteFile: The remote file path which saves to FTP site.

Page 15 / 35

Page 16: reference

EDraw Office Viewer Component http://www.ocxt.com

OverWrite: Overwrites the exsited file if the same file exists at the FTP server.

Function: boolean FtpDisConnect();Description: Closes the FTP Connect.

Return Value: Nonzero if successful; otherwise 0.

The follow code is demo how to download a file to local disk with the FTP mode.<script language="vbscript">Sub UploadFileviaFTP()

WebOffice1. FtpConnect “ftp.ocxt.com”, “username”, “password” WebOffice1. FtpDownloadFile “ftp.ocx.com/archieve/001.doc”, “c:\temp.doc”WebOffice1. FtpDisConnect

End Sub</script>

16. Delete Local Disk File

Function: boolean DeleteLocalFile([in] BSTR FilePath);

Description: Deletes a local disk file.

Parameters:FilePath: Local file path which needs to delete.Return Value: Nonzero if successful; otherwise 0.

You can delete the temporary file with the function.

<script language="vbscript">Sub ClearTempFile()

WebOffice1. DeleteLocalFile “c:\windows\temp\~001.doc”End Sub</script>

17. Get the Temporary File Path

Function: BSTR GetTempFilePath();

Description: Returns a temporary file path.

Return Value: A string containing the temporary file path if successful, otherwise 0.

Some time you need get a full path to save a temporary file. With the function you can get a file name in the windows system temporary directory.

18. Executes a Specified OLE Command

Page 16 / 35

Page 17: reference

EDraw Office Viewer Component http://www.ocxt.com

Function: boolean ExecOleCommand([in] long dwOleCmdID, [in, optional] VARIANT dwOptions, [in, optional] VARIANT* vInParam, [in, out, optional] VARIANT* vInOutParam);

Description: Calls IOleCommandTarget::Exec on embedded object.

Parameters: dwOleCmdID: The command to be executed. This command must belong to the group specified with pguidCmdGroup.dwOptions: Values taken from the OLECMDEXECOPT enumeration, which describe how the object should execute the command.vInParam: Pointer to a VARIANTARG structure containing input arguments. Can be NULL.vInOutParam: Pointer to a VARIANTARG structure to receive command output. Can be NULL.Return Value: Nonzero if successful; otherwise 0.

19. Enable/Disable the File Commands

Function: void SetEnableFileCommand([in] FileCommandType Item, [in] boolean bNewValue);

Description: Sets whether a specific action item is enabled.

Parameters: Item: An enumerable value of FileCommandType.bNewValue: New value for the file command.

Function: boolean GetEnableFileCommand([in] FileCommandType Item);

Description: Returns whether a specific action item is enabled.

Parameters: Item: An enumerable value of FileCommandType.

Return Value: Nonzero if a specific action item is enabled; otherwise 0.

You can enable or disable items on the File menu by using the two functions. For example, the following code disables the Print Preview command.

typedef enum FileCommandType{

FileNew = 0,FileOpen,FileClose,FileSave,

Page 17 / 35

Page 18: reference

EDraw Office Viewer Component http://www.ocxt.com

FileSaveAs,FilePrint,FilePageSetup,FileProperties,FilePrintPreview

} FileCommandType;

HTML

<script language="vbscript">Sub EnablePrintPreviewButton()

WebOffice1. SetEnableFileCommand 8, falseEnd Sub</script>

ASP.NET

SuPrivate Sub Form_Load() WebOffice1.EnableFileCommand(FilePrint) = FalseEnd Sub

20. Display the Loading Process with Animation

Function: void BeginWait();

Description: Sets the begin flag for waiting a task to process.

Function: void EndWait();

Description: Sets the end flag for waiting a task to process.

Call this function to display the cursor as an hourglass when you expect a command to take a noticeable time interval to execute. During the process, the view shows a loading animation.

<script language="vbscript">Sub OpenFile()

WebOffice1.BeginWaitWebOffice1.Open “http://www.ocx.com/demo/sample.doc”WebOffice1.EndWait

</script>

21. Whether Is Office Installed

Function: boolean ProgramIsInstalled([in] BSTR ProgIdOrTemplate);

Description: Returns whether the client installs the special program.

Parameters:

Page 18 / 35

Page 19: reference

EDraw Office Viewer Component http://www.ocxt.com

ProgIdOrTemplate: Program Id or Template ID. The following shows the possible values for this parameter.Return Value: Nonzero if the client installs the special office program; otherwise 0.

You can use the function to judge whether the client installs the office program.

<script language="vbscript">Sub JudgeInstallOffice()

If WebOffice1. ProgramIsInstalled “Word.Document” = false ThenMsgBox “The client hasn’t installed the Microsoft Word.”ELSEWebOffice1.BeginWaitWebOffice1.Open “http://www.ocx.com/demo/sample.doc”WebOffice1.EndWaitEnd If

</script>

22. Activate the Document Object

Function: void Activate();

Description: Activates the current document object.

You can use the function to activate the document object in the component when you need to set the focus for the object.

23. Get Dispatch Interface to support the Office Automation

Function: IDispatch* GetActiveDocument();

Description: Returns the Automation interface of the document object.

Function: IDispatch* GetApplication ();

Description: Returns the Automation interface of the application.

The control 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:

<script language="vbscript">Sub OfficeAutomationDemo()

WebOffice1.CreateNew "Word.Document"Set objWord = WebOffice1.GetActiveDocumentobjWord.Content.Text = "This was added by Automation"

End Sub

Page 19 / 35

Page 20: reference

EDraw Office Viewer Component http://www.ocxt.com

</script>

24. Protect Document / Read Only

Function: boolean ProtectDocument([in, optional] VARIANT Password);

Description: Protects the opened file from modification for Word and Excel. Read Only.

Parameters: Password: An optional password to protect the document.

Return Value: Nonzero if successful; otherwise 0.

Function: boolean UnprotectDocument([in, optional] VARIANT Password);

Description: Cancels the protect from modification for Word and Excel.

Parameters: Password: An optional password to unprotect the document. The password should be the value which protects the document.

Return Value: Nonzero if successful; otherwise 0.

The control also supports Read Only mode for Microsoft Word Document and Microsoft Excel Sheet. In the Read Only mode, the component will prevent any action attempts to modify the document. In other word, you can’t copy or paste the content in the document too.

<script language="vbscript">Sub OpenWithReadOnly()

WebOffice1.BeginWaitWebOffice1. Toolbars FalseWebOffice1.Titlebar FalseWebOffice1.Open “http://www.ocxt.com/demo/sample.doc”WebOffice1.ProtectDocumentWebOffice1.EndWait

End Sub</script>

25. Play Slide Show in the Same Window

Function: boolean PlaySlideShow([in] boolean SameWindow);

Description: Plays the PowerPoint slide show file in the same window or full screen.

Parameters:

Page 20 / 35

Page 21: reference

EDraw Office Viewer Component http://www.ocxt.com

SameWindow: If it is true, the component will play the slideshow in the same window. Otherwise it will play slide show in full screen mode.

Return Value: Nonzero if successful; otherwise 0.

The method allow the developer to play the Microsoft PowerPoint file in a custom window.

<script language="vbscript">Sub PlaySlideShow()

WebOffice1. IsOpenWebOffice1.PlaySlideShow TrueWebOffice1.Toolbars False

End Sub</script>

26. Switch to Different View

Function: boolean ShowView([in] long ViewType);

Description: Switches to the different view for office program.

Parameters: ViewType: You can referent the enum variable in the end of document. It can be a value of PpViewType, WdViewType or XlViewType.Return Value: Nonzero if successful; otherwise 0.

The method allow the developer to play the Microsoft PowerPoint file in a custom window.

<script language="vbscript">Sub SwitchView()

WebOffice1. ShowView 12 ‘ppViewMasterThumbnails‘WebOffice1. ShowView 7 ‘wdReadingView‘WebOffice1. ShowView 6 ‘wdWebView

End Sub</script>

27. Show/Hide Revisions

Function: boolean ShowRevisions([in] boolean ShowRevisions);

Description: Shows/Hides the revisions for the office program.

Parameters: ShowRevisions: A new value to show/hide revisions.Return Value: Nonzero if successful; otherwise 0.

The method allow the developer to show or hide the revisions for the office program.

<script language="vbscript">

Page 21 / 35

Page 22: reference

EDraw Office Viewer Component http://www.ocxt.com

Sub ShowRevisions()WebOffice1.ShowRevisions False

End Sub</script>

Properties

1. Show/Hide Toolbars

Property: boolean Toolbars;

Description: Shows/Hides the toolbars.

The property allow the developer to show or hide the toolbars in the office program.

<script language="vbscript">Sub ToggleTitlebar()

If WebOffice1.Toolbars = False ThenWebOffice1.Toolbars = True

ElseWebOffice1.Toolbars = False

End IfEnd Sub</script>

You can hide the toolbar when you play the slide show too.<script language="vbscript">Sub PalySlideInSameWindows()

WebOffice1.Open “c:\testfile.ppt”WebOffice1. PlaySlideShow TrueWebOffice1.Toolbars = False

End Sub</script>

2. Show/Hide Titlebar

Property: boolean Titlebar;

Description: Shows/Hides the titlebar.

The method allow the developer to show or hide the titlebar in the top of the component.

<script language="vbscript">Sub ToggleTitlebar()

If WebOffice1.Titlebar = False ThenWebOffice1. Titlebar = True

ElseWebOffice1. Titlebar = False

End IfEnd Sub</script>

Page 22 / 35

Page 23: reference

EDraw Office Viewer Component http://www.ocxt.com

In the titlebar there is a icon in the left. Click it you can find a menubar.

3. Show/Hide Menubars

Property: boolean Menubars;

Description: Shows/Hides the Menubars.

The property allows the developer to show or hide the menubar. The menubar will display when you click the icon in the titlebar.

<script language="vbscript">Sub ToggleTitlebar()

If WebOffice1. Menubars = False ThenWebOffice1. Menubars = True

ElseWebOffice1. Menubars = False

End IfEnd Sub</script>

4. Modify the Caption

Property: BSTR Caption;

Description: Set the caption of the titlebar.

The property allows the developer to modify the caption in the titlebar.

<object classid="clsid:053AFEBA-D968-435F-B557-19FF76372B1B" id="EDrawOfficeViewer1" width="657" height="452">

<param name="Caption" value="EDraw Office Viewer Component"></object>

5. Modify the Border Style

Property: short BorderStyle;

Description: Set the caption of the titlebar.

The property allows the developer to modify the border style. It can be the follow value:

typedef enum BorderStyle{

BorderNone = 0,BorderFlat,Border3D,Border3DThin

} BorderStyle;<object classid="clsid:053AFEBA-D968-435F-B557-19FF76372B1B"

Page 23 / 35

Page 24: reference

EDraw Office Viewer Component http://www.ocxt.com

id="EDrawOfficeViewer1" width="657" height="452"><param name="BorderStyle" value="2">

</object>

6. Modify the Loading Text

Property: BSTR WaitingText;

Description: Set the waiting string when load a document.

The property allows the developer to modify the wait text.

<object classid="clsid:053AFEBA-D968-435F-B557-19FF76372B1B" id="EDrawOfficeViewer1" width="657" height="452">

<param name="WaitingText" value="Loading the office document!"></object>

7. Set the Full Path for Document

Property: BSTR DocumentFullName;

Description: Set the full document name.

The property allows the developer to set a full document name. If the value is NULL, the component will ignore it. Otherwise the component will save the document to the path when you click Save button.

<object classid="clsid:053AFEBA-D968-435F-B557-19FF76372B1B" id="EDrawOfficeViewer1" width="657" height="452">

<param name="DocumentFullName" value=”c:\windows\temp\temp.doc”></object>

8. Set the Color Scheme for the component

Properties:

OLE_COLOR BorderColor;

OLE_COLOR BackColor;

OLE_COLOR ForeColor;

COLOR TitlebarColor;

OLE_COLOR TitlebarTextColor;

Description: Set the color secheme for the component.

<object classid="clsid:053AFEBA-D968-435F-B557-19FF76372B1B" id="EDrawOfficeViewer1" width="657" height="452">

<param name="BorderColor" value="-2147483632"><param name="BackColor" value="-2147483643"><param name="ForeColor" value="-2147483640">

Page 24 / 35

Page 25: reference

EDraw Office Viewer Component http://www.ocxt.com

<param name="TitlebarColor" value="-2147483635"><param name="TitlebarTextColor" value="-2147483634">

</object>

9. Localize the File Menubars

Properties:

BSTR FileMenu;

BSTR FileMenu_New;

BSTR FileMenu_Open;

BSTR FileMenu_Close;

BSTR FileMenu_Save;

BSTR FileMenu_SaveAs;

BSTR FileMenu_PageSetup;

BSTR FileMenu_PrintPreview;

BSTR FileMenu_Print;

BSTR FileMenu_Properties;

Description: Set the caption of file menu.

The component allows the developer to localize the file menubars by setting the above properties.

<object classid="clsid:053AFEBA-D968-435F-B557-19FF76372B1B" id="EDrawOfficeViewer1" width="657" height="452">

<param name="FileMenu" value="&amp;File"><param name=" FileMenu_New" value="&amp;New... Ctrl+N "><param name=" FileMenu_Open" value="&amp;Open... Ctrl+O "><param name=" FileMenu_Close" value="&amp;Close "><param name=""FileMenu_Save" value="&amp;Save Ctrl+S "><param name=" FileMenu_SaveAs" value=" Save &amp;As..."><param name=" FileMenu_PageSetup" value=" Page Set&amp;up..."><param name=" FileMenu_PrintPreview" value=" Print Pre&amp;view "><param name=" FileMenu_Print" value="&amp;Print..."><param name=" FileMenu_Properties" value=" Propert&amp;ies "><param name=" FileMenu_ExitPrintPreview" value=" E&amp;xit PrintPreview

"></object>

Events

1. Customize the File Command

Event: void OnFileCommand([in] FileCommandType Item, [in,out] VARIANT* Cancel);

Page 25 / 35

Page 26: reference

EDraw Office Viewer Component http://www.ocxt.com

Description: Called when File menu item is selected by user (may be canceled).

Every time a user selects an item from the File menu or an item on a toolbar that is associated with a file command, the OnFileCommand event is raised. The event allows you to override the default behavior for the control and supply your own custom actions and dialog boxes to do normal file operations.VB 6.0

Private Sub EDrawOfficeViewer1_OnFileCommand(ByVal Item As EDrawOfficeViewerLib.FileCommandType, Cancel As Variant)If Item = FilePrint Then MsgBox "You asked to print, but I won't allow it." Cancel = True End If End Sub

HTML + JScript<script language="JScript" for=EDrawOfficeViewer1 event="OnFileCommand (Item, Cancel)"> OnFileCommandEvent(Item, Cancel);</script>

<script language=javascript> function OnFileCommandEvent (Item, Cancel) {

Alert(“Respond the File Command Event.”);}</script>

HTML + VBScript<SCRIPT FOR= EDrawOfficeViewer1 EVENT= OnFileCommand (Item, Cancel)> OnFileCommandEvent(Item, Cancel)</SCRIPT>

<script language=VBSrcript> Sub OnFileCommandEvent (Item, Cancel)

MsgBox “Respond the File Command Event.”End Sub</script>

2. Document Opened Event

Event: void OnDocumentOpened([in] BSTR FileName, [in] IDispatch* Document);

Description: Called when document is opened or new document added.

Every time a user opened a file successfully, the OnDocumentOpened event is raised. The event allows you to override the default behavior for the control and supply your own custom actions and dialog boxes to do normal file operations.

Page 26 / 35

Page 27: reference

EDraw Office Viewer Component http://www.ocxt.com

HTML + JScript<script language="JScript" for=EDrawOfficeViewer1 event=" OnDocumentOpened(FileName, Document)"> OnDocumentOpenedEvent(FileName, Document);</script>

<script language=javascript> function OnDocumentOpenedEvent(FileName, Document) {

Alert(“Respond the Document Opened Event.”);}</script>

3. Document Close Event

Event: void OnDocumentClosed();

Description: Called when document is closed.

Every time a user closed a file successfully, the OnDocumentClosed event is raised. The event allows you to override the default behavior for the control and supply your own custom actions and dialog boxes to do normal file operations.HTML + JScript

<script language="JScript" for=EDrawOfficeViewer1 event=" OnDocumentClosed()"> OnDocumentClosedEvent();</script>

<script language=javascript> function OnDocumentClosedEvent() {

Alert(“Respond the Document Close Event.”);}</script>

4. Activation Change Event

Event: void OnActivationChange([in] VARIANT GoingActive);

Description: Called when component gains/loses activation.

Every time a user opens a new document or closes a document the OnActivationChange event is raised. The event allows you to override the default behavior for the control and supply your own custom actions and dialog boxes to do normal file operations.HTML + JScript

<script language="JScript" for=EDrawOfficeViewer1 event=" OnActivationChange(GoingActive)">

Page 27 / 35

Page 28: reference

EDraw Office Viewer Component http://www.ocxt.com

OnActivationChangeEvent(GoingActive);</script>

<script language=javascript> function OnActivationChangeEvent (GoingActive){

Alert(“Respond the Activation Change Event.”);}</script>

5. Before Document Closed Event

Event: void BeforeDocumentClosed([in] IDispatch* Document, [in,out] VARIANT* Cancel);

Description: Called before document is closed (may be canceled).

Every time before a user closed a document the OnActivationChange event is raised. The event allows you to override the default behavior for the control and supply your own custom actions and dialog boxes to do normal file operations.HTML + JScript

<script language="JScript" for=EDrawOfficeViewer1 event=" BeforeDocumentClosed (Document, Cancel)"> OnBeforeDocumentClosedEvent(GoingActive);</script>

<script language=javascript> function OnBeforeDocumentClosedEvent (GoingActive){

Alert(“Respond the Before Document Closed Event.”);}</script>

6. Before Document Saved Event

Event: void BeforeDocumentSaved([in] IDispatch* Document, [in] BSTR Location, [in,out] VARIANT* Cancel);

Description: Called before document is saved (may be canceled).

Every time a user opens a new document or closes a document the OnActivationChange event is raised. The event allows you to override the default behavior for the control and supply your own custom actions and dialog boxes to do normal file operations.HTML + JScript

<script language="JScript" for=EDrawOfficeViewer1 event=" BeforeDocumentSaved(Document, Location, Cancel)"> OnBeforeDocumentSavedEvent(GoingActive);

Page 28 / 35

Page 29: reference

EDraw Office Viewer Component http://www.ocxt.com

</script>

<script language=javascript> function OnBeforeDocumentSavedEvent (Document, Location, Cancel){

Alert(“Respond the Before Document Saved Event.”);}</script>

7. Print Preview Exit Event

Event: void OnPrintPreviewExit();

Description: Called when print preview is closed.

Every time a user closes the print preview the OnPrintPreviewExit event is raised. The event allows you to override the default behavior for the control and supply your own custom actions and dialog boxes to do normal file operations.HTML + JScript

<script language="JScript" for=EDrawOfficeViewer1 event="OnPrintPreviewExit ()"> OnPrintPreviewExitEvent(GoingActive);</script>

<script language=javascript> function OnPrintPreviewExitEvent (GoingActive){

Alert(“Respond the Print Preview Exit Event.”);}</script>

8. Before Document Print Event

Event: HRESULT BeforeDocumentPrint();

Description: Called before print a document.

Every time before a user print a document the OnActivationChange event is raised. The event allows you to override the default behavior for the control and supply your own custom actions and dialog boxes to do normal file operations.HTML + JScript

<script language="JScript" for=EDrawOfficeViewer1 event=" OnBeforeDocumentPrint(GoingActive)"> OnBeforeDocumentPrintEvent(GoingActive);</script>

<script language=javascript> function OnBeforeDocumentPrintEvent(GoingActive){

Page 29 / 35

Page 30: reference

EDraw Office Viewer Component http://www.ocxt.com

Alert(“Respond the Before Document Print Event.”);}</script>

9. Mouse Event

Event: HRESULT OnWindowBeforeRightClick();

Description: Called before right click the component.

Event: HRESULT OnWindowBeforeDoubleClick();

Description: Called before double click the component.

Every time before a user click the component with right key mouse the OnWindowBeforeRightClick event is raised. Every time before a user double click the component the OnWindowBeforeDoubleClick event is raised. The event allows you to override the default behavior for the control and supply your own custom actions and dialog boxes to do normal file operations.

10. Ready to Open Document Event

Event: HRESULT NotifyCtrlReady();

Description: Ready to open document.

When the component finished the initialization the NotifyCtrlReady event is raised. The event allows you to open a new document after the component has released all the resource and is ready to open a new document.HTML + JScript

<html><script language=javascript> function NotifyCtrlReadyEvent (){

EDrawWebOffice1.BeginWaitEDrawWebOffice1.Open “http://www.ocxt.com/demo/sample.doc”EDrawWebOffice1.EndWait

}</script>

<body><object classid="clsid:053AFEBA-D968-435F-B557-19FF76372B1B" id="EDrawOfficeViewer1" width="657" height="452">

<param name="Titlebar" value="1"><param name="Toolbars" value="0">

</object></body>

Page 30 / 35

Page 31: reference

EDraw Office Viewer Component http://www.ocxt.com

<script language="JScript" for=EDrawOfficeViewer1 event=" NotifyCtrlReady ()"> NotifyCtrlReadyEvent ();

</script> </html>

More Help: Visit http://www.ocxt.comScreenshot:

Page 31 / 35

Page 32: reference

EDraw Office Viewer Component http://www.ocxt.com

Enumerable Variables

typedef enum BorderStyle{

BorderNone = 0,BorderFlat,Border3D,Border3DThin

} BorderStyle;

typedef enum ShowDialogType{

DialogNew = 0,DialogOpen,DialogSave,DialogSaveCopy,DialogPrint,DialogPageSetup,DialogProperties

} ShowDialogType;

typedef enum FileCommandType{

FileNew = 0,FileOpen,FileClose,FileSave,FileSaveAs,FilePrint,FilePageSetup,FileProperties,FilePrintPreview

} FileCommandType;

typedef enum XlFileFormat{

xlAddIn = 18,xlCSV = 6,xlCSVMac = 22,xlCSVMSDOS = 24,xlCSVWindows = 23,xlDBF2 = 7,

Page 32 / 35

Page 33: reference

EDraw Office Viewer Component http://www.ocxt.com

xlDBF3 = 8,xlDBF4 = 11,xlDIF = 9,xlExcel2 = 16,xlExcel2FarEast = 27,xlExcel3 = 29,xlExcel4 = 33,xlExcel5 = 39,xlExcel7 = 39,xlExcel9795 = 43,xlExcel4Workbook = 35,xlIntlAddIn = 26,xlIntlMacro = 25,xlWorkbookNormal = -4143,xlSYLK = 2,xlTemplate = 17,xlCurrentPlatformText = -4158,xlTextMac = 19,xlTextMSDOS = 21,xlTextPrinter = 36,xlTextWindows = 20,xlWJ2WD1 = 14,xlWK1 = 5,xlWK1ALL = 31,xlWK1FMT = 30,xlWK3 = 15,xlWK4 = 38,xlWK3FM3 = 32,xlWKS = 4,xlWorks2FarEast = 28,xlWQ1 = 34,xlWJ3 = 40,xlWJ3FJ3 = 41,xlUnicodeText = 42,xlHtml = 44

}XlFileFormat;

typedef enum WdSaveFormat{

wdFormatDocument = 0,wdFormatTemplate = 1,wdFormatText = 2,wdFormatTextLineBreaks = 3,wdFormatDOSText = 4,

Page 33 / 35

Page 34: reference

EDraw Office Viewer Component http://www.ocxt.com

wdFormatDOSTextLineBreaks = 5,wdFormatRTF = 6,wdFormatUnicodeText = 7,wdFormatEncodedText = 7,wdFormatHTML = 8

}WdSaveFormat;

typedef enum PpSaveAsFileType{

ppSaveAsPresentation = 1,ppSaveAsPowerPoint7 = 2,ppSaveAsPowerPoint4 = 3,ppSaveAsPowerPoint3 = 4,ppSaveAsTemplate = 5,ppSaveAsRTF = 6,ppSaveAsShow = 7,ppSaveAsAddIn = 8,ppSaveAsPowerPoint4FarEast = 10,ppSaveAsDefault = 11,ppSaveAsHTML = 12,ppSaveAsHTMLv3 = 13,ppSaveAsHTMLDual = 14,ppSaveAsMetaFile = 15,ppSaveAsGIF = 16,ppSaveAsJPG = 17,ppSaveAsPNG = 18,ppSaveAsBMP = 19

}PpSaveAsFileType;

typedef enum PpViewType{

ppViewHandoutMaster = 4,ppViewMasterThumbnails = 12,ppViewNormal = 9,ppViewNotesMaster = 5, ppViewNotesPage = 3,ppViewOutline = 6,ppViewPrintPreview = 10, ppViewSlide = 1,ppViewSlideMaster = 2, ppViewSlideSorter = 7,ppViewThumbnails = 11,ppViewTitleMaster =8

}PpViewType;

Page 34 / 35

Page 35: reference

EDraw Office Viewer Component http://www.ocxt.com

typedef enum WdViewType{

wdMasterView = 5, wdNormalView = 1 ,wdOutlineView = 2,wdPrintPreview = 4 ,wdPrintView = 3, wdReadingView = 7, wdWebView = 6,

}WdViewType;

typedef enum XlViewType{

xlNormalView = 1 ,xlPageBreakPreview = 2,

}XlViewType;

Page 35 / 35