Esempi
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa sezione presenta un
codelab che puoi
utilizzare per acquisire familiarità con l'API Google Sheets. Viene inoltre fornito un insieme di esempi di "ricette" che mostrano come tradurre un'azione Google Sheets prevista in una richiesta API.
Spesso esiste più di un modo per completare una determinata attività con l'API. Quando
decidi come affrontare un'attività, tieni presente quanto segue:
- Se devi leggere o scrivere valori delle celle, la raccolta
spreadsheets.values
è una scelta migliore rispetto alla raccolta spreadsheets
. L'interfaccia del primo è più facile da usare per semplici operazioni di lettura/scrittura.
Ove possibile, utilizza i metodi batch
(spreadsheet.batchUpdate
,
spreadsheet.values.batchGet
,
e
spreadsheet.values.batchUpdate
)
per raggruppare più richieste in una singola chiamata al metodo. L'utilizzo di questi metodi batch
migliora l'efficienza perché:
- Ridurre l'overhead HTTP del client.
- Riduci il numero di query eseguite.
- Riduci il numero di revisioni del documento.
- Garantisci l'atomicità di tutte le modifiche nel batch.
Ricette
Gli esempi elencati in questa sezione mostrano come esprimere azioni comuni in
Fogli come richieste dell'API Sheets v4.
Questi esempi sono presentati sotto forma di richieste HTTP per essere indipendenti dalla lingua. Per scoprire come implementare i protocolli di richiesta dell'API Sheets in un
linguaggio specifico utilizzando le librerie client delle API di Google, consulta le guide Lettura e scrittura dei valori
delle celle e Aggiornamento
dei fogli di lavoro.
Le ricette in questa sezione sono suddivise nelle seguenti categorie:
- Lettura di base: ricette che
mostrano come leggere i valori di un foglio.
- Scrittura di base: ricette che
mostrano come scrivere valori in un foglio.
- Formattazione di base: ricette
che mostrano come modificare l'aspetto di fogli e celle.
- Grafici: ricette che mostrano come
creare e modificare i grafici in un foglio.
- Formattazione condizionale: ricette che mostrano come modificare l'aspetto delle celle in base alle condizioni.
- Operazioni sui dati: ricette che
mostrano come creare, spostare e manipolare i dati in un foglio di lavoro.
- Intervalli denominati e protetti: ricette che mostrano come creare, aggiornare e rimuovere intervalli denominati e protetti in un foglio di lavoro.
- Tabelle pivot: ricette
che mostrano come creare tabelle pivot in un foglio.
- Operazioni su righe e colonne: ricette che mostrano come aggiungere, rimuovere e spostare righe e colonne e aggiornarne le proprietà.
- Operazioni sui fogli: ricette che
mostrano come creare, cancellare, copiare ed eliminare fogli e come controllarne
le proprietà.
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-08-29 UTC.
[null,null,["Ultimo aggiornamento 2025-08-29 UTC."],[],[],null,["# Samples\n\nThis section presents a\n[codelab](https://codelabs.developers.google.com/codelabs/sheets-api/) you can\nuse to become familiar with the Google Sheets API. Also provided are a set of\n\"recipe\" examples that demonstrate how to translate an intended Google Sheets\naction into an API request.\n\nOften there's more than one way to complete a given task with the API. When\nyou're deciding on how to approach a task, keep the following in mind:\n\n- If you need to read or write cell values, the [`spreadsheets.values`](/workspace/sheets/api/reference/rest/v4/spreadsheets.values) collection is a better choice than the [`spreadsheets`](/workspace/sheets/api/reference/rest/v4/spreadsheets) collection. The former's interface is easier to use for simple read/write operations.\n- Wherever possible, use the batch methods\n ([`spreadsheet.batchUpdate`](/workspace/sheets/api/reference/rest/v4/spreadsheets/batchUpdate),\n [`spreadsheet.values.batchGet`](/workspace/sheets/api/reference/rest/v4/spreadsheets.values/batchGet),\n and\n [`spreadsheet.values.batchUpdate`](/workspace/sheets/api/reference/rest/v4/spreadsheets.values/batchUpdate))\n to bundle multiple requests into a single method call. Using these batch\n methods improves efficiency as they:\n\n - Reduce client HTTP overhead.\n - Reduce the number of queries made.\n - Reduce the number of revisions on the doc.\n - Ensure atomicity of all the changes in the batch.\n\nRecipes\n-------\n\nThe examples listed in this section demonstrate how to express common actions in\nSheets as Sheets API v4 requests.\n\nThese examples are presented in the form of HTTP requests to be language\nneutral. To learn how to implement Sheets API request protocols in a\nspecific language using Google API client libraries, see the [Read \\& write cell\nvalues](/workspace/sheets/api/guides/values) and [Update\nspreadsheets](/workspace/sheets/api/guides/batchupdate) guides.\n\nRecipes in this section are divided into the following categories:\n\n- [Basic reading](/workspace/sheets/api/samples/reading)---Recipes that show how to read values from a sheet.\n- [Basic writing](/workspace/sheets/api/samples/writing)---Recipes that show how to write values to a sheet.\n- [Basic formatting](/workspace/sheets/api/samples/formatting)---Recipes that show how to change the appearance of sheets and cells.\n- [Charts](/workspace/sheets/api/samples/charts)---Recipes that show how to create and alter charts in a sheet.\n- [Conditional formatting](/workspace/sheets/api/samples/conditional-formatting)--- Recipes that show how to alter cell appearance based on conditions.\n- [Data operations](/workspace/sheets/api/samples/data)---Recipes that show how to create, move, and manipulate data in a spreadsheet.\n- [Named \\& protected\n ranges](/workspace/sheets/api/samples/ranges)---Recipes that show how to create, update, and remove named and protected ranges in a spreadsheet.\n- [Pivot tables](/workspace/sheets/api/samples/pivot-tables)---Recipes that show how to create pivot tables in a sheet.\n- [Row \\& column\n operations](/workspace/sheets/api/samples/rowcolumn)---Recipes that show how to add, remove, and move rows and columns, and update their properties.\n- [Sheet operations](/workspace/sheets/api/samples/sheet)---Recipes that show how to create, clear, copy, and delete sheets, and also control their properties."]]