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

google sheet operations #8

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

suresh-kumara-gist
Copy link
Collaborator

@suresh-kumara-gist suresh-kumara-gist commented Dec 17, 2024

In order to Test modify cell data and insert rows/columns functionality.

  • we have to create service account in google cloud with editor role and download it has json store securely in project

  • we have to share respective google sheet with service account email as a editor

README to create service account

Now you can test this code:-

  1. Modify Cell Value:-

first you have to create list of values in a json file to add/modify in google sheet.

Examples:-

Create ./unversioned/list_of_values.json file with below values.

    [
        ["Hello, world!", "How are you?", "Good morning."],
        ["I love programming.", "Python is awesome!"],
        ["This is a test.", "Let's explore data structures."]
    ]

then insert these values at B8 Cell in Sheet! we have to run below command.

GOOGLE_SERVICE_ACCOUNT_FILE='/app/<your-service-account-file-path>'
GOOGLE_SHEETS_SPREADSHEET_ID='<your-google-sheet-id>'
RANGE="Sheet1\!B8"

google-sheets-to-csv % ./scripts/modify-cell-value.sh $GOOGLE_SERVICE_ACCOUNT_FILE $GOOGLE_SHEETS_SPREADSHEET_ID $RANGE  '/app/unversioned/list_of_values.json'

Now the values are replaced at B8 C8 D8, B9 C9, B10 C10 cells in Sheet1.

In list_of_values.json file:-

if You have provided [["row 1"]] then only B8 cell has modified.
if You have provided [["row 1"]["row 2"]] then A8,B9 cells has modified.
if You have provided [["row 1, "col 1"]] then B8,C* cells has modified.
if You have provided [["row 1, "col 1"],["row 2, "col 2"]] then B8 C8,B9 C9 cell has modified.

  1. Insert Rows and Columns in a google sheet:-

  GOOGLE_SERVICE_ACCOUNT_FILE='/app/<your-service-account-file-path>'
  GOOGLE_SHEETS_SPREADSHEET_ID='<your-google-sheet-id>'
  1. Insert 2 rows after row 5 in Sheet1.
google-sheets-to-csv % ./scripts/insert-rows-columns.sh $GOOGLE_SERVICE_ACCOUNT_FILE $GOOGLE_SHEETS_SPREADSHEET_ID 0 row 5 2 --after

0 -> represents Sheet1 , 1 for Sheet2 .....

  1. Insert 5 rows before row 10 in Sheet1.
google-sheets-to-csv % ./scripts/insert-rows-columns.sh $GOOGLE_SERVICE_ACCOUNT_FILE $GOOGLE_SHEETS_SPREADSHEET_ID 0 row 10 5 --before
  1. Insert 2 columns after column 5 in Sheet1.
google-sheets-to-csv % ./scripts/insert-rows-columns.sh $GOOGLE_SERVICE_ACCOUNT_FILE $GOOGLE_SHEETS_SPREADSHEET_ID 0 column 5 2 --after
  1. Insert 12 columns before column 5 in Sheet1.
google-sheets-to-csv % ./scripts/insert-rows-columns.sh $GOOGLE_SERVICE_ACCOUNT_FILE $GOOGLE_SHEETS_SPREADSHEET_ID 0 column 5 12 --before

@suresh-kumara-gist suresh-kumara-gist changed the title modify google sheet data google sheet operations Dec 17, 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

Successfully merging this pull request may close these issues.

1 participant