How to wrap text in either a cell or merged cells using macro?

I got the example code from here, but this code:

Sub WrapTextInACell
	ThisComponent.CurrentController.ActiveSheet.getCellByPosition(7, 3).String = "TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest"
	ThisComponent.CurrentController.ActiveSheet.getCellRangeByPosition(7, 3).IsTextWrapped = False
	ThisComponent.CurrentController.ActiveSheet.getCellRangeByPosition(7, 3).IsTextWrapped = True
End Sub

gave this error message:
Screenshot from 2023-01-02 15-16-18

What is the problem?

0046WrapTextInACellOrMergedCell.ods (13.0 KB)

LibreOffice:
Version: 7.3.7.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 4; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Ubuntu package version: 1:7.3.7-0ubuntu0.22.04.1
Calc: threaded

OS:
Ubuntu 22.04 LTS Desktop

1 Like

Hi Lonk,

In your code… … Change 2nd line FROM ```
ThisComponent.CurrentController.ActiveSheet.getCellRangeByPosition(7, 3).IstextWrapped = False
and
3rd Line

ThisComponent.CurrentController.ActiveSheet.getCellRangeByPosition(7, 3).IstextWrapped = True

TO
2nd Line
ThisComponent.CurrentController.ActiveSheet.getCellByPosition(7, 3).IsTextWrapped = False
and
3rd Line
ThisComponent.CurrentController.ActiveSheet.getCellByPosition(7, 3).IsTextWrapped = True

Now, You will not get any error message. As it is Cell not Range
Because, In Your First Line Your mentioned Cell but next two lines your mentioned Range
In Range have 4 arguments ( Start Column, Start Row, End Column, End Row )

Here is the Code with Screen shots
Sub TextWrapped
Dim oDoc As Object, oSheet As Object, oCell As Object
oDoc = ThisComponent : oSheet = oDoc.Sheets(1)
oCell = oSheet.getCellByPosition(7,3)
oCell.String = “TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest”
oCell.IsTextWrapped = True
oCell.IsTextWrapped = False
End Sub

Screen Shots
oCell.String = "TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest"

oCell.IsTextWrapped = True

oCell.IsTextWrapped = False

Thats all

1 Like

Thank you so much.
Sorry for my typo.

1 Like

I also say to you THANKS… You mentioned the Link … that is very Useful to me to get more knowledge Macros in LibreOffice of All the Products like General , Calc, Writer, Impress, Base, Math, Drawing etc…
This is what i was searching so may months… Now, i got it… THANKS… lonk.

1 Like