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 overwrite existing sheet? #12

Open
oleg-agapov opened this issue Jun 3, 2019 · 5 comments
Open

How to overwrite existing sheet? #12

oleg-agapov opened this issue Jun 3, 2019 · 5 comments

Comments

@oleg-agapov
Copy link

oleg-agapov commented Jun 3, 2019

Like title says, I want to be able to overwrite existing sheet with data.
I tried add SaveMode, but no effect:

df
  .write
  .mode(SaveMode.Overwrite)
  .format("com.github.potix2.spark.google.spreadsheets")
  .option("serviceAccountId", gserviceAccount)
  .option("credentialPath", pathToP12)
  .save(spreadsheetsId + "/newWorksheet")

I'm getting permission error:

Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Invalid requests[0].addSheet: A sheet with the name \"newWorksheet\" already exists. Please enter another name.",
    "reason" : "badRequest"
  } ],
  "message" : "Invalid requests[0].addSheet: A sheet with the name \"newWorksheet\" already exists. Please enter another name.",
  "status" : "INVALID_ARGUMENT"
}

How can I overcome this? I'm using version 0.4.0.

@larsskaug
Copy link

I would like to know as well. Thanks!

@antonmry
Copy link

As workaround,delete the sheet before, it works and it doesn't need additional libraries:

    val sc = SparkSpreadsheetService.SparkSpreadsheetContext(
      Option("[email protected]"),
      new File("/path/to/credential.p12"))

    val s = sc.findSpreadsheet("<spreadsheetID>")

    s.deleteWorksheet("worksheet1")

@ycw9 ycw9 mentioned this issue Jun 24, 2020
@krisBroekstra1
Copy link

As workaround,delete the sheet before, it works and it doesn't need additional libraries:

    val sc = SparkSpreadsheetService.SparkSpreadsheetContext(
      Option("[email protected]"),
      new File("/path/to/credential.p12"))

    val s = sc.findSpreadsheet("<spreadsheetID>")

    s.deleteWorksheet("worksheet1")

@antonmry is there also a way in scala with pyspark? i tried this methode, but doesn't work

@LucaXD-china
Copy link

My way is to add deleteWorksheet(sheetName) at the very beginning of addWorksheet.

@susmitsahad11
Copy link

As workaround,delete the sheet before, it works and it doesn't need additional libraries:

    val sc = SparkSpreadsheetService.SparkSpreadsheetContext(
      Option("[email protected]"),
      new File("/path/to/credential.p12"))

    val s = sc.findSpreadsheet("<spreadsheetID>")

    s.deleteWorksheet("worksheet1")

this is not working
could you pls send the import statements

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

6 participants