Remove Column
This guide will demonstrate the process of removing a specific column from a spreadsheet using UniOffice
.
Sample input
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/remove-column
folder in the unioffice-examples
directory.
cd unioffice-examples/spreadsheet/remove-column/
How it works
The import
section imports the necessary libraries.
The init
function in lines 14-21
initializes the package by setting the metered license key using license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))
. This authorizes the library request.
The main
function defined in lines 23-51
contains the code that is used to remove a column. First, the workbook is loaded from a file in line 24
. The target sheet is obtained by name from the workbook using ss.GetSheet("Cells")
. Here cells
is the name of the sheet we are interested in. Then in line 35
the column C
is removed from the sheet using sheet0.RemoveColumn("C")
. Lines 40-45
, removes column C
from sheet MergedCells
in the same manner. Finally, in line 50
, the new workbook is saved to file.
Run the code
Use the following command to run the code.
go run main.go