Copies a spreadsheet. :param str file_id: A key of a spreadsheet to copy. :param str title: (optional) A title for the new spreadsheet. :param bool copy_permissions: (optional) If True, copy permissions from the original spreadsheet to the new spreadsheet.
(
self,
file_id: str,
title: Optional[str] = None,
copy_permissions: bool = False,
folder_id: Optional[str] = None,
copy_comments: bool = True,
)
| 264 | return self.http_client.export(file_id=file_id, format=format) |
| 265 | |
| 266 | def copy( |
| 267 | self, |
| 268 | file_id: str, |
| 269 | title: Optional[str] = None, |
| 270 | copy_permissions: bool = False, |
| 271 | folder_id: Optional[str] = None, |
| 272 | copy_comments: bool = True, |
| 273 | ) -> Spreadsheet: |
| 274 | """Copies a spreadsheet. |
| 275 | |
| 276 | :param str file_id: A key of a spreadsheet to copy. |
| 277 | :param str title: (optional) A title for the new spreadsheet. |
| 278 | |
| 279 | :param bool copy_permissions: (optional) If True, copy permissions from |
| 280 | the original spreadsheet to the new spreadsheet. |
| 281 | |
| 282 | :param str folder_id: Id of the folder where we want to save |
| 283 | the spreadsheet. |
| 284 | |
| 285 | :param bool copy_comments: (optional) If True, copy the comments from |
| 286 | the original spreadsheet to the new spreadsheet. |
| 287 | |
| 288 | :returns: a :class:`~gspread.models.Spreadsheet` instance. |
| 289 | |
| 290 | .. versionadded:: 3.1.0 |
| 291 | |
| 292 | .. note:: |
| 293 | |
| 294 | If you're using custom credentials without the Drive scope, you need to add |
| 295 | ``https://www.googleapis.com/auth/drive`` to your OAuth scope in order to use |
| 296 | this method. |
| 297 | |
| 298 | Example:: |
| 299 | |
| 300 | scope = [ |
| 301 | 'https://www.googleapis.com/auth/spreadsheets', |
| 302 | 'https://www.googleapis.com/auth/drive' |
| 303 | ] |
| 304 | |
| 305 | Otherwise, you will get an ``Insufficient Permission`` error |
| 306 | when you try to copy a spreadsheet. |
| 307 | |
| 308 | """ |
| 309 | url = "{}/{}/copy".format(DRIVE_FILES_API_V3_URL, file_id) |
| 310 | |
| 311 | payload: Dict[str, Any] = { |
| 312 | "name": title, |
| 313 | "mimeType": MimeType.google_sheets, |
| 314 | } |
| 315 | |
| 316 | if folder_id is not None: |
| 317 | payload["parents"] = [folder_id] |
| 318 | |
| 319 | params: ParamsType = {"supportsAllDrives": True} |
| 320 | r = self.http_client.request("post", url, json=payload, params=params) |
| 321 | spreadsheet_id = r.json()["id"] |
| 322 | |
| 323 | new_spreadsheet = self.open_by_key(spreadsheet_id) |