ADS BY GOOGLE SEE

Thursday, July 2, 2009

How to Load a List in OpenOffice Impress

OpenOffice Impress is a presentation program similar to PowerPoint and is part of the OpenOffice application suite. It is frequently desirable to populate a list box from an external data source like a spreadsheet. Fortunately, Impress has a macro writing capability like other components of OpenOffice. The following steps will show how to load a list in OpenOffice Impress with a macro.
Instructions
  1. Step 1

    Use Universal Network Objects (UNO) methods for short lists. UNO is the component model used by OpenOffice and is an easy way to create dialog boxes because it is interface-based. By the same token, however, each call to a UNO method requires a considerable amount of time, which can become prohibitive with long lists.

  2. Step 2

    Create variables for intermediate objects as shown in the following code snippet:

    …
    oListBox = oDlg.getControl("ListBox1");
    For i = 0 to 1000;
    oListBox.addItem(…);
    Next;
    …

    This allows us to avoid 1,000 calls to getControl() when performing a name lookup.

  3. Step 3

    Make additional code optimizations to the snippet in Step 2. In this example, we would then keep a separate counter and pass it to addItem() instead of calling getItemCount() 1,000 times.

  4. Step 4

    Fill an array A with string values from a spreadsheet (column A in this example). The following snippet would be placed in a loop:

    yMax = 1000;
    Redim A(yMax) As String;
    For y = 0 to yMax;
    A(y) = mySheet.getCellByPosition(0,y).String;
    Next.

  5. Step 5

    Load the array that was filled in Step 4 to the list box with a single instruction: oDlg.getControl("ListBox1").Model.StringItemList() = A(). Note how this method fills the array internally without making an external library call for each item in the list box. The list box can therefore be populated much more quickly.

No comments:

Post a Comment

ADS BY GOOGLE

flag ctr count

free counters