Validate Workbook

This guide will demonstrate the process of validating workbooks 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

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

cd unioffice-examples/spreadsheet/validation/

How it works

The import section in lines 10-14 imports the necessary libraries. Then the init function initializes the package by setting the metered license key.

The main function is defined in lines 21-60. In this function a new workbook with a sheet is created in lines 22-24. Lines 27-32 creates a dropdown validation list that references another sheet using the following snippet.

vsheet := ss.AddSheet()
vsheet.SetName("Validation Data")

sheet.Cell("B1").SetString("references sheet")
dvCombo := sheet.AddDataValidation()
dvList := dvCombo.SetList()

The dropdown list of valid results are can be seen in the following sample result.

Alt text

Lines 42-53 create validation options which are directly specified in the code using:

sheet.Cell("C1").SetString("value list")
dvComboDirect := sheet.AddDataValidation()
dvListDirect := dvComboDirect.SetList()
dvListDirect.SetValues([]string{"foo", "bar", "baz"})
sheet.Cell("C1").SetString("positive whole numbers")
dvWhole := sheet.AddDataValidation()
dvWholeCmp := dvWhole.SetComparison(spreadsheet.DVCompareTypeWholeNumber, spreadsheet.DVCompareOpGreaterEqual)

The list of valid lists which are foo, bar and baz are shown in the spreadsheet when trying to input value in the respective column as follows.

Alt text

Finally, in lines 55-59, the workbook is validated and save to file.

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.