Issue 33783 - can not set AnchorType of a control in calc via API
Summary: can not set AnchorType of a control in calc via API
Alias: None
Product: Base
Classification: Application
Component: code (show other issues)
Version: OOo 3.1
Hardware: All All
: P3 Trivial (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
Depends on:
Reported: 2004-09-02 20:03 UTC by Oliver Brinzing
Modified: 2017-05-20 10:47 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---

here's an example that works right now (8.23 KB, application/vnd.oasis.opendocument.spreadsheet)
2009-05-20 09:07 UTC, caolanm
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description Oliver Brinzing 2004-09-02 20:03:57 UTC

AFAIK it is not possible to anchor a control AT_PAGE as I can do it in writer.
In calc all controls will be anchored at cell ...
Please have a look at the macro ...

Has it something to do with my issue

or can this be fixed soon ?




Option Explicit

Sub CreateControl

	Dim oDocument as Object
	Dim oView as Object
	Dim oDrawPage as Object
	Dim oController as Object

	Dim oControlShape as Object
	Dim oControlModel as Object
	Dim oSize as New
	Dim oPosition as New

	oDocument = StarDesktop.getCurrentComponent
	oView = oDocument.CurrentController

	If Not hasUnoInterfaces(oDocument, "") Then
		oDrawPage = oDocument.DrawPage
		oDrawPage = oView.getActiveSheet.DrawPage

	oControlShape = oDocument.createInstance("")

	oSize.Height = 1000
	oSize.Width = 3000
	oPosition.X	= 2000
	oPosition.Y = 3000


	' this works only for Writer ...
	' I am missing the "AnchorType" for calc with the options AT_CELL / AT_PAGE
	' all controlls will be anchored at cell ...

	oControlModel = createUNOService("")
	oControlModel.Name = "My Control"
	oControlModel.Enabled = True

	oController = oView.getControl(oControlModel)
End Sub
Comment 1 marc.neumann 2004-09-09 14:14:39 UTC
Hi Frank,

the attached macro doesn't work as expect.

Is there any anchor type for spreadsheets?

Bye Marc
Comment 2 Frank Schönheit 2004-09-10 09:11:01 UTC
well, as the name suggests, css.text.TextContentAnchorType is a Writer feature.
It seems that in Calc, shapes cannot be anchored via API at all.
You could argue whether this is a bug (since our API should be complete,
shouldn't it?) or a missing feature ...
Anyway, assigning to nn, who's in charge for the Calc/API.
Comment 3 niklas.nebel 2004-09-13 13:45:48 UTC
Shapes in a spreadsheet have the property "Anchor" (can be set only after
inserting the shape, modifies the position).
Comment 4 Oliver Brinzing 2004-09-13 17:52:13 UTC
Hi Niklas,

> Shapes in a spreadsheet have the property "Anchor"

this seems to be true, I can access the anchored cell ...

> (can be set only after inserting the shape, modifies the position).

I don't know how to *set* a new anchor "at cell", or how to set "at page"
oControlShape.Anchor = oCell does not work, seems to be write protected ...

Could you please provide an example ?

best regards

Comment 5 Oliver Brinzing 2006-02-17 13:52:32 UTC

this issue is still valid for oo 2.0.2 rc1 ...

Comment 6 Oliver Brinzing 2009-05-19 07:58:49 UTC
verified in oo 3.1 - all controls are anchored AT_CELL.
AT_PAGE can be done only via GUI.
are there any plans to fix this issue ?
Comment 7 caolanm 2009-05-20 09:07:02 UTC
Created attachment 62390 [details]
here's an example that works right now
Comment 8 caolanm 2009-05-20 09:09:58 UTC
FWIW, after insertion, using...
	oControlShape.setPropertyValue("Anchor", oCell)
	oControlShape.setPropertyValue("Anchor", oSheet)
toggles from cell anchored to sheet anchored in the attached example
Comment 9 Frank Schönheit 2009-05-20 09:21:32 UTC
Oliver, can you verify this works now?

Without looking at Caolan's macro, I am pretty sure the issue is fixed: I used
the API to change an object's anchor in Calc, when I fixed issue 99056, and it
worked flawlessly :)
Comment 10 Oliver Brinzing 2009-05-21 16:12:54 UTC
i just tried:
  oControlShape.setPropertyValue("Anchor", oSheet)

this will toggle to sheet anchored - but also set the controls 
position to strange X/Y positions:

for example:

X/Y                   controls X/Y
100/100	          0,1/0,1cm
1000/1000	 1,0/0,1cm
2000/2000	 2,0/0,19 cm
3000/3000  	 0,74/0,29cm

using oControlShape.setPropertyValue("Anchor",    
will set the *anchor* to cell  C3 - with shapes oPosition.X=0  and oPosition.Y=0
it works like expected.

setPropertyValue("Anchor") before inserting the control has no effect
in this case the control is anchored to cell...
Comment 11 Frank Schönheit 2009-05-21 20:05:00 UTC
Oliver, I remember having had strange effects with the position, too. Well, at
least unexpected, though perhaps explainable ...
First, when you switch the anchor from a cell to the sheet, you need to get the
shape's position first, and restore it after setting the Anchor property. This
way, the control/shape stays where it was before changing the anchor. Otherwise,
the position previously relative to the cell is now relative to the sheet, which
makes the control jumping.
Second, when you switch the anchor from the sheet to a cell, you also need to
adjust the position, to prevent the control jumping. You might want to look into
the impl_setSheetAnchorType_nothrow method in
to see how I solved that.

In any way, I would argue that the strange behavior of the position is another
issue (if at all), since this one here is named "can not set AnchorType ...",
which is not true anymore.
Comment 12 Oliver Brinzing 2009-05-22 12:56:32 UTC
Hi Frank,

from my point of view it should be possible to set a control - anchored 
to the sheet - for example to an absolut X/Y position like 3cm/3cm 
at the moment it will added to the drawpage - first set all properties,
than add to drawpage ..

in writer there is a property "AnchorType":
TextContentAnchorType.AT_PAGE/AT_CELL which will do the job ...

in calc i have to add the control to the drawpage first, change the "Anchor" 
form cell to sheet (cause cell is default) and than have to set the new position 
cause 3/3cm changed undefinitly to 0,74/0,29 cm - so as you mentionend - 
before - the control will move ...... this is a bit unfortune 

i agree we could open a new issue ...

Comment 13 Oliver Brinzing 2009-05-22 13:01:28 UTC
so this is the workaound for the moment:

oPosition.X	= 3000
oPosition.Y = 3000
oControlShape.setPropertyValue("Anchor", oSheet)
Comment 14 Marcus 2017-05-20 10:47:56 UTC
Reset assigne to the default "".