Text Extraction

This guide will explain how to extract text from 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/text_extraction folder in the unioffice-examples directory.

cd unioffice-examples/spreadsheet/text_extraction/

How it works

In lines `10-16`, the necessary libraries are imported. Then the metered license key is set inside the `init` function using ``license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))``.

In line 28 a new workbook is loaded from file using spreadsheet.Open("extract_styles.xlsx"). A flattened version of the text content is printed in lines 34-37 using:

extracted := wb.ExtractText()
flattened := extracted.Text()
fmt.Println(flattened)

Run the code

Use the following command to run the code.

go run main.go

Sample Output

Cell 00
Cell 01
Cell 02
Cell 03
Cell 10
Cell 11
Cell 12
Cell 13
Cell 20
Cell 21
Cell 22
Cell 23
Cell 30
Cell 31
Cell 32
Cell 33


Row: 0, Column: 0
Text: Cell 00
Font color theme: 0
Font color tint: -0.1499984740745262
Cell color theme: 9
Cell color tint: 0.7999816888943144

Row: 0, Column: 1
Text: Cell 01
Bold
Font color theme: 0
Font color tint: -0.249977111117893
Cell color theme: 9
Cell color tint: 0.7999816888943144

Row: 0, Column: 2
Text: Cell 02
Italic
Font color theme: 0
Font color tint: -0.3499862666707358
Cell color theme: 9
Cell color tint: 0.7999816888943144

Row: 0, Column: 3
Text: Cell 03
Bold
Italic
Font color theme: 0
Font color tint: -0.499984740745262
Cell color theme: 9
Cell color tint: 0.7999816888943144

Row: 1, Column: 0
Text: Cell 10
Font color theme: 0
Font color tint: -0.1499984740745262
Cell color theme: 9
Cell color tint: 0.5999938962981048

Row: 1, Column: 1
Text: Cell 11
Bold
Font color theme: 0
Font color tint: -0.249977111117893
Cell color theme: 9
Cell color tint: 0.5999938962981048

Row: 1, Column: 2
Text: Cell 12
Italic
Font color theme: 0
Font color tint: -0.3499862666707358
Cell color theme: 9
Cell color tint: 0.5999938962981048

Row: 1, Column: 3
Text: Cell 13
Bold
Italic
Font color theme: 0
Font color tint: -0.499984740745262
Cell color theme: 9
Cell color tint: 0.5999938962981048

Row: 2, Column: 0
Text: Cell 20
Font color theme: 0
Font color tint: -0.1499984740745262
Cell color theme: 9
Cell color tint: 0.3999755851924192

Row: 2, Column: 1
Text: Cell 21
Bold
Font color theme: 0
Font color tint: -0.249977111117893
Cell color theme: 9
Cell color tint: 0.3999755851924192

Row: 2, Column: 2
Text: Cell 22
Italic
Font color theme: 0
Font color tint: -0.3499862666707358
Cell color theme: 9
Cell color tint: 0.3999755851924192

Row: 2, Column: 3
Text: Cell 23
Bold
Italic
Font color theme: 0
Font color tint: -0.499984740745262
Cell color theme: 9
Cell color tint: 0.3999755851924192

Row: 3, Column: 0
Text: Cell 30
Font color theme: 0
Font color tint: -0.1499984740745262
Cell color theme: 9
Cell color tint: -0.249977111117893

Row: 3, Column: 1
Text: Cell 31
Bold
Font color theme: 0
Font color tint: -0.249977111117893
Cell color theme: 9
Cell color tint: -0.249977111117893

Row: 3, Column: 2
Text: Cell 32
Italic
Font color theme: 0
Font color tint: -0.3499862666707358
Cell color theme: 9
Cell color tint: -0.249977111117893

Row: 3, Column: 3
Text: Cell 33
Bold
Italic
Font color theme: 0
Font color tint: -0.499984740745262
Cell color theme: 9
Cell color tint: -0.249977111117893

Got any Questions?

We're here to help you.