-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell.go
45 lines (39 loc) · 1.12 KB
/
cell.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package models
import (
"fmt"
// Third-party libraries
"github.com/Deathfireofdoom/excel-client-go/pkg/utils"
)
// Cell represents a single cell in a spreadsheet
type Cell struct {
ID string `json:"id"`
WorkbookID string `json:"workbook_id"`
SheetID string `json:"sheet_id"`
Row int `json:"row"`
Column string `json:"column"`
Value interface{} `json:"value"`
}
// NewCell creates a new Cell instance.
// If id is empty, a new UUID will be generated.
func NewCell(workbook_id string, sheet_id string, row int, column string, value interface{}, id string) (*Cell, error) {
if id == "" {
var err error
id, err = utils.GenerateUUID()
if err != nil {
return nil, fmt.Errorf("failed to generate UUID for Cell: %w", err)
}
}
return &Cell{
ID: id,
WorkbookID: workbook_id,
SheetID: sheet_id,
Row: row,
Column: column,
Value: value,
}, nil
}
// GetPosition returns the position of the cell as a string,
// concatenating the column and row information.
func (c *Cell) GetPosition() string {
return c.Column + fmt.Sprint(c.Row)
}