xxxxxxxxxx
import openpyxl
# Load the Excel workbook
workbook = openpyxl.load_workbook('example.xlsx')
# Select the desired worksheet
worksheet = workbook['Sheet1']
# Select the cell where you want to wrap the text
cell = worksheet['A1']
# Enable text wrapping for the cell
cell.alignment = openpyxl.styles.Alignment(wrap_text=True)
# Save the modified workbook
workbook.save('example.xlsx')
xxxxxxxxxx
' On the Home tab, in the Alignment group, click Wrap Text (Alt + H + W)
' In VBA:
Worksheets("Sheet1").Range("B2").Value = "This text should wrap in a cell."
Worksheets("Sheet1").Range("B2").WrapText = True