Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get a cell coordinate,there is GetRows GetColumns but no coordinate #1854

Closed
answer91 opened this issue Mar 20, 2024 · 1 comment
Closed

Comments

@answer91
Copy link

Description

Steps to reproduce the issue:
1.
2.
3.

Describe the results you received:

Describe the results you expected:

Output of go version:

(paste your output here)

Excelize version or commit ID:

(paste here)

Environment details (OS, Microsoft Excel™ version, physical, etc.):

@xuri
Copy link
Member

xuri commented Mar 20, 2024

Thanks for your issue. As the documentation says, the Excelize library provides a set of utility functions that allow you to convert between cell names and coordinates, you can also use these functions when iterating rows or column cells. For example, convert column/row index to cell name when iterating rows:

package main

import (
    "fmt"

    "github.com/xuri/excelize/v2"
)

func main() {
    f := excelize.NewFile()
    defer func() {
        if err := f.Close(); err != nil {
            fmt.Println(err)
        }
    }()
    if err := f.SetSheetRow("Sheet1", "A1", &[]interface{}{1, 2}); err != nil {
        fmt.Println(err)
        return
    }
    if err := f.SetSheetRow("Sheet1", "A2", &[]interface{}{3, 4}); err != nil {
        fmt.Println(err)
        return
    }
    rows, err := f.GetRows("Sheet1")
    if err != nil {
        fmt.Println(err)
        return
    }
    for rowIdx, row := range rows {
        for colIdx, cell := range row {
            // Convert column/row index to cell name
            cellName, err := excelize.CoordinatesToCellName(colIdx+1, rowIdx+1)
            if err != nil {
                fmt.Println(err)
                return
            }
            fmt.Printf("value of cell %s is %s\r\n", cellName, cell)
        }
    }
}

I've closed this issue. If you have any questions, please let me know, and you can reopen this anytime.

@xuri xuri closed this as completed Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants