Wrap Cell Text

This guide will demonstrate how to wrap cell text in a spreadsheet using UniOffice.

Before you begin

You should get your API key from your UniCloud account.

If this is your first time using UniOffice SDK, follow this guide to set up a local development environment.

Clone the project repository

In your terminal, clone the examples repository. It contains the Go code we will be using for this guide.

git clone https://github.com/unidoc/unioffice-examples

To get the example navigate to the path spreadsheet/wrapped-text folder in the unioffice-examples directory.

cd unioffice-examples/spreadsheet/wrapped-text/

How it works

The `import` section in lines `4-10` imports the necessary libraries. The `init` function defined in lines `12-19` sets the license key to authenticate the library usage.

In line 21, A long text is defined. This will be used in on of the cells. Then in lines 23-42, the main function is defined. In the beginning section of this function a new work book with a single empty sheet is created. Then in lines 29-30, a new row and single cell is added to the sheet as follows.

row := sheet.AddRow()
cell := row.AddCell()

In line 31 a new CellStyle is created from the sheet using ss.StyleSheet.AddCellStyle(). The wrapped property of the cell is set using the CellStyle by calling the SetWrapped method with a value true. After this the content and the style of the cell are set in lines 34-35 using:


Finally, the workbook is validated in line 137 and saved to file in line 41.

Run the code

Use the following command to run the code.

go run main.go

Sample Output


Got any Questions?

We're here to help you.