First, you need to understand what is returned when you get the current
selection and then you need to check for it. For example:
Nothing selected or multiple text ranges: com.sun.star.text.TextRanges
ne or more cells selected in one block: com.sun.star.text.TextTableCursor
So, you must inspect what is returned and then make changes based on that
For example:
Sub WhatIsSelected
Dim oSel
Dim oneSel
Dim i As Long
oSel = ThisComponent.CurrentCOntroller.getSelection()
'Inspect oSel
If oSel.supportsService("com.sun.star.text.TextRanges") Then
For i = 0 To oSel.getCount() - 1
oneSel = oSel.getByIndex(i)
If oneSel.supportsService("com.sun.star.text.TextRange") Then
If NOT IsNull(oneSel.Cell) Then
' You have a cell here
' If actually select stuff, it will probably look like
' there is one more selection than you really have.
' One for each selected range and one for the current cursor
' location (I think).
ENd If
Else
Print "what is this thing"
'Inspect oneSel
End If
Next
ElseIf oSel.supportsService("com.sun.star.text.TextTableCursor") Then
'Inspect oSel
'Can you set what you want on the entire range at once?
' I think that you can, I do not think that you must enumerate the
cells.
End If
End Sub
Hope this helps
On 07/08/2015 06:44 PM, Hung Mark wrote:
Hi,
I didn't express very clearly. What I want to do is to set WritingMode
property for all the selected cells.
I did use MRI to explore APIs, but I was stuck in the middle.
To Mathias,
When selecting multiple cells, WritingMode of the first cell changed. The
remaining cells didn't
In contrast, ParaAdjust of all paragraphs in all the selected cells are
changed.
To Bernard,
It seems that I can't even call getByIndex() on my selection.
2015-07-09 1:12 GMT+08:00 Bernard Marcelly <marce...@club-internet.fr>:
Hi Mark,
You should use Xray to help you explore the API.
All my indications here can be found by a study of what Xray displays (and
then reading of API docs).
- You can find if your selection is inside a paragraph of a cell, and then
find the cell and its table:
Dim firstSelection As Object
Dim currentCell As Variant, currentTable As Variant
firstSelection = oCurrentSelection.getByIndex(0)
currentCell = firstSelection.Cell
if not IsEmpty(currentCell) then
currentCell.WritingMode = com.sun.star.text.WritingMode2.TB_RL
currentTable = oCurrentSelection.TextTable
else
MsgBox("First selection is not in a table")
end if
- A table has a property WritingMode. Perhaps it can set WritingMode to
all cells at once (not tested).
- Enumerate all cells of a table : the table has method getCellNames()
that returns an array of all the cell names.
Regards
Bernard
Hung Mark a écrit le 2015-07-08 13:52 :
Hi Mathias,
While invoking setPropertyValue for ParaAdjust works, it is a Paragraph
property instead of a cell property.
Sub ModifyCells
Dim oCurrentSelection As Variant
oCurrentSelection = ThisComponent.getCurrentSelection()
oCurrentSelection.setPropertyValue( "WritingMode",
com.sun.star.text.WritingMode2.TB_RL ) ' doesn't work
oCurrentSelection.setPropertyValue( "VertOrient",
com.sun.star.text.VertOrientation.BOTTOM ) ' doesn't work
oCurrentSelection.setPropertyValue( "ParaAdjust",
com.sun.star.style.ParagraphAdjust.RIGHT ) ' works
oCurrentSelection.setPropertyValue( "ParaBackColor",RGB(100,0,0) ) '
works
End Sub
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscr...@openoffice.apache.org
For additional commands, e-mail: api-h...@openoffice.apache.org
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info: http://www.pitonyak.org/oo.php