Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Schongar P.VBScript unleashed.1997

.pdf
Скачиваний:
43
Добавлен:
23.08.2013
Размер:
1.59 Mб
Скачать

31:</OBJECT>

32:<OBJECT ID="DOWN"

33:CLASSID="CLSID:D7053240-CE69-11CD-A777-00DD01143C57"

STYLE="TOP:182pt;LEFT:50pt;WIDTH:41pt;HEIGHT:25pt;

TABINDEX:1;ZINDEX:1;">

34:<PARAM NAME="Caption" VALUE="Down">

35:<PARAM NAME="Size" VALUE="1455;873">

36:<PARAM NAME="FontCharSet" VALUE="0">

37:<PARAM NAME="FontPitchAndFamily" VALUE="2">

38:<PARAM NAME="ParagraphAlign" VALUE="3">

39:<PARAM NAME="FontWeight" VALUE="0">

40:</OBJECT>

41:<OBJECT ID="LEFT"

42:CLASSID="CLSID:D7053240-CE69-11CD-A777-00DD01143C57"

STYLE="TOP:182pt;LEFT:116pt;WIDTH:41pt;HEIGHT:25pt;

TABINDEX:2;ZINDEX:2;">

43:<PARAM NAME="Caption" VALUE="Left">

44:<PARAM NAME="Size" VALUE="1455;873">

45:<PARAM NAME="FontCharSet" VALUE="0">

46:<PARAM NAME="FontPitchAndFamily" VALUE="2">

47:<PARAM NAME="ParagraphAlign" VALUE="3">

48:<PARAM NAME="FontWeight" VALUE="0">

49:</OBJECT>

50:<OBJECT ID="RIGHT"

51:CLASSID="CLSID:D7053240-CE69-11CD-A777-00DD01143C57"

STYLE="TOP:215pt;LEFT:83pt;WIDTH:41pt;HEIGHT:25pt;

TABINDEX:3;ZINDEX:3;">

52:<PARAM NAME="Caption" VALUE="Right">

53:<PARAM NAME="Size" VALUE="1455;873">

54:<PARAM NAME="FontCharSet" VALUE="0">

55:<PARAM NAME="FontPitchAndFamily" VALUE="2">

56:<PARAM NAME="ParagraphAlign" VALUE="3">

57:<PARAM NAME="FontWeight" VALUE="0">

58:</OBJECT>

59:<SCRIPT LANGUAGE="VBScript">

60:<!--

61:-->

62:</SCRIPT>

63:<SCRIPT LANGUAGE="VBScript">

64:<!--

65:Sub UP_Click()

66:Marquee.ScrollPixelsX = "0"

67:Marquee.ScrollPixelsY = "-50"

68:end sub

69:-->

70:</SCRIPT>

71:<SCRIPT LANGUAGE="VBScript">

72:<!--

73:Sub DOWN_Click()

74:Marquee.ScrollPixelsX = "0"

75:Marquee.ScrollPixelsY = "50"

76:end sub

77:-->

78:</SCRIPT>

79:<SCRIPT LANGUAGE="VBScript">

80:<!--

81:Sub LEFT_Click()

82:Marquee.ScrollPixelsX = "-50"

83:Marquee.ScrollPixelsY = "0"

84:end sub

85:-->

86:</SCRIPT>

87:<SCRIPT LANGUAGE="VBScript">

88:<!--

89:Sub RIGHT_Click()

90:Marquee.ScrollPixelsX = "50"

91:Marquee.ScrollPixelsY = "0"

92:end sub

93:-->

94:</SCRIPT>

95:</HTML>

Once again, by simply changing the properties of the ActiveX control, I can change the functionality that is seen in the animation. The important things to note are the fact that ScrollPixelsX and ScrollPixelsY properties control the number of pixels the marquee will display at each interval. The interval is set at 1000 milliseconds when the object is defined, and the name of the URL that holds the HTML file to display is also set. Both of these properties could be changed at runtime with buttons or scrollbars to affect the rate at which the animation runs and which file is displaying.

Do you see a pattern in the examples? Almost all of the functionality built into the ActiveX controls is handled for you. VBScript can affect the properties and produce the types of animations that make a Web site interesting. Creating animations with VBScript is not really a matter of calling a particular series of functions but of creatively using the objects that are at hand. As mentioned before, more and more objects will become available, and some will handle more traditional style path and frame-based animations-but with simple property manipulation you can achieve some interesting and powerful results. Look at the StockTicker and Gradient controls. The Stockticker can display information much the same way the marquee can, but it uses a completely different type of file format, which is good for business applications. Can you see a way to make color-cycling animated page breaks using the gradient object? By using a Timer object and adjusting the StartColor and EndColor properties, it is a sure bet that you can create an HTML page that has content separators that no one has ever seen before.

Other HTML Tags that Provide Multimedia Playback

Most of this chapter has dealt with providing animation control through ActiveX, which is the most logical way to perform the operation with VBScript because you can use VBScript to address the properties of the objects and make changes at runtime. There are several tags not supported by all browsers that allow playback of multimedia files. You cannot use VBScript to change the properties of these tags, but if you are using VBScript to generate HTML pages on the fly it is a good idea to know about them. Once again, the standards are changing even in the world of HTML tags, and those of you with extensive HTML building knowledge will already know these; but the most current tags are as follows:

<img> Using the src property, you can display a GIF or JPG image. This is nearly the same as using the Image control, but your best bet for animating the image is to use an animated GIF and a browser that supports GIFs.

Using the dynsrc property, you can display video files. The string <img dynsrc="myvideo.avi" start="mouseover"> will put the first frame of myvideo.avi on your page and begin displaying it when you move the mouse over it.

<body> Supports a background property that allows you to display a graphic as a tiled wallpaper.

<bgsound> Used much like the <img> tag, this tag lets you specify a source (src) file that is a Wave audio (.WAV) or MIDI (.MID) file so you can play audio on your HTML page. The loop property sets the number of times a MIDI file will play. -1 indicates infinite playback as long as the page is loaded, and a positive integer will set the number of times the file plays.

Using these tags in conjunction with the VBScript Document.Write method, you can generate HTML pages on the fly that actually contain multimedia content. Too bad all the Web pages out there that use CGI scripts don't do that.

Chapter 16

Controlling MS Office Documents in Web Pages

by Ramesh Chandak

CONTENTS

ActiveX

ActiveX Scripting

ActiveX Control Pad

Leveraging Your Investment

Microsoft Office Suite

Relevant Web Sites

Review

The browser has revolutionized the way the Internet and Web are accessed. The key to this tremendous success is very simple-an easy-to-use interface coupled with the worldwide network of computers. A product with an easy-to-use interface has been instrumental to the success of several companies. Apple Computer made it big time with the introduction of Macintosh; the Macintosh interface was revolutionary to the people who had been so accustomed to the character-based DOS world. Next followed the Windows 3.1 interface. The most recent wave is the introduction of the browser, which has made it very easy to surf the Internet and the Web. In fact, the hyperlink hot spot concept implemented in the browser was first introduced as part of Hypercard on the Macintosh. But it did not hit the main street until the Web and the browser came together.

What Macintosh and Windows did for the desktop, the browser does for the Net. To begin with, the browser offers point- and-click graphical access to the Net. You can point to a site, link to another site, link to yet another site, and so on. It is the hyperlink capability that makes it so easy. Obviously, users expect more functionality from the browser than just the ability to point and surf! It has become the central point of navigation. It is only natural that a lot of features will be added to the browser in time.

The word processor is probably the most commonly used application in the world today. Again, it is only natural to expect direct links to your word processing documents from your browser. The alternative to this would be to switch to your word processing application, open it, select the document you wish to view, and click OK. This is a tedious and cumbersome task that hampers productivity. It is a lot easier and quicker to click the hot spot on your Web page that represents a word processing document and have it open automatically, without worrying about the format, type, and location of the document.

Along with its other Internet products, Microsoft has announced the release of its ActiveX technology. ActiveX is the level next to OLE. The data transfer technology has come a long way from the days of using Clipboard, to dynamic data exchange (DDE) protocol, to OLE, to now: ActiveX! ActiveX is based on Microsoft's Component Object Model (COM). The COM architecture specifies development of reusable software objects. Such objects can be written in completely different languages. They can reside on completely different platforms across completely different networks. Yet they can communicate and integrate with each other easily. This is the basic premise of the COM theory: creating reusable components that can interact with each other easily, irrespective of their language or location of origin. ActiveX is the

result of Microsoft's five-year investment in research and development of the COM specification. Microsoft renamed OLE controls as ActiveX controls in an effort to push their Internet technology and standards aggressively.

ActiveX technology has multiple paradigms. You can create ActiveX controls and integrate them with your Windows applications. You can make your Web pages active by embedding ActiveX controls in them. An ActiveX control can also be downloaded by the user. As a corporate developer, you can create active documents using ActiveX. An active document is an ActiveX control representing Office documents such as Word, Excel, and PowerPoint.

Using active documents is the focus of this chapter. It discusses how you can make your browser a one-stop access point to your word processing, spreadsheet, and presentation documents.

Listing 16.1 shows HTML code for a sample Web page of this book, VBScript Unleashed, also shown in Figure 16.1. All the documents represented by the hot spots are stored in Microsoft Word 6.0 format.

Figure 16.1 : Sample Web page of this book, VBScript Unleashed.

Listing 16.1. HTML for a sample Web page of this book, VBScript Unleashed.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML><HEAD><TITLE>

VBScript Unleashed

</TITLE></HEAD><!--DocHeaderStart--><BODY leftmargin=8 bgcolor="#FFFFFF"

VLINK="#666666" LINK="#FF0000"><FONT FACE="ARIAL,HELVETICA"

SIZE="2"><!--DocHeaderEnd-->

<P><h2>VBScript Unleashed

</h2><P><!--DATE-->September 1, 1996<P><!--/DATE-->

<P><A HREF="vbs18or.doc">Controlling MS Office Documents in web pages<P>

<P><A HREF="vbs20or.doc">VBScript and Java<P>

<!--DocFooterStart--></FONT><FONT FACE="MS SANS SERIF" SIZE="1"

COLOR="BLACK"><A HREF="/Misc/cpyright.htm" target="_top">©

1996 Sams.net</A></FONT><!--DocFooterEnd--></BODY></HTML>

If you click the hot spot VBScript and Java, it opens the document in Microsoft Word 6.0 format within the Internet Explorer window. See Figure 16.2.

Figure 16.2 : A Microsoft Word document within the Internet Explorer window.

If you want to provide read-only access to your Word or Excel documents (such as human resource policies and employee handbooks), you can use the free application viewers (such as Microsoft PowerPoint Viewer, Microsoft Word Viewer, and Microsoft Excel Viewer).

This chapter provides a brief background on ActiveX technology. It focuses on how you can use ActiveX controls and VBScript to integrate Office documents into your Web pages. Although it specifically discusses Microsoft Office Suite products, the concept and steps involved in configuring them apply to other products such as Lotus Suite as well.

ActiveX

It all started with the need for applications to communicate with each other. In the good old days, data would be transferred between documents of the same application or between applications, using our beloved Clipboard. This changed in due course with the advent of dynamic data exchange (DDE) technology. The Clipboard and DDE eventually became the foundation for OLE. Microsoft actively and aggressively promoted this technology. It eventually became the de facto standard on the Windows platform. OLE made it very easy to embed a variety of documents into the host application. For example, a word processing document can contain a chart, graph, and spreadsheet. The word processing document is the container that holds other objects. Using OLE, applications can import information without the need to understand the format and origin of the data being imported. OLE helps improve the user's overall productivity. Users can focus on their tasks at hand and not worry about the format, origin, and location of the data. The popularity and widespread acceptance of OLE technology created a new industry, developing OCX controls. Hundreds of thousands of shareware and commercial OCX controls are available in the market today.

Having received a wake up call from Netscape and the wired community worldwide, Microsoft announced its own Internet strategy. In addition to introducing a variety of products and services aimed at Internet and intranet development, Microsoft seized this opportunity to promote its ActiveX technology. ActiveX is OLE and much more! ActiveX is OLE redefined for the Internet, and it goes beyond that. Traditional OCXs are large files, not suitable for deployment, and download over the Net. ActiveX is OLE optimized for the Net. It is all-encompassing. You can create ActiveX controls. Such controls can be integrated with your Web and other client/server applications. They can also be downloaded over the Net. Just as you have had hundreds of thousands of VBXs and OCXs integrate with your applications, built using programming tools such as PowerBuilder and Visual Basic, you now have ActiveX controls ready to be integrated with your Web, desktop, and network applications. With ActiveX you can also create active documents. Active documents are ActiveX controls representing Office documents such as Word, Excel, and PowerPoint. You can do ActiveX scripting. ActiveX scripting is writing scripts, using VBScript and ActiveX controls.

At the time of this writing, Microsoft is giving away a suite of ActiveX controls for the Internet. It is called the Internet Control Pack (ICP) and is available for download at http://www.microsoft.com/icp/us/icpdown/

icpdown.htm. You can use these controls to develop your Internet and intranet applications quickly and easily.

NOTE

Microsoft Internet Control Pack includes the following:

Winsock TCP

Winsock UDP

FTP

HTML

HTTP

SMTP

NNTP

POP

ActiveX is presently supported on the Windows platform. ActiveX on the Macintosh and UNIX platforms is expected by

the end of 1996. Microsoft and Metrowerks are working together to include ActiveX support on the Macintosh. Microsoft, Mainsoft, and Bristol are working together to include ActiveX support on the UNIX platform. Microsoft Internet Explorer 3.0 is the only browser on the market today that includes full support for ActiveX and VBScript technology. You can use ActiveX controls with Netscape Navigator 3.0 if you use the ActiveX plug-in from NCompassLabs (http://www.ncompasslabs.com), a third-party software vendor.

NOTE

To stay current with ActiveX technology, visit Microsoft's ActiveX Web site at http://www.microsoft.com/activex.

ActiveX Scripting

ActiveX scripting is writing scripts, using a scripting language such as VBScript, JavaScript, and AppleScript, as well as ActiveX controls. You can integrate any type of object, including ActiveX objects, into your Web pages using the HTML <OBJECT> extension. The ability to integrate ActiveX objects lets you create active Web pages. Such Web pages can be dynamic and interactive in nature. Gone are the days of static Web pages where the surfer could only point, click, and read. You can now add animation and 3-D virtual reality experience to your Web pages and liven them up! If you are a corporate developer, you can integrate ActiveX controls that represent your Office documents on the intranet server. This lets users open Word, Excel, and PowerPoint documents directly, using their browser.

You can write ActiveX controls using programming tools such as Visual C++ and Borland C++ (the same tools that are used to write DLLs and OCX controls). Microsoft has released the ActiveX SDK, a Windows toolkit for Internet and intranet software development. In fact, the Microsoft Internet Explorer 3.0 is written completely using ActiveX SDK. Alternatively, you can buy third-party ActiveX controls developed by Microsoft and other independent software vendors.

You can download Microsoft's freebies-a suite of ActiveX controls-from its ActiveX home page (http://www.

microsoft.com/activex). Table 16.1 lists descriptions of several of these controls.

 

Table 16.1. ActiveX freebies from Microsoft.

Name of control

Description

StockTicker

Continuously displays changing data. The control downloads the URL

 

specified at regular intervals and displays that data. The data can be in

 

text or XRT format.

Label

Displays given text at any specified angle. It can also render the text

 

along user-defined curves.

Marquee

Scrolls, slides, and/or bounces URLs, within a user-defined window.

Chart

Enables you to draw various types of charts with different styles.

Timer

Invokes an event periodically and is invisible at runtime.

Listing 16.2 shows the object declaration for the chart control.

Listing 16.2. Object declaration for Microsoft's ActiveX chart control.

<OBJECT

classid="clsid:FC25B780-75BE-11CF-8B01-444553540000"

id=chart1

width=400

height=200

align=center

hspace=0

vspace=0

>

<param name="hgridStyle" value="3">

<param name="vgridStyle" value="0">

<param name="colorscheme" value="0">

<param name="DisplayLegend" value="0">

<param name="BackStyle" value="1">

<param name="BackColor" value="#ffffff">

<param name="ForeColor" value="#0000ff">

<param name="Scale" value="100">

<param name="url" value="http://www.mycompany.com/chart.txt">

</OBJECT>

ActiveX Control Pad

ActiveX Control Pad is yet another Microsoft application. You can use it to design and develop your Web pages visually. Figure 16.3 shows the ActiveX Control Pad.

Figure 16.3 : The ActiveX Control Pad.

The Control Pad provides a visual way of accomplishing ActiveX scripting. Using the Pad, you can visually insert an ActiveX control into a Web page. Use the Edit | Insert ActiveX Control option to insert an ActiveX control. Figure 16.4 shows the Insert ActiveX Control dialog box.

Figure 16.4 : Inserting an ActiveX control in your Web page using ActiveX Control Pad.

Choose the appropriate control and click OK. The Properties dialog box is displayed. See Figure 16.5.

Figure 16.5 : The ActiveX control properties dialog box.

Use this dialog box to set the properties of the control per your application requirements. After you finish specifying the properties, close the Properties dialog box. The corresponding <OBJECT> code is added within your HTML code.

The following list outlines the steps required to include the ability to open Office documents such as Word, Excel, and PowerPoint within your browser window:

Place all the required Office documents on the server in the appropriate directories.

The host applications (Microsoft Word, Excel, and PowerPoint) should reside on the server or each client machine. Clearly, having them on the server is costand space-effective.

If the users should have read-only access to the documents, set the access level of the directories to read-only. Alternatively, you can use the Office viewers instead of the complete applications.

Use a tool such as ActiveX Control Pad to visually integrate ActiveX Office link controls into your HTML code.

Use the control's Properties dialog box to set the name and location of the host application and the Office documents.

Figure 16.2, earlier in this chapter, shows an example of a Microsoft Word document within the Internet Explorer window.

NOTE

If you do not have Microsoft Word installed on your system or on the Web server, you cannot view the word processing documents from your browser. The presence of the host application on the desktop or the network is required.

NOTE

Office viewers are available for download from Microsoft's Web site:

http://www.microsoft.com.

NOTE

Viewers are also helpful if you have not upgraded from version 2.0 to version 6.0 or 7.0. If you are still using Microsoft Word 2.0 for Windows and plan to upgrade later, you can use the Word Viewer for Windows in the meantime. The Word Viewer takes less resources than the full application and lets you view and print Word 6.0 documents. If you receive Word 6.0 documents from different sources, you can view and print them. Your Word 2.0 documents are upward-compatible with Word 6.0 for Windows.

Leveraging Your Investment

Microsoft Office Suite is the most popular software application package today. A number of corporations have invested