GoSheets is a simple Go package wrapper that provides basic functionalities to interact with Google Sheets spreadsheets programmatically. It allows you to read data from, add data to, and delete rows from a Google Sheets spreadsheet.
-
Initialize Google Sheets Service:
credentials, err := os.ReadFile("path/to/credentials.json") gs, err := gosheets.NewGoogleSheetsClient(credentials)
-
Set the Spreadsheet ID and sheet name:
gs.SetSpreadsheetID("spreadsheetID") gs.SetSheetName("Sheet1")
-
Read Data from current sheet set:
data, err := gs.ReadData("A:F")
-
Append Data to current sheet set:
values := [][]interface{}{ {"Value1", "Value2"}, {"Value3", "Value4"}, } err := gs.AppendData(values, "A1")
-
Insert data after a specific row in the current sheet set:
values := []interface{}{"Value1", "Value2"} err := gs.InsertRowsAfterPosition(values, "3")
-
Insert data at the beginning of the current sheet set:
values := []interface{}{"Value1", "Value2"} err := gs.InsertRowsAtBeginning(values)
-
Delete Row from current sheet set:
err := gs.DeleteRow(data, "A", value)
-
Print Data as string:
data, err := gs.ReadData("A:F") fmt.Println(gs.DataToString(data))
go get github.com/zavaladiego/gosheets@latest
To use this package, ensure you have the following:
- Google Sheets API enabled in your Google Cloud Console. You can enable it by visiting the Google Cloud Console, creating a new project and enabling the Google Sheets API.
- Service account key file (JSON) obtained from the Google Cloud Console. This key file is used for authentication when accessing Google Sheets.
- The google service account must have access to the spreadsheet you want to work with. Ensure that this Google account has been granted the necessary permissions (e.g., edit, read) for the spreadsheet.
ok | github.com/zavaladiego/gosheets |
---|---|
execution time | 5.408s |
coverage | 95.5% of statements |
Contributions are welcome! Feel free to open issues or pull requests.