cellwalker

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2024 License: MIT Imports: 5 Imported by: 0

README

Cell Walker

Cell Walker is a go package for virtually traversing Excel cell by cell's name. The package does not actually traverse into a real Excel file.

Example

package main

import (
	"fmt"

	"github.com/chonla/cellwalker"
)

func main() {
	// Walk from a cell to other cell
	fmt.Println(cellwalker.At("B3").Right().Below().String()) // C4

	// Jump from a cell to other cell
	fmt.Println(cellwalker.At("C2").ColumnOffset(5).RowOffset(10).String()) // H12

	// Too far jump from a cell to other cell will hit the limit of boundary
	fmt.Println(cellwalker.At("ZZZ2").ColumnOffset(5).RowOffset(10).String()) // XFD12

	// Range walking apply other boundary to walker
	fmt.Println(cellwalker.Within("C2:H3").At("C3").Right().Below().String()) // D3

	// Too far jump in a new boundary
	fmt.Println(cellwalker.Within("C2:H3").At("ZZZ2").ColumnOffset(5).RowOffset(10).String()) // XFD12

	// Range traversal
	result1 := cellwalker.Within("B3:E5").At("C4") // Define range and initial cell position
	fmt.Println(result1.String()) // C4
	result2 := result1.Tour()
	fmt.Println(result2.String()) // D4
	result3 := result2.Tour()
	fmt.Println(result3.String()) // E4
	result4 := result3.Tour()
	fmt.Println(result4.String()) // B5
	result5 := result4.Tour()
	fmt.Println(result5.String()) // C5
	result6 := result5.Tour()
	fmt.Println(result6.String()) // D5
	result7 := result6.Tour()
	fmt.Println(result7.String()) // E5
	result8 := result7.Tour()
	fmt.Println(result8 == nil) // true
}

License

MIT

Documentation

Index

Constants

View Source
const (
	RowsLimit    = 1048576
	ColumnsLimit = 16384
)

RowsLimit https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3

Variables

This section is empty.

Functions

func ColumnIndexToName

func ColumnIndexToName(id int) string

ColumnIndexToName converts column index to default excel name

func ColumnNameToIndex

func ColumnNameToIndex(name string) int

ColumnNameToIndex converts default excel column name to index, 1-based index name must be uppercase start from A, B, C, ..., Z, AA, AB, ... ZZ, AAA, ..., ZZZ, ...

Types

type Cell

type Cell struct {
	// contains filtered or unexported fields
}

Cell represents a cell in Excel

func (*Cell) Clone

func (c *Cell) Clone() *Cell

Clone creates a copy of Cell

func (*Cell) ColumnIndex

func (c *Cell) ColumnIndex() int

ColumnIndex returns column number

func (*Cell) RowIndex

func (c *Cell) RowIndex() int

RowIndex returns row number

func (*Cell) String

func (c *Cell) String() string

String representation of Cell

type CellWalker

type CellWalker struct {
	// contains filtered or unexported fields
}

CellWalker struct

func At

func At(cellID string) *CellWalker

At initializes CellWalker by specify initial cell to start

func (*CellWalker) Above

func (c *CellWalker) Above() *CellWalker

Above to move up one row

func (*CellWalker) Below

func (c *CellWalker) Below() *CellWalker

Below to move down one row

func (*CellWalker) BottomMost added in v1.2.0

func (c *CellWalker) BottomMost() *CellWalker

Bottommost to move bottommost column

func (*CellWalker) CanMoveDown

func (c *CellWalker) CanMoveDown() bool

CanMoveDown determines if it is at the bottom most cell

func (*CellWalker) CanMoveLeft

func (c *CellWalker) CanMoveLeft() bool

CanMoveLeft determines if it is at the left most cell

func (*CellWalker) CanMoveRight

func (c *CellWalker) CanMoveRight() bool

CanMoveRight determines if it is at the right most cell

func (*CellWalker) CanMoveUp

func (c *CellWalker) CanMoveUp() bool

CanMoveUp determines if it is at the up most cell

func (*CellWalker) Clone

func (c *CellWalker) Clone() *CellWalker

Clone creates a clone of cellwalker

func (*CellWalker) Column

func (c *CellWalker) Column(colName string) *CellWalker

Column jumps to a given colName

func (*CellWalker) ColumnIndex added in v1.1.2

func (c *CellWalker) ColumnIndex() int

ColumnIndex returns the current column number

func (*CellWalker) ColumnName added in v1.1.2

func (c *CellWalker) ColumnName() string

ColumnName returns the current column name

func (*CellWalker) ColumnOffset

func (c *CellWalker) ColumnOffset(offset int) *CellWalker

ColumnOffset returns a cell with a given offset distance to column

func (*CellWalker) IsAtBottomBoundary added in v1.1.1

func (c *CellWalker) IsAtBottomBoundary() bool

IsAtBottomBoundary determine if current position is at the bottom of range

func (*CellWalker) IsAtLeftBoundary added in v1.1.1

func (c *CellWalker) IsAtLeftBoundary() bool

IsAtLeftBoundary determine if current position is at the left of range

func (*CellWalker) IsAtRightBoundary added in v1.1.1

func (c *CellWalker) IsAtRightBoundary() bool

IsAtRightBoundary determine if current position is at the right of range

func (*CellWalker) IsAtTopBoundary added in v1.1.1

func (c *CellWalker) IsAtTopBoundary() bool

IsAtTopBoundary determine if current position is at the top of range

func (*CellWalker) Left

func (c *CellWalker) Left() *CellWalker

Left to move left one column

func (*CellWalker) LeftMost

func (c *CellWalker) LeftMost() *CellWalker

LeftMost to move leftmost column

func (*CellWalker) Right

func (c *CellWalker) Right() *CellWalker

Right to move right one column

func (*CellWalker) RightMost added in v1.2.0

func (c *CellWalker) RightMost() *CellWalker

Rightmost to move rightmost column

func (*CellWalker) Row

func (c *CellWalker) Row(row int) *CellWalker

Row jumps to a given row

func (*CellWalker) RowIndex added in v1.1.2

func (c *CellWalker) RowIndex() int

RowIndex returns the current row number

func (*CellWalker) RowOffset

func (c *CellWalker) RowOffset(offset int) *CellWalker

RowOffset returns a cell with a given offset distance to row

func (*CellWalker) String

func (c *CellWalker) String() string

func (*CellWalker) TopMost

func (c *CellWalker) TopMost() *CellWalker

TopMost to move topmost column

func (*CellWalker) Tour

func (c *CellWalker) Tour() *CellWalker

Tour traverses position to Right column first then first column of next row if hit the boundary edge. Return nil if cannot make a further move

type Range

type Range struct {
	// contains filtered or unexported fields
}

Range is a boundary that cellwalker can move

func Sheet

func Sheet() *Range

Sheet returns sheet boundary

func Within

func Within(rangeID string) *Range

Within creates a new range

func (*Range) At

func (r *Range) At(cellID string) *CellWalker

At returns cell walker with range constraint

func (*Range) BottomIndex

func (r *Range) BottomIndex() int

BottomIndex returns row index of bottom boundary

func (*Range) Clone

func (r *Range) Clone() *Range

Clone creates a copy of Range

func (*Range) LeftIndex

func (r *Range) LeftIndex() int

LeftIndex returns column index of left boundary

func (*Range) RightIndex

func (r *Range) RightIndex() int

RightIndex returns column index of right boundary

func (*Range) String

func (r *Range) String() string

func (*Range) TopIndex

func (r *Range) TopIndex() int

TopIndex returns row index of top boundary