Printing Cells With Empty Content

This guide will explain how to print empty spreadsheet using UniOffice.

Sample Input

test spreadsheet

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/cells-with-empty folder in the unioffice-examples directory.

cd unioffice-examples/spreadsheet/cells-with-empty/

How it works

The import section in lines 6-13 imports the necessary packages. Then in the init function a metered license API key is set.

The main function starts in line 24. In line 25, a test spreadsheet is loaded using spreadsheet.Open("test.xlsx"). Line 31 chooses the first cell using ss.Sheets()[0]. Then in lines 31-36, the cells of the table are printed using:

maxColumnIdx := s.MaxColumnIdx()
for _, row := range s.Rows() {
  for _, cell := range row.CellsWithEmpty(maxColumnIdx) {
    fmt.Println(cell.Reference(), ":", cell.GetFormattedValue())
  }
}

Then a new content is added to cell F4 and then the content is printed again in lines 39-45.

Run the code

Use the following command to run the code.

go run main.go

Sample Output

A1 : Col1
B1 : Col2
C1 : Col3
D1 : Col4
A2 : V1
B2 : V11
C2 : V111
D2 : 
A3 : V2
B3 : V22
C3 : 
D3 : 
A5 : V3
B5 : 
C5 : V33
D5 : 
A6 : 
B6 : 
C6 : 
D6 : xxx



A1 : Col1
B1 : Col2
C1 : Col3
D1 : Col4
E1 : 
F1 : 
A2 : V1
B2 : V11
C2 : V111
D2 : 
E2 : 
F2 : 
A3 : V2
B3 : V22
C3 : 
D3 : 
E3 : 
F3 : 
A4 : 
B4 : 
C4 : 
D4 : 
E4 : 
F4 : Hello world
A5 : V3
B5 : 
C5 : V33
D5 : 
E5 : 
F5 : 
A6 : 
B6 : 
C6 : 
D6 : xxx
E6 : 
F6 : 

Got any Questions?

We're here to help you.