spark-google-spreadsheets
spark-google-spreadsheets copied to clipboard
How to overwrite existing sheet?
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
.
I would like to know as well. Thanks!
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")
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
My way is to add deleteWorksheet(sheetName) at the very beginning of addWorksheet.
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