Working Solution for Worksheet Resizing

Background

In Adding Ole Frames article, we have explained how to add an Ole Frame in presentation in a PowerPoint Presentation using Aspose.Slides for .NET. In order to accommodate the object changed issue, we assigned the worksheet image of selected area to the Chart OLE Object Frame. In the output presentation, when we double click the OLE Object Frame showing the worksheet Image, the Excel Chart is activated. The end users can make any desired changes in the actual Excel Workbook and then return to the concerned Slide by clicking outside the activated Excel Workbook. The size of the OLE Object Frame will change when the user gets back to the slide. The resizing factor will be different for different sizes of OLE Object Frame and embedded Excel Workbook.

Cause of Resizing

Since the Excel Workbook has its own window size, it tries to retain its original size on first time activation. On the other hand, the OLE Object Frame will have its own size. According to Microsoft, on activation of the Excel Workbook, Excel and PowerPoint negotiate the size and ensure it is in the correct proportions as part of the embedding operation. Based on the differences in the Excel Windows size and OLE Object Frame size / position, the resizing takes place.

Working Solution

There are two possible solutions to avoid the re-sizing effect.

  • Scale the Ole frame size in PPT to match the size in terms of height/width of desired number of rows/columns in Ole Frame
  • Keeping the Ole frame size constant and scale the size of participating rows/columns to get fit in selected Ole frame size

Scale Ole frame size to Worksheet’s selected rows/ columns size

In this approach, we will learn how to set the Ole frame size of the embedded Excel Workbook equivalent to the cumulative size of number of participating rows and columns in Excel Worksheet.

Example

Suppose, we have defined a template excel sheet and and desire to add that to presentation as Ole frame. In this scenario, the size of the OLE Object Frame will be calculated first based on cumulative rows height and columns widths of participating workbook’s rows and columns respectively. Then we will set the size of Ole frame to that calculated value. In order to avoid the red Embedded Object message for Ole frame in PowerPoint we will also get the image of desired portions of rows and columns in Workbook and set that as Ole frame image.

Scale worksheet’s row height and column width according to Ole Frame size

In this approach, we will learn how to scale the heights of participating rows and width of participating column in accordance with custom set ole frame size

Example

Suppose, we have defined a template excel sheet and and desire to add that to presentation as Ole frame. In this scenario, we will set the size of Ole frame and scale the size of rows and columns participating in Ole Frame area. We will then save the workbook in stream to save changes and convert that to byte array for adding it in Ole frame. In order to avoid the red Embedded Object message for Ole frame in PowerPoint we will also get the image of desired portions of rows and columns in Workbook and set that as Ole frame image.

Conclusion

Creating and Embedding an Excel Chart as OLE Object in Presentation

Updating OLE Objects automatically