EDraw Office Viewer Component

EDraw OfficeViewer Component V4.1

Overview

EDrawOffice 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:

Company Home:

Online Demo:

Support Mail:

Sales online:

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 Component

File Name: edrawofficeviewer.ocx

CLSID: 053AFEBA-D968-435f-B557-19FF76372B1B

Version: 4,1,5,21

Release Date: 2007-5-20

OCX 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 "

  1. Change the anchor property of EDrawOfficeViewer1 to Top, Bottom, Left, Right
  2. 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
  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 "

  1. Save your changes and close Visual Basic
  2. Save the form and close it
  3. Double-click on the form to run it.
  4. Click the button. The Word Document should appear!
  5. Experiment by changing the file path to a local file such as:

EDrawOfficeViewer1.Open "c:\test.xls"

Visit 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:booleanCreateNew([in] BSTRProgIdOrTemplate);

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.

Create a blank word document:

WebOffice1. CreateNew "Word.Document "

Create a blank excel sheet:

WebOffice1. CreateNew "Excel.Sheet "

  1. Open documents

Function: booleanOpen([in] VARIANTDocument, [in, optional] VARIANTProgId);

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 “

‘WebOffice1.Open “ “Word.Document”

End Sub

</script>

JavaScript:

<script language="JavaScript">

Function OpenDocument()

{

WebOffice1. Open(" “Word.Document”);

//WebOffice1.Open(“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.Open(varpath, varOpt);
}

  1. Save Documents

Function: booleanSave([in, optional] VARIANTSaveAsDocument, [in, optional] VARIANTWebUsername, [in, optional] VARIANTWebPassword);

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 “

‘WebOffice1.Save “ “UserName”, “Password”

End Sub

</script>

JavaScript:

<script language="JavaScript">

Function OpenDocument()

{

WebOffice1. Save (" “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 "

End Sub

</script>

//UploadAction.aspx.cs file

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

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:

<?php

header("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']);

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_Class

Uploader.NoAllowExt="cs;vb;js;exe"

Uploader.GetData (Request.TotalBytes)

Request.TotalBytes

if 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.End

End if

Dim id

If "" > Request.QueryString("id") then

id = Request.QueryString("id")

End if

if id>0 then

Sql="SELECT * from doc where doc.id = "&id

else

Sql="SELECT * from doc"

End if

rs.Open Sql,conn,1, 3

for each formName in Uploader.file

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 If

set file=nothing

rs.Update

exit for

next

rs.Close

Set rs=Nothing

conn.close

set conn = Nothing

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

%>

  1. Save As

Function: booleanSaveAs([in] BSTRFilePath, [in, optional] VARIANTFileFormat);

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 format

WebOffice1.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>

  1. Call the Standard Open Dialog

Function: booleanCallOpenFileDialog([in, optional] VARIANTFilter);

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>

  1. Call the Standard Save Dialog

Function: booleanCallSaveFileDialog([in, optional] VARIANTFilter);

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>

  1. Show Dialog

Function: booleanShowDialog([in] ShowDialogTypeDlgType);

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.

typedefenumShowDialogType

{

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

</script>

  1. Print

Function:booleanPrintOut([in, optional] VARIANTPromptUser, [in, optional] VARIANTPrinterName, [in, optional] VARIANTCopies, [in, optional] VARIANTFromPage, [in, optional] VARIANTToPage, [in, optional] VARIANTOutputFile);

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>

  1. Print Preview

Function:booleanPrintPreview();

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 Then

Dim bResult = WebOffice1.Printview

If bResult = False Then

WebOffice1.EndPrintPreview

MsgBox ”Fail to prview the document.”

End If

End If

End Sub

  1. Is Dirty

Function: booleanIsDirty();

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 Then

MsgBox “The document has been modified.”

ELSE

MsgBox “The document hasn’t been modified.”

End Sub

</script>

  1. Is Open

Function: booleanIsOpen();

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 Then

WebOffice1.Close

End Sub

</script>

  1. Close Document

Function: booleanClose();

Description: Closes the currently open document.

Return Value:

Nonzero if successful; otherwise 0.

  1. HTTP Upload File

Function: booleanHttpInit();

Description: Initializes the HTTP connection.

Function: booleanHttpAddpostString([in] BSTRName, [in] BSTRValue);

Description: Adds the post parameter.

Parameters:

Name: The parameter name.

Value: The parameter value.

Function: booleanHttpAddPostFile([in] BSTRLocalFilePath, [in] BSTRNewFileName);

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: booleanHttpPost([in] BSTRWebUrl,[in, optional] VARIANTWebUsername, [in, optional] VARIANTWebPassword);

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.HttpInit

WebOffice1.HttpAddpostString "author", "anyname"

WebOffice1.HttpAddpostString "Data", "2007-5-15"

WebOffice1.HttpAddPostFile "", "newfilename.doc"

WebOffice1.HttpPost "

End Sub

</script>

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

  1. HTTP Download File

Function: booleanHttpDownloadFile([in] BSTRWebUrl, [in] BSTRLocalFile);

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.