1*cdf0e10cSrcweir {***********************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  *  The Contents of this file are made available subject to the terms of
4*cdf0e10cSrcweir  *  the BSD license.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7*cdf0e10cSrcweir  *  All rights reserved.
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  *  Redistribution and use in source and binary forms, with or without
10*cdf0e10cSrcweir  *  modification, are permitted provided that the following conditions
11*cdf0e10cSrcweir  *  are met:
12*cdf0e10cSrcweir  *  1. Redistributions of source code must retain the above copyright
13*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer.
14*cdf0e10cSrcweir  *  2. Redistributions in binary form must reproduce the above copyright
15*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer in the
16*cdf0e10cSrcweir  *     documentation and/or other materials provided with the distribution.
17*cdf0e10cSrcweir  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18*cdf0e10cSrcweir  *     contributors may be used to endorse or promote products derived
19*cdf0e10cSrcweir  *     from this software without specific prior written permission.
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*cdf0e10cSrcweir  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*cdf0e10cSrcweir  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24*cdf0e10cSrcweir  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25*cdf0e10cSrcweir  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26*cdf0e10cSrcweir  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27*cdf0e10cSrcweir  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28*cdf0e10cSrcweir  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29*cdf0e10cSrcweir  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30*cdf0e10cSrcweir  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31*cdf0e10cSrcweir  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*cdf0e10cSrcweir  *
33*cdf0e10cSrcweir  *************************************************************************}
34*cdf0e10cSrcweir unit SampleCode;
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir interface
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir uses
39*cdf0e10cSrcweir   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
40*cdf0e10cSrcweir   StdCtrls, ComObj, Variants;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir   type
43*cdf0e10cSrcweir     TSampleCode = class
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir     function Connect() : boolean;
46*cdf0e10cSrcweir     procedure Disconnect();
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir     function CreateDocument(bReadOnly : boolean) : boolean;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir     procedure InsertTable(sTableName : String; dbPointer : String);
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir     procedure InsertDatabaseTable(
53*cdf0e10cSrcweir         oDoc : Variant;
54*cdf0e10cSrcweir         sTableName : String;
55*cdf0e10cSrcweir         oCursor : Variant;
56*cdf0e10cSrcweir         iRows : Integer;
57*cdf0e10cSrcweir         iColumns : Integer;
58*cdf0e10cSrcweir         dbPointer : String );
59*cdf0e10cSrcweir     function CreateTextTable(
60*cdf0e10cSrcweir         oDoc : Variant;
61*cdf0e10cSrcweir         oCursor : Variant;
62*cdf0e10cSrcweir         sName : String;
63*cdf0e10cSrcweir         iRow : Integer;
64*cdf0e10cSrcweir         iColumn : Integer) : Variant;
65*cdf0e10cSrcweir     function getCellContent(
66*cdf0e10cSrcweir         sBookmarkName : String ) : Variant;
67*cdf0e10cSrcweir     function getDatabasePointer(
68*cdf0e10cSrcweir         sTableName : String;
69*cdf0e10cSrcweir         sCellname : String ) : String;
70*cdf0e10cSrcweir     procedure InsertBookmark(
71*cdf0e10cSrcweir         oDoc : Variant;
72*cdf0e10cSrcweir         oTextCursor : Variant;
73*cdf0e10cSrcweir         sBookmarkName : String );
74*cdf0e10cSrcweir     function CreateBookmarkName(
75*cdf0e10cSrcweir         sTableName : String;
76*cdf0e10cSrcweir         sCellName : String;
77*cdf0e10cSrcweir         sDatabasepointer : String ) : String;
78*cdf0e10cSrcweir     procedure ChangeCellContent(
79*cdf0e10cSrcweir         oDoc : Variant;
80*cdf0e10cSrcweir         sTableName : String;
81*cdf0e10cSrcweir         sCellName : String;
82*cdf0e10cSrcweir         dValue : Double );
83*cdf0e10cSrcweir     function GetBookmarkFromDBPointer(
84*cdf0e10cSrcweir         oDoc : Variant;
85*cdf0e10cSrcweir         sBookmarkName : String) : Variant;
86*cdf0e10cSrcweir     function GetBookmarkFromAdress(
87*cdf0e10cSrcweir         oDoc : Variant;
88*cdf0e10cSrcweir         sTableName : String;
89*cdf0e10cSrcweir         sCellAdress : String) : Variant;
90*cdf0e10cSrcweir     function JumpToBookmark(
91*cdf0e10cSrcweir         oBookmark : Variant) : Variant;
92*cdf0e10cSrcweir     function CreateUniqueTablename(oDoc : Variant) : String;
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir   private
95*cdf0e10cSrcweir    StarOffice : Variant;
96*cdf0e10cSrcweir    Document : Variant;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir     { Private-Deklarationen }
99*cdf0e10cSrcweir   public
100*cdf0e10cSrcweir     { Public-Deklarationen }
101*cdf0e10cSrcweir   end;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir implementation
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir { Insert a table texttable and insert in each cell a Bookmark with the address
106*cdf0e10cSrcweir   of the cell and database pointer
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir function TSampleCode.Connect() : boolean;
110*cdf0e10cSrcweir begin
111*cdf0e10cSrcweir     if  VarIsEmpty(StarOffice) then
112*cdf0e10cSrcweir         StarOffice := CreateOleObject('com.sun.star.ServiceManager');
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     Connect := not (VarIsEmpty(StarOffice) or VarIsNull(StarOffice));
115*cdf0e10cSrcweir end;
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir procedure TSampleCode.Disconnect();
118*cdf0e10cSrcweir begin
119*cdf0e10cSrcweir     StarOffice := Unassigned;
120*cdf0e10cSrcweir end;
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir function TSampleCode.CreateDocument(bReadOnly : boolean) : boolean;
123*cdf0e10cSrcweir var
124*cdf0e10cSrcweir     StarDesktop : Variant;
125*cdf0e10cSrcweir     LoadParams : Variant;
126*cdf0e10cSrcweir     CoreReflection : Variant;
127*cdf0e10cSrcweir     PropertyValue : Variant;
128*cdf0e10cSrcweir begin
129*cdf0e10cSrcweir    StarDesktop := StarOffice.createInstance('com.sun.star.frame.Desktop');
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir    if (bReadOnly) then begin
132*cdf0e10cSrcweir         LoadParams := VarArrayCreate([0, 0], varVariant);
133*cdf0e10cSrcweir         CoreReflection := StarOffice.createInstance('com.sun.star.reflection.CoreReflection');
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir         CoreReflection
136*cdf0e10cSrcweir                 .forName('com.sun.star.beans.PropertyValue')
137*cdf0e10cSrcweir                 .createObject(PropertyValue);
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir         PropertyValue.Name := 'ReadOnly';
140*cdf0e10cSrcweir         PropertyValue.Value := true;
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         LoadParams[0] := PropertyValue;
143*cdf0e10cSrcweir    end
144*cdf0e10cSrcweir    else
145*cdf0e10cSrcweir         LoadParams := VarArrayCreate([0, -1], varVariant);
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir    Document := StarDesktop.LoadComponentFromURL( 'private:factory/swriter', '_blank', 0,  LoadParams);
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir    CreateDocument := not (VarIsEmpty(Document) or VarIsNull(Document));
150*cdf0e10cSrcweir end;
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir function TSampleCode.getCellContent(
154*cdf0e10cSrcweir     sBookmarkName : String ) : Variant;
155*cdf0e10cSrcweir var
156*cdf0e10cSrcweir     oBookmark : Variant;
157*cdf0e10cSrcweir     oTextCursor : Variant;
158*cdf0e10cSrcweir begin
159*cdf0e10cSrcweir     oBookmark := GetBookmarkFromDBPointer( Document, sBookmarkName );
160*cdf0e10cSrcweir     oTextCursor := JumpToBookmark( oBookmark );
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     getCellContent := oTextCursor.Cell.Value;
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir end;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir function TSampleCode.getDatabasePointer(
168*cdf0e10cSrcweir     sTableName : String;
169*cdf0e10cSrcweir     sCellname : String ) : String;
170*cdf0e10cSrcweir var
171*cdf0e10cSrcweir     oBookmark : Variant;
172*cdf0e10cSrcweir     sBookmarkName : String;
173*cdf0e10cSrcweir     iPos : Integer;
174*cdf0e10cSrcweir begin
175*cdf0e10cSrcweir     oBookmark := GetBookmarkFromAdress( Document, sTableName, sCellName );
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     sBookmarkName := oBookmark.getName();
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir     iPos := Pos('/%', sBookmarkName);
180*cdf0e10cSrcweir     while Pos('/%', sBookmarkName) > 0 do
181*cdf0e10cSrcweir     begin
182*cdf0e10cSrcweir         iPos := Pos('/%', sBookmarkName);
183*cdf0e10cSrcweir         sBookmarkName[iPos] := '%';
184*cdf0e10cSrcweir     end;
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     Delete( sBookmarkName, 1, iPos+1);
187*cdf0e10cSrcweir     getDatabasePointer := sBookmarkName;
188*cdf0e10cSrcweir end;
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir procedure TSampleCode.InsertTable(sTableName : String; dbPointer : String);
192*cdf0e10cSrcweir var
193*cdf0e10cSrcweir    oCursor : Variant;
194*cdf0e10cSrcweir begin
195*cdf0e10cSrcweir    { create a cursor object on the current position in the document }
196*cdf0e10cSrcweir    oCursor := Document.Text.CreateTextCursor();
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir    { Create for each table a unique database name }
199*cdf0e10cSrcweir    if (sTableName = '') then
200*cdf0e10cSrcweir         sTableName := createUniqueTablename(Document);
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir    InsertDatabaseTable( Document, sTableName, oCursor, 4, 2, dbPointer );
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir    ChangeCellContent( Document, sTableName, 'B2', 1.12 );
205*cdf0e10cSrcweir end;
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir procedure TSampleCode.InsertDatabaseTable(
208*cdf0e10cSrcweir     oDoc : Variant;
209*cdf0e10cSrcweir     sTableName : String;
210*cdf0e10cSrcweir     oCursor : Variant;
211*cdf0e10cSrcweir     iRows : Integer;
212*cdf0e10cSrcweir     iColumns : Integer;
213*cdf0e10cSrcweir     dbPointer : String);
214*cdf0e10cSrcweir var
215*cdf0e10cSrcweir     oTable : Variant;
216*cdf0e10cSrcweir     sCellnames : Variant;
217*cdf0e10cSrcweir     iCellcounter : Integer;
218*cdf0e10cSrcweir     oCellCursor : Variant;
219*cdf0e10cSrcweir     oTextCursor : Variant;
220*cdf0e10cSrcweir     sCellName : String;
221*cdf0e10cSrcweir begin
222*cdf0e10cSrcweir     oTable := CreateTextTable( oDoc, oCursor, sTableName, iRows, iColumns );
223*cdf0e10cSrcweir     sCellnames := oTable.getCellNames();
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir     For iCellcounter := VarArrayLowBound( sCellnames, 1) to VarArrayHighBound(sCellnames, 1) do
226*cdf0e10cSrcweir     begin
227*cdf0e10cSrcweir         sCellName := sCellnames[iCellcounter];
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir     	oCellCursor := oTable.getCellByName(sCellName);
230*cdf0e10cSrcweir     	oCellCursor.Value := iCellcounter;
231*cdf0e10cSrcweir     	oTextCursor := oCellCursor.getEnd();
232*cdf0e10cSrcweir         InsertBookmark(
233*cdf0e10cSrcweir                 oDoc,
234*cdf0e10cSrcweir                 oTextCursor,
235*cdf0e10cSrcweir                 createBookmarkName(sTableName, sCellName, dbPointer));
236*cdf0e10cSrcweir     end;
237*cdf0e10cSrcweir end;
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir ' Change the content of a cell
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir procedure TSampleCode.ChangeCellContent(
245*cdf0e10cSrcweir         oDoc : Variant;
246*cdf0e10cSrcweir         sTableName : String;
247*cdf0e10cSrcweir         sCellName : String;
248*cdf0e10cSrcweir         dValue : Double );
249*cdf0e10cSrcweir var
250*cdf0e10cSrcweir     oBookmark : Variant;
251*cdf0e10cSrcweir     oTextCursor : Variant;
252*cdf0e10cSrcweir     sBookmarkName : String;
253*cdf0e10cSrcweir begin
254*cdf0e10cSrcweir     oBookmark := GetBookmarkFromAdress( oDoc, sTableName, sCellName );
255*cdf0e10cSrcweir     oTextCursor := JumpToBookmark( oBookmark );
256*cdf0e10cSrcweir     oTextCursor.Cell.Value := dValue;
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir     { create a new bookmark for the new number }
259*cdf0e10cSrcweir     sBookmarkName := oBookmark.getName();
260*cdf0e10cSrcweir     oBookmark.dispose();
261*cdf0e10cSrcweir     InsertBookmark( oDoc, oTextCursor, sBookmarkName );
262*cdf0e10cSrcweir end;
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir { ' Jump to Bookmark and return for this position the cursor }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir function TSampleCode.JumpToBookmark(
268*cdf0e10cSrcweir         oBookmark : Variant) : Variant;
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir begin
271*cdf0e10cSrcweir 	JumpToBookmark := oBookmark.Anchor.Text.createTextCursorByRange(
272*cdf0e10cSrcweir                 oBookmark.Anchor );
273*cdf0e10cSrcweir end;
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir { ' Create a Texttable on a Textdocument }
277*cdf0e10cSrcweir function TSampleCode.CreateTextTable(
278*cdf0e10cSrcweir         oDoc : Variant;
279*cdf0e10cSrcweir         oCursor : Variant;
280*cdf0e10cSrcweir         sName : String;
281*cdf0e10cSrcweir         iRow : Integer;
282*cdf0e10cSrcweir         iColumn : Integer) : Variant;
283*cdf0e10cSrcweir var
284*cdf0e10cSrcweir     ret : Variant;
285*cdf0e10cSrcweir begin
286*cdf0e10cSrcweir     ret := oDoc.createInstance( 'com.sun.star.text.TextTable' );
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir     ret.setName( sName );
289*cdf0e10cSrcweir     ret.initialize( iRow, iColumn );
290*cdf0e10cSrcweir     oDoc.Text.InsertTextContent( oCursor, ret, False );
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir     CreateTextTable := ret;
293*cdf0e10cSrcweir end;
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir { 'create a unique name for the Texttables }
297*cdf0e10cSrcweir function TSampleCode.CreateUniqueTablename(oDoc : Variant) : String;
298*cdf0e10cSrcweir var
299*cdf0e10cSrcweir     iHighestNumber : Integer;
300*cdf0e10cSrcweir     sTableNames : Variant;
301*cdf0e10cSrcweir     iTableCounter : Integer;
302*cdf0e10cSrcweir     sTableName : String;
303*cdf0e10cSrcweir     iTableNumber : Integer;
304*cdf0e10cSrcweir     i : Integer;
305*cdf0e10cSrcweir begin
306*cdf0e10cSrcweir     sTableNames := oDoc.getTextTables.getElementNames();
307*cdf0e10cSrcweir     iHighestNumber := 0;
308*cdf0e10cSrcweir     For iTableCounter := VarArrayLowBound(sTableNames, 1) to VarArrayHighBound(sTableNames, 1) do
309*cdf0e10cSrcweir     begin
310*cdf0e10cSrcweir     	sTableName := sTableNames[iTableCounter];
311*cdf0e10cSrcweir         i := Pos( '$$', sTableName );
312*cdf0e10cSrcweir     	iTableNumber := strtoint( Copy(sTableName, i + 2, Length( sTableName ) - i - 1 ) );
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir     	If iTableNumber > iHighestNumber then
315*cdf0e10cSrcweir     		iHighestNumber := iTableNumber;
316*cdf0e10cSrcweir     end;
317*cdf0e10cSrcweir     createUniqueTablename := 'DBTable$$' + inttostr(iHighestNumber + 1);
318*cdf0e10cSrcweir end;
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir {' Insert a Bookmark on the cursor }
322*cdf0e10cSrcweir procedure TSampleCode.InsertBookmark(
323*cdf0e10cSrcweir         oDoc : Variant;
324*cdf0e10cSrcweir         oTextCursor : Variant;
325*cdf0e10cSrcweir         sBookmarkName : String);
326*cdf0e10cSrcweir var
327*cdf0e10cSrcweir     oBookmarkInst : Variant;
328*cdf0e10cSrcweir begin
329*cdf0e10cSrcweir     oBookmarkInst := oDoc.createInstance('com.sun.star.text.Bookmark');
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir     oBookmarkInst.Name := sBookmarkName;
332*cdf0e10cSrcweir     oTextCursor.gotoStart( true );
333*cdf0e10cSrcweir     oTextCursor.text.InsertTextContent( oTextCursor, oBookmarkInst, true );
334*cdf0e10cSrcweir end;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir function TSampleCode.CreateBookmarkName(
338*cdf0e10cSrcweir         sTableName : String;
339*cdf0e10cSrcweir         sCellName : String;
340*cdf0e10cSrcweir         sDatabasepointer : String ) : String;
341*cdf0e10cSrcweir begin
342*cdf0e10cSrcweir     createBookmarkName := '//' + sTableName + '/%' + sCellName + '/%' + sDatabasePointer + ':' + sCellName;
343*cdf0e10cSrcweir end;
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir { ' Returns the Bookmark the Tablename and Cellname }
346*cdf0e10cSrcweir function TSampleCode.GetBookmarkFromAdress(
347*cdf0e10cSrcweir         oDoc : Variant;
348*cdf0e10cSrcweir         sTableName : String;
349*cdf0e10cSrcweir         sCellAdress : String) : Variant;
350*cdf0e10cSrcweir var
351*cdf0e10cSrcweir     sTableAddress : String;
352*cdf0e10cSrcweir     iTableNameLength : Integer;
353*cdf0e10cSrcweir     sBookNames : Variant;
354*cdf0e10cSrcweir     iBookCounter : Integer;
355*cdf0e10cSrcweir begin
356*cdf0e10cSrcweir     sTableAddress := '//' + sTableName + '/%' + sCellAdress;
357*cdf0e10cSrcweir     iTableNameLength := Length( sTableAddress );
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir     sBookNames := oDoc.Bookmarks.getElementNames;
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir     for iBookCounter := VarArrayLowBound(sBookNames, 1) to VarArrayHighBound(sBookNames, 1) do
362*cdf0e10cSrcweir     begin
363*cdf0e10cSrcweir     	If sTableAddress = Copy( sBookNames[iBookCounter], 1, iTableNameLength) then
364*cdf0e10cSrcweir         begin
365*cdf0e10cSrcweir     		GetBookmarkFromAdress := oDoc.Bookmarks.getByName(sBookNames[iBookCounter]);
366*cdf0e10cSrcweir     		exit;
367*cdf0e10cSrcweir         end;
368*cdf0e10cSrcweir     end;
369*cdf0e10cSrcweir end;
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir { ' Returns the Bookmark the Tablename and Cellname }
372*cdf0e10cSrcweir function TSampleCode.GetBookmarkFromDBPointer(
373*cdf0e10cSrcweir         oDoc : Variant;
374*cdf0e10cSrcweir         sBookmarkName : String) : Variant;
375*cdf0e10cSrcweir var
376*cdf0e10cSrcweir     sBookNames : Variant;
377*cdf0e10cSrcweir     iBookCounter : Integer;
378*cdf0e10cSrcweir begin
379*cdf0e10cSrcweir     sBookNames := oDoc.Bookmarks.getElementNames;
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir     for iBookCounter := VarArrayLowBound(sBookNames, 1) to VarArrayHighBound(sBookNames, 1) do
382*cdf0e10cSrcweir     begin
383*cdf0e10cSrcweir     	If Pos(sBookmarkName, sBookNames[iBookCounter]) = (1 + Length(sBookNames[iBookCounter]) - Length(sBookmarkName)) then
384*cdf0e10cSrcweir         begin
385*cdf0e10cSrcweir     		GetBookmarkFromDBPointer := oDoc.Bookmarks.getByName(sBookNames[iBookCounter]);
386*cdf0e10cSrcweir     		exit;
387*cdf0e10cSrcweir         end;
388*cdf0e10cSrcweir     end;
389*cdf0e10cSrcweir end;
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir end.
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 
394