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