Borders

This guide will demonstrate the process of creating spreadsheet borders 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/borders folder in the unioffice-examples directory.

cd unioffice-examples/spreadsheet/borders/

How it works

The example code starts by importing the necessary UniOffice packages and other Go libraries. The metered License API key is set inside the init function in lines 14-21.

Inside the main function, in line 24, a new spreadsheet.Workbook object is created using spreadsheet.New(). Then a new sheet is created and its string content and style are set in lines 26-32. An all sided border is created in lines 36-43 using:

// add some borders to the style (ordering isn't important, we could just as
// easily construct the cell style and then apply it to the cell)
bAll := ss.StyleSheet.AddBorder()
cs.SetBorder(bAll)
bAll.SetLeft(sml.ST_BorderStyleThin, color.Blue)
bAll.SetRight(sml.ST_BorderStyleThin, color.Blue)
bAll.SetTop(sml.ST_BorderStyleThin, color.Blue)
bAll.SetBottom(sml.ST_BorderStyleThin, color.Blue)
// red dashed line from top left down to bottom right
bAll.SetDiagonal(sml.ST_BorderStyleDashed, color.Red, false, true)

Then in line 50, The border is set using sheet.SetBorder("B6:D10", bAll). Finally, the document is written to file in line 56.

Run the code

Run the following command to create the file.

go run main.go

Sample output

Spreadsheet file.

sample output file

Got any Questions?

We're here to help you.