Working with OLE

book list add book to my bookshelf create a bookmark purchase this book online

mastering crystal reports 9
Chapter 3 - Formatting Fields and Objects
Mastering Crystal Reports 9
by Cate McCoy and Gord Maric
Sybex 2003

Do you have a Microsoft Excel spreadsheet that you’ve been perfecting and maintaining for years that perfectly represents a piece of your business? And now you’ve been asked to do the same thing in Crystal Reports? There is no need to start from scratch and rebuild all the same capabilities into a report. Instead, object linking and embedding (OLE) might be just what you need.

OLE is a technical standard that allows one software application to share its information with other software applications. The goal is the integration of technologies, for example, Microsoft Excel and Crystal Reports, while allowing each application to do what it does best. In this case, Crystal Reports is a great report-writing application and Microsoft Excel is a terrific spreadsheet application. The most effective way to include spreadsheet capabilities in Crystal Reports is not to build this functionality into Crystal but instead to make use of the existing Microsoft Excel spreadsheet technology. The result is a Crystal Report that contains a Microsoft Excel spreadsheet.

OLE Components

OLE technology can be broken down into five components working together to create a shared information environment. The five pieces are shown in Figure 3.24. Let’s look at each one separately.

OLE server application This is a software application that allows its information to be used in OLE container applications. Examples include Microsoft Excel, Microsoft Paint, and Microsoft Word.

OLE container application This is a software application that uses information from OLE server applications. Crystal Reports is a container application.

Server document This document is a file created and stored using the OLE server application, e.g., an Excel spreadsheet stored in an XLS file.

Container document This document is a file created and stored using the OLE container application, e.g., a Crystal Report. A container document can contain OLE objects. A container document is also known as a compound document.

OLE object This is an item that becomes a part of the container document but retains a connection to or relationship with the server document.

click to expand
Figure 3.24. OLE components

Adding OLE Objects to a Report

An OLE object can be added to a Crystal Report by linking it, embedding it, or creating a copy of it. The choice of which method to use is often driven by the availability of the OLE server application and runtime performance considerations.

Linking

Linked items placed in a Crystal Report maintain a connection or reference to the original source document. If you edit the OLE object from within Crystal, the changes you make are actually being made back in the original file outside of Crystal. Any other applications that are linked to the same object would automatically detect and display any updates to the source document. So, if one spreadsheet was embedded in several reports, using the link method would guarantee that each Crystal Report always contains the most up-to-date spreadsheet information.

The process of creating an OLE link begins with the menu sequence Insert > OLE Object. The next choice is whether to create a new OLE object in this report or to link to an existing external object by selecting an object type. The list of object types is unique to each computer because the information is pulled from the software registry of installed products. For this example, we’ll choose to create a new Microsoft Excel Worksheet inside of Crystal, as shown in Figure 3.25.

click to expand
Figure 3.25. Linking to Excel

When you click the OK button on the Insert Object dialog shown in Figure 3.25, the familiar gray placement rectangle appears in Design mode, and you can drop the embedded object in whichever section of the report makes sense for your purposes.

At this point, a new worksheet labeled with the name of your report is created as Crystal opens the Excel application. Figure 3.26 shows the file Worksheet in CH03.rpt, and you can see Excel open behind it with Crystal open on the task bar at the bottom. This gives you the full power of all the Excel menu commands to create the spreadsheet. After we opened this particular spreadsheet in Crystal, we entered the column for CostBasis and its values. You can also choose Insert > Name > Define from the Excel menu to name a cell. Named cells can be linked directly to a report field in Crystal Reports so that when the cell changes in Excel, the update is reflected in the report’s field value. In Figure 3.26, cell A2 has been given the name CostBasisA2.

click to expand
Figure 3.26. Linking to a cell

There are two types of links that can be included in a report:

  • Automatic

  • Manual

When an automatic link is used, when the report is opened, the most recent information stored in the source document is retrieved and added to the report. By comparison, a manual link provides an icon that you click in the report to retrieve the most recent information on demand. A linked OLE object is an automatic link by default. To modify this setting, select the OLE object and choose Edit > Links to display the Links dialog shown in Figure 3.27.

click to expand
Figure 3.27. Editing links

The radio buttons at the bottom let you choose between automatic or manual updating. The buttons along the right side of the dialog give you the opportunity to force an immediate refresh of the object, open the object in the source application, change the object source, or break the link entirely. Breaking the link converts the OLE object to an embedded object.

Embedding

When you embed an OLE object into Crystal Reports, the original document is displayed in your report. Embedding does not maintain a link back to the original document for purposes of data refreshes. This means that if something changes in the original, the Crystal report will reflect the information as it existed at the time it was embedded and not how it exists after being updated. You can, however, edit the version of OLE object stored in the report. This is called in-place editing, and the source application must exist on the computer being used to view the report. The original object used to create the embedded object is not modified by the editing process; only the version of it that exists in the report is modified.

Let’s take the example of embedding a Microsoft Paint BMP graphic into our report. You begin by choosing Insert > OLE Object from the menu as you did with linking. You can choose to create a new object directly in your report or create the object using an existing file. For our example, the difference between these in practical terms is that you can either draw the picture inside Microsoft Paint, which is included in Crystal Reports, or you can use an existing BMP file that was created previously with Microsoft Paint. Figure 3.28 demonstrates the latter type of embedding.

click to expand
Figure 3.28. Embedding a BMP file

Notice also that in Figure 3.28 the check box to Display As Icon is checked; this option will display Microsoft’s Paintbrush icon in your Crystal Report as a clickable icon. The icon that you will see in the report is actually shown on this dialog; you can replace this icon with another using the Change Icon button. When a user clicks the icon in the report, the Paintbrush application opens and the image you embedded is displayed. The technique of using an icon can preserve initial real estate in your report, effectively displaying the embedded object only if the person using the report wants to see it.

Warning 

To embed the object, be sure to leave the Link check box unchecked.

If you leave the Display As Icon check box in Figure 3.28 unchecked, the BMP image is displayed directly in your report. Right-clicking the image gives you the opportunity to edit, open, or convert it using the Bitmap Image Object menu. The menu option Bitmap Image Object is specific to OLE objects that are of the BMP type. If the OLE object was of another type, the menu item would refer more specifically to that type of object. For instance, if the object was an Excel spreadsheet, the menu item displayed would be Worksheet Object. The options to edit and to open are self-explanatory; the option to convert allows you to display the OLE object as an icon or in its entirely on initial opening of the report.

Note 

The OLE object and its edit, open, and convert tasks are also directly accessible from the main Edit menu in Crystal Reports.

Copying

Copying an OLE object is also referred to as working with static OLE objects. The idea behind a static OLE object is that the item is placed in the report in its entirety with no connection to the original stored version. This completely suppresses the ability to edit the object inside Crystal Reports. An example of inserting a static OLE object is choosing Insert > Picture to add a graphic to a report.

The static OLE technique expands the list of external data objects that can be added to a report, especially in the area of graphics, since Crystal does not have to provide a way to edit the object. With Insert > Picture, all of the following image types are supported: BMP, TIFF, JPEG, PNG, and Windows Metafiles.

In some cases, a static OLE object can be converted to an editable OLE object using a variation of the Convert menu option discussed earlier. By right-clicking the static object or by choosing the Edit menu with the object selected, the Convert Picture Object option is available. After conversion, the ability to actually edit the object from a report is dependant on the presence of the underlying application. For instance, to convert a static BMP object to an editable BMP object, the Microsoft Paint application needs to be present on the computer that is attempting the edit process.

Use of content on this site is expressly subject to the restrictions set forth in the Membership Agreement
 
Conello © 2000-2003     Feedback


Mastering Crystal Reports 9
Mastering Crystal Reports 9
ISBN: 0782141730
EAN: 2147483647
Year: 2005
Pages: 217

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net