I
I
It_poirot2021-09-23 19:13:11
Visual Basic
It_poirot, 2021-09-23 19:13:11

How to cancel text wrapping in a cell in code, and how to set the width of a certain column?

The code:

Sub jurnal
    Dim oDoc As Object
    Dim oSheet As Object
    Dim Cell As Object
    
       oDoc = ThisComponent
       oSheet = oDoc.getCurrentController().ActiveSheet
    
       oSheet.Rows.insertByIndex(0,1)
       
       oSheet.Columns.insertByIndex(3, 1)
       
       Cell = oSheet.getCellRangeByName("A1")
       Cell.String = "Журнал телефонной базы предприятия"
       Cell.CharWeight = com.sun.star.awt.FontWeight.BOLD
       Cell.CharHeight = 14
           Range("A1").WrapText= False
       
       Cell = oSheet.getCellRangeByName("D2")
       Cell.String = "Номер телефона"
End Sub

The code on the Range("A1").WrapText= False command throws an error. Maybe you can cancel the text wrapping by another method?

And the column of cell D2 is greatly stretched. We need to reduce the width. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ti_zh_vrach, 2021-09-25
@ti_zh_vrach

There seems to be a problem with the sheet. Try writing like this: "Sheet1" is not the one under the table, but which is visible only in the code editor:
Лист1.Range("A1").WrapText = False

picture
614eca4e1a7a9850237200.png

It can be changed. Better yet, try doing this:
Лист1.Cells(1,  1).WrapText = False 'в данном случае Cells(1,  1) = Range("A1")

You can change the width like this:
Лист1.Columns(4).ColumnWidth = 8 '4 - номер колонки D.

8 is the width displayed here:
picture
614ecff583fb1679855225.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question