Creating a Lot of Rows

This guide will demonstrate how to create a workbook with large amount of rows using UniOffice. The speed of read and write operations will also be measured.

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/lots-of-rows folder in the unioffice-examples directory.

cd unioffice-examples/spreadsheet/lots-of-rows/

How it works

The import section in lines 4-14 imports the necessary libraries. The init function in lines 16-23 initializes the package by setting the metered license key using license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`)).

The main function is defined in lines 27-72. It starts by parsing the command-line flags from os.Args[1:] flag.Parse(). This to check for the cpuprofile flag provided in the command line arguments. Line 38 starts the time to time the process.

A new workbook with a spreadsheet is created in lines 39-43. The number of rows and columns are also defined in this section, i.e. 30000 rows and 100 columns. The nested for loops in line 46-53, create the rows and cells of spreadsheet. Then spreadsheet is validated in line 54.
Line 58 prints the amount of time it took to create the 30000 rows.

In line 59, the workbook is saved to a file. Then the amount of time it took to save the file is measured and printed in line 60. The time it takes to read is measured and printed in lines 65-70.

Run the code

Use the following command to run the code.

go run main.go

Sample Output

Preview of the created workbook.

sample spreadsheet with images

Bash output.

creating 30000 rows * 100 cells took 2.713507333s
saving took 42ns
reading took 4.842941208s

Got any Questions?

We're here to help you.