You are viewing a plain text version of this content. The canonical link for it is here.
Posted to api@openoffice.apache.org by Hung Mark <ma...@gmail.com> on 2015/07/08 07:37:38 UTC
Set property of selected cell range in a textable in Writer
I'm not sure if I it is possible to make cell enumeration based on the
CellRange
so that i can set property for each cell. Setting the property of a
CellRange seems not work.
Please advice, thank you.
Sub Snippet
Dim oCurrentSelection As Variant
Dim sRangeName As String
Dim oCurrentController As Variant
Dim oViewCursor As Variant
Dim oTextTable As Variant
Dim oCellRangeByName As Variant
oCurrentSelection = ThisComponent.getCurrentSelection()
sRangeName = oCurrentSelection.getRangeName()
oCurrentController = ThisComponent.getCurrentController()
oViewCursor = oCurrentController.getViewCursor()
oTextTable = oViewCursor.TextTable
oCellRangeByName = oTextTable.getCellRangeByName(sRangeName)
oCellRangeByName.setPropertyValue("WritingMode",2)
End Sub
--
Mark Hung
Re: Set property of selected cell range in a textable in Writer
Posted by Andrew Douglas Pitonyak <an...@pitonyak.org>.
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 <ma...@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-unsubscribe@openoffice.apache.org
>> For additional commands, e-mail: api-help@openoffice.apache.org
>>
>>
>
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info: http://www.pitonyak.org/oo.php
Re: Set property of selected cell range in a textable in Writer
Posted by Andrew Douglas Pitonyak <an...@pitonyak.org>.
Sadly, I am not aware of a simple obvious way to do this.
I suppose that if you know that the table is simple, you can take some
short-cuts. Here are some things that you do know...
You know the range name by calling oSel.RangeName
You can get the containing text table (because you cannot select cells
from different tables at the same time).
ThisComponent.CurrentController.ViewCursor.TextTable
Especially if this is a simple table, you can parse B3:C4 to get what
you need / want...
You can get the cell range itself (rather than the text table cursor)
oTextTable.getCellRangeByName(sRangeName)
You can then use the number of rows and columns to get what you want,
but, again, this only works for a simple text table.
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.
' The view cursor must be in a text table, so...
Dim sRangeName$
Dim oTextTable
Dim o
Dim oCell
Dim oEmpty
Dim iNumCols As Long
Dim iNumRows As Long
Dim iCol As Long
Dim iRow As Long
Dim s$
sRangeName = oSel.RangeName
oTextTable = ThisComponent.CurrentController.ViewCursor.TextTable
o = oTextTable.getCellRangeByName(sRangeName)
print sRangeName
'Inspect oTextTable.getCellRangeByName(sRangeName).ColumnDescriptions
iNumCols = UBound(o.getColumnDescriptions())
iNumRows = UBound(o.GetRowDescriptions())
For iCol = 0 To iNumCols
For iRow = 0 To iNumRows
oCell = o.getCellByPosition(iCol, iRow)
s = s & oCell.CellName & CHR$(10)
Next
Next
MsgBox s
End If
On 07/09/2015 08:18 PM, Hung Mark wrote:
> Hi Mathias,
>
> I use mouse to select cells, as below.
> http://i.imgur.com/2H6JFAb.png
>
> After running macro. Paragraph property works but the others doesn't.
> http://i.imgur.com/Tc7utrz.png
>
> If I add messages to show the values, I can see that the values changed,
> but it has no effect on formatting.
> I wonder what makes the difference.
> I've tested OpenOffice 4.1.1 and LibreOffice 4.4.4.3, both on Windows.
>
> Back to my original question, how do I enumerate all the cells if I have a
> cell range name like "B3:C4"?
>
> 2015-07-09 15:27 GMT+08:00 Mathias Röllig <mr...@gmx.net>:
>
>> Hi!
>>
>> 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.
>>>
>> How do you "select"? With mouse or with API?
>>
>> I use simply a text document with one table and select the cells with the
>> mouse cursor.
>> If I run my macro (with the missing line: oCurrentSelection =
>> ThisComponent.getCurrentSelection()) then I can see that the values
>> changed. And if I run it again for a piece of the previous selected cells I
>> see that the values was changed before for all the cells.
>>
>> Regards, Mathias
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
>> For additional commands, e-mail: api-help@openoffice.apache.org
>>
>>
>
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info: http://www.pitonyak.org/oo.php
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: Set property of selected cell range in a textable in Writer
Posted by Hung Mark <ma...@gmail.com>.
Hi Mathias,
I use mouse to select cells, as below.
http://i.imgur.com/2H6JFAb.png
After running macro. Paragraph property works but the others doesn't.
http://i.imgur.com/Tc7utrz.png
If I add messages to show the values, I can see that the values changed,
but it has no effect on formatting.
I wonder what makes the difference.
I've tested OpenOffice 4.1.1 and LibreOffice 4.4.4.3, both on Windows.
Back to my original question, how do I enumerate all the cells if I have a
cell range name like "B3:C4"?
2015-07-09 15:27 GMT+08:00 Mathias Röllig <mr...@gmx.net>:
> Hi!
>
> 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.
>>
>
> How do you "select"? With mouse or with API?
>
> I use simply a text document with one table and select the cells with the
> mouse cursor.
> If I run my macro (with the missing line: oCurrentSelection =
> ThisComponent.getCurrentSelection()) then I can see that the values
> changed. And if I run it again for a piece of the previous selected cells I
> see that the values was changed before for all the cells.
>
> Regards, Mathias
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
> For additional commands, e-mail: api-help@openoffice.apache.org
>
>
--
Mark Hung
Re: Set property of selected cell range in a textable in Writer
Posted by Mathias Röllig <mr...@gmx.net>.
Hi!
> 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.
How do you "select"? With mouse or with API?
I use simply a text document with one table and select the cells with
the mouse cursor.
If I run my macro (with the missing line: oCurrentSelection =
ThisComponent.getCurrentSelection()) then I can see that the values
changed. And if I run it again for a piece of the previous selected
cells I see that the values was changed before for all the cells.
Regards, Mathias
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: Set property of selected cell range in a textable in Writer
Posted by Hung Mark <ma...@gmail.com>.
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 <ma...@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-unsubscribe@openoffice.apache.org
> For additional commands, e-mail: api-help@openoffice.apache.org
>
>
--
Mark Hung
Re: Set property of selected cell range in a textable in Writer
Posted by Bernard Marcelly <ma...@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-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: Set property of selected cell range in a textable in Writer
Posted by Mathias Röllig <mr...@gmx.net>.
Hello Mark!
What is your Selection? If you select a complete cell or cellrange it
should work.
What means "it works not"? Is there a errror message? If not:
Sub CellModifyTest
Dim oCurrentSelection As Object
Dim i As Integer
i = oCurrentSelection.getPropertyValue( "WritingMode" )
oCurrentSelection.setPropertyValue( "WritingMode",
com.sun.star.text.WritingMode2.TB_RL )
MsgBox( "WritingMode was: " & i & " new: " &
oCurrentSelection.getPropertyValue( "WritingMode" )
i = oCurrentSelection.getPropertyValue( "ParaAdjust" )
oCurrentSelection.setPropertyValue( "ParaAdjust",
com.sun.star.style.ParagraphAdjust.RIGHT )
MsgBox( "ParaAdjust was: " & i & " new: " &
oCurrentSelection.getPropertyValue( "ParaAdjust" )
i = oCurrentSelection.getPropertyValue( "ParaVertAlignment" )
oCurrentSelection.setPropertyValue( "ParaVertAlignment",
com.sun.star.text.ParagraphVertAlign.BOTTOM )
MsgBox( "ParaVertAlignment was: " & i & " new: " &
oCurrentSelection.getPropertyValue( "ParaVertAlignment" )
End Sub
See
http://www.openoffice.org/api/docs/common/ref/com/sun/star/style/ParagraphPropertiesComplex.html#WritingMode
http://www.openoffice.org/api/docs/common/ref/com/sun/star/style/ParagraphProperties.html#ParaAdjust
http://www.openoffice.org/api/docs/common/ref/com/sun/star/style/ParagraphProperties.html#ParaVertAlignment
Regards, Mathias
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: Set property of selected cell range in a textable in Writer
Posted by Hung Mark <ma...@gmail.com>.
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
2015-07-08 18:02 GMT+08:00 Mathias Röllig <mr...@gmx.net>:
> Hello Mark!
>
> It works. Maybe you are missing something like
>
> oCurrentSelection.setPropertyValue( "ParaAdjust",
> com.sun.star.style.ParagraphAdjust.RIGHT )
>
> Regards, Mathias
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
> For additional commands, e-mail: api-help@openoffice.apache.org
>
>
--
Mark Hung
Re: Set property of selected cell range in a textable in Writer
Posted by Mathias Röllig <mr...@gmx.net>.
Hello Mark!
It works. Maybe you are missing something like
oCurrentSelection.setPropertyValue( "ParaAdjust",
com.sun.star.style.ParagraphAdjust.RIGHT )
Regards, Mathias
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: Set property of selected cell range in a textable in Writer
Posted by Hung Mark <ma...@gmail.com>.
Hi Mathias,
It doesn't work.
2015-07-08 16:04 GMT+08:00 Mathias Röllig <mr...@gmx.net>:
> Hello Hung!
>
> It should be enough:
>
> Sub Snippet
> Dim oCurrentSelection As Variant
>
> oCurrentSelection = ThisComponent.getCurrentSelection()
> oCurrentSelection.setPropertyValue( "WritingMode",
> com.sun.star.text.WritingMode2.TB_RL )
> End Sub
>
>
> Regards, Mathias
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
> For additional commands, e-mail: api-help@openoffice.apache.org
>
>
--
Mark Hung
Re: Set property of selected cell range in a textable in Writer
Posted by Mathias Röllig <mr...@gmx.net>.
Hello Hung!
It should be enough:
Sub Snippet
Dim oCurrentSelection As Variant
oCurrentSelection = ThisComponent.getCurrentSelection()
oCurrentSelection.setPropertyValue( "WritingMode",
com.sun.star.text.WritingMode2.TB_RL )
End Sub
Regards, Mathias
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org