spark-google-spreadsheets icon indicating copy to clipboard operation
spark-google-spreadsheets copied to clipboard

How to overwrite existing sheet?

Open oleg-agapov opened this issue 5 years ago • 5 comments

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.

oleg-agapov avatar Jun 03 '19 13:06 oleg-agapov

I would like to know as well. Thanks!

larsskaug avatar Dec 12 '19 22:12 larsskaug

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 avatar Mar 30 '20 15:03 antonmry

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

krisBroekstra1 avatar May 15 '21 12:05 krisBroekstra1

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

LucaXD-china avatar Sep 23 '22 03:09 LucaXD-china

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

susmitsahad11 avatar Mar 30 '23 19:03 susmitsahad11