The following examples show the simplest requests possible depending on the action you want to perform.
The following is quite a simple example of adding a sheet, according to the object structure.
$this->performRequest(
method: "POST",
endpoint: '1234567890:batchUpdate',
body: json_encode(
[
"requests" => [
[
"addSheet": [
"properties" => [
"title" => "My sheet"
]
]
]
]
]
),
);
The request body contains an instance of ValueRange
$this->performRequest(
method: "PUT",
endpoint: '1234567890/values/Sheet1!A1:B2',
query: [
"valueInputOption" => 'USER_ENTERED',
],
body: json_encode([
"range": 'Sheet1!A1:B2',
"values" => [
[
"A1", "B1", "C1"
],
[
"A2", "B2", "C2"
],
[
"A3", "B3", "C3"
]
],
"majorDimension": "ROWS"
]),
);
The following is quite a simple example of updating cells, according to the object structure.
$this->performRequest(
method: "POST",
endpoint: '1234567890:batchUpdate',
body: json_encode(
[
"requests" => [
[
"updateCells": [
"range": [
"sheetId": 0,
"startRowIndex": 0,
"endRowIndex": 3,
"startColumnIndex": 0,
"endColumnIndex": 3
],
"rows": [
[
"values": [
[
"userEnteredValue": [
"stringValue": "A1"
]
],
[
"userEnteredValue": [
"stringValue": "B1"
]
],
[
"userEnteredValue": [
"stringValue": "C1"
]
]
]
],
[
"values": [
[
"userEnteredValue": [
"stringValue": "A2"
]
],
[
"userEnteredValue": [
"stringValue": "B2"
]
],
[
"userEnteredValue": [
"stringValue": "C2"
]
]
]
],
[
"values": [
[
"userEnteredValue": [
"stringValue": "A3"
]
],
[
"userEnteredValue": [
"stringValue": "B3"
]
],
[
"userEnteredValue": [
"stringValue": "C3"
]
]
]
]
],
"fields": "userEnteredValue"
]
]
]
]
),
);
The following is quite a simple example of adding a chart to a sheet, according to the object structure.
$this->performRequest(
method: "POST",
endpoint: '1234567890:batchUpdate',
body: json_encode(
[
"requests" => [
[
"addChart": [
"chart": [
"spec": [
"title": "Chart title",
"basicChart": [
"chartType": "COLUMN",
"legendPosition": "BOTTOM_LEGEND",
"axis": [
[
"position": "BOTTOM_AXIS",
"title": "X axis"
],
[
"position": "LEFT_AXIS",
"title": "Y axis"
]
],
"domains": [
[
"domain": [
"sourceRange": [
"sources": [
[
"sheetId": 0,
"startRowIndex": 0,
"endRowIndex": 1,
"startColumnIndex": 0,
"endColumnIndex": 1
]
]
]
]
]
],
"series": [
[
"series": [
"sourceRange": [
"sources": [
[
"sheetId": 0,
"startRowIndex": 0,
"endRowIndex": 1,
"startColumnIndex": 1,
"endColumnIndex": 2
]
]
]
],
"targetAxis": "LEFT_AXIS"
]
]
]
],
"position": [
"newSheet": true
],
]
]
]
]
]
),
);
The following are non-static methods that can be called from instances (client instances) of the SheetsApi class.
-
Gets the spreadsheet data.
Parameters
-
Required
spreadsheetId
: Integer
ID of the Spreadsheet to get data from.
-
-
Clears the sheet.
Parameters
-
Required
spreadsheetId
: String
ID of the spreadsheet where the sheet is located.
-
Optional
Note: If none of the following is specified, the first sheet will be cleared
-
sheetId
: Integer | null
The ID of the sheet to be cleared.
Defaults tonull
. -
sheetIndex
: Integer | null
The index of the sheet to be cleared.
Defaults tonull
. -
sheetTitle
: String | null
Title of the sheet to be cleared.
Defaults tonull
.
method
: ClearSheetMethods
The method to use to clear the sheet.
Defaults toClearSheetMethods::CLEAR_CELLS
.
-
-
-
Copies a sheet from one spreadsheet to another (or duplicates it in the same spreadsheet).
Parameters
-
Required
-
sourceSpreadsheetId
: String
ID of the Spreadsheet to copy the sheet from. -
sheetId
: Integer
ID of the sheet to be copied.
-
-
Optional
destinySpreadsheetId
: Integer | null
ID of the Spreadsheet to copy the sheet to. If not specified, the sheet will be copied to the same spreadsheet.
Defaults tonull
.
-
-
Creates a new sheet in the spreadsheet.
Parameters
-
Required
-
spreadsheetId
: String
ID of the Spreadsheet to add the chart to. -
index
: Integer
The zero-based index where the sheet should be inserted.
-
-
Optional
-
title
: String,
The title of the chart.
Defaults to"New Chart"
. -
sheetId
: Integer | null
A custom ID to identify the sheet. If not specified, an ID will be randomly generated.
Defaults tonull
. -
spreadsheetData
: Array | null
The spreadsheet data, which can be obtained through the getSpreadsheetData() method. Submitting this data will save a request to the API. If this parameter is not specified, the data will be fetched from the spreadsheet when needed.
Defaults tonull
.
-
-
-
Creates a new sheet at the start of the spreadsheet.
Parameters
-
Required
spreadsheetId
: String
ID of the Spreadsheet to add the chart to.
-
Optional
-
title
: String,
The title of the chart.
Defaults to"New Chart"
. -
sheetId
: Integer | null
A custom ID to identify the sheet. If not specified, an ID will be randomly generated.
Defaults tonull
.
-
-
-
Creates a new sheet at the end of the spreadsheet.
Parameters
-
Required
spreadsheetId
: String
ID of the Spreadsheet to add the chart to.
-
Optional
-
title
: String,
The title of the chart.
Defaults to"New Chart"
. -
sheetId
: Integer | null
A custom ID to identify the sheet. If not specified, an ID will be randomly generated.
Defaults tonull
. -
spreadsheetData
: Array | null
The spreadsheet data, which can be obtained through the getSpreadsheetData() method. Submitting this data will save a request to the API. If this parameter is not specified, the data will be fetched from the spreadsheet when needed.
Defaults tonull
.
-
-
-
Deletes a sheet from the spreadsheet.
Parameters
-
Required
-
spreadsheetId
: String
ID of the Spreadsheet to add the chart to. -
sheetId
: Integer
ID of the sheet to delete.
-
-
Optional
spreadsheetData
: Array | null
The spreadsheet data, which can be obtained through the getSpreadsheetData() method. Submitting this data will save a request to the API. If this parameter is not specified, the data will be fetched from the spreadsheet when needed.
Defaults tonull
.
-
-
Clears a range of cells.
Parameters
-
Required
-
spreadsheetId
: String
ID of the spreadsheet where the sheet is located. -
sheetId
: Integer
ID of the sheet to delete.
-
-
Optional
Note: If none of the following is specified, the first sheet will be cleared
-
sheetId
: Integer | null
The ID of the sheet to clear cells from.
Defaults tonull
. -
sheetIndex
: Integer | null
The index of the sheet to clear cells from.
Defaults tonull
. -
sheetTitle
: String | null
Title of the sheet to clear cells from.
Defaults tonull
.
-
startColumnIndex
: String | Integer
The column index of the first cell to clear.
Defaults to"A"
. -
startRowIndex
: Integer
The row index of the first cell to clear.
Defaults to1
. -
endColumnIndex
: String | Integer
The column index of the last cell to clear.
Defaults to"ZZ"
. -
endRowIndex
: Integer
The row index of the first cell to clear.
Defaults to1000000
. -
spreadsheetData
: Array | null
The spreadsheet data, which can be obtained through the getSpreadsheetData() method. Submitting this data will save a request to the API. If this parameter is not specified, the data will be fetched from the spreadsheet when needed.
Defaults tonull
.
-
-
-
Reads a range of cells.
Parameters
-
Required
-
spreadsheetId
: String
ID of the spreadsheet where the sheet is located. -
sheetId
: Integer
ID of the sheet to delete.
-
-
Optional
Note: If none of the following is specified, the first sheet will be cleared
-
sheetId
: Integer | null
The ID of the sheet to read cells from.
Defaults tonull
. -
sheetIndex
: Integer | null
The index of the sheet to read cells from.
Defaults tonull
. -
sheetTitle
: String | null
Title of the sheet to read cells from.
Defaults tonull
.
-
startColumnIndex
: String | Integer
The column index of the first cell to read.
Defaults to"A"
. -
startRowIndex
: Integer
The row index of the first cell to read.
Defaults to1
. -
endColumnIndex
: String | Integer
The column index of the last cell to read.
Defaults to"ZZ"
. -
endRowIndex
: Integer
The row index of the first cell to read.
Defaults to1000000
. -
spreadsheetData
: Array | null
The spreadsheet data, which can be obtained through the getSpreadsheetData() method. Submitting this data will save a request to the API. If this parameter is not specified, the data will be fetched from the spreadsheet when needed.
Defaults tonull
.
-
-
-
Updates a range of cells.
Parameters
-
Required
-
spreadsheetId
: String
ID of the spreadsheet where the sheet is located. -
sheetId
: Integer
ID of the sheet to delete.
-
-
Optional
-
rows
: Array
Updating rows' data and attributes.
Defaults to[]
. -
data
: Array
Updating rows' data and attributes. Simpler array format where each cell is an array of values that specifies the type and the value. Ex:[['type' => 'string', 'value' => 'Hello'], ['type' => 'number', 'value' => 123]]
. If "type" is not specified, it will be considered asstring
. Defaults to[]
. -
fields
: String
Fields to update. Fields not specified will be ignored.
Defaults to'*'
.
Note: If none of the following is specified, the first sheet will be cleared
-
sheetId
: Integer | null
The ID of the sheet to update cells to.
Defaults tonull
. -
sheetIndex
: Integer | null
The index of the sheet to update cells to.
Defaults tonull
. -
sheetTitle
: String | null
Title of the sheet to update cells to.
Defaults tonull
.
-
startColumnIndex
: String | Integer
The column index of the first cell to be updated.
Defaults to1
. -
startRowIndex
: Integer
The row index of the first cell to be updated.
Defaults to1
. -
endColumnIndex
: String | Integer
The column index of the last cell to be updated.
Defaults to1000000
. -
endRowIndex
: Integer
The row index of the first cell to be updated.
Defaults to1000000
. -
spreadsheetData
: Array | null
The spreadsheet data, which can be obtained through the getSpreadsheetData() method. Submitting this data will save a request to the API. If this parameter is not specified, the data will be fetched from the spreadsheet when needed.
Defaults tonull
.
-
-
-
Updates a range of cells.
Parameters
-
Required
spreadsheetId
: String
ID of the spreadsheet where the sheet is located.
-
Optional
-
data
: Array
Data to be written to the cells.
Defaults to[]
. -
majorDimension
: Dimension
The major dimension that results should use.
Defaults toDimension::ROWS
.
Note: If none of the following is specified, the first sheet will be cleared
-
sheetId
: Integer | null
The ID of the sheet to write data to.
Defaults tonull
. -
sheetIndex
: Integer | null
The index of the sheet to write data to.
Defaults tonull
. -
sheetTitle
: String | null
Title of the sheet to write data to.
Defaults tonull
.
-
startColumnIndex
: String | Integer
The column index of the first cell to be written into.
Defaults to"A"
. -
startRowIndex
: Integer
The row index of the first cell to be written into.
Defaults to1
. -
endColumnIndex
: String | Integer
The column index of the last cell to be written into.
Defaults to"ZZ"
. -
endRowIndex
: Integer
The row index of the first cell to be written into.
Defaults to1000000
. -
spreadsheetData
: Array | null
The spreadsheet data, which can be obtained through the getSpreadsheetData() method. Submitting this data will save a request to the API. If this parameter is not specified, the data will be fetched from the spreadsheet when needed.
Defaults tonull
. -
valueInputOption
: ValueInputOption
How the input data should be interpreted.
Defaults toValueInputOption::USER_ENTERED
. -
responseValueRenderOption
: ValueRenderOption
How values should be represented in the output.
Defaults toValueRenderOption::FORMATTED_VALUE
. -
responseDateTimeRenderOption
: DateTimeRenderOption
How dates, times, and durations should be represented in the output.
Defaults toDateTimeRenderOption::SERIAL_NUMBER
.
-
-
-
Adds a chart to a spreadsheet.
Parameters
-
Required
-
spreadsheetId
: Integer
ID of the Spreadsheet to add the chart to -
chartId
: Integer
Custom ID to identify the chart -
chartData
: Array
The chart's data in array format
-
-
Optional
-
dataSourceId
: String | null
The ID of the data source to use for the chart. If not specified, the chart will use the first data source in the spreadsheet.
Defaults tonull
. -
filterSpecs
: Array | null
The filters to apply to the chart.
Defaults tonull
. -
sortSpecs
: Array | null
If specified, the chart will be sorted by the specified data source.
Defaults tonull
. -
title
: String,
The title of the chart.
Defaults to"New Chart"
. -
subtitle
: String,
The subtitle of the chart.
Defaults to""
. -
fontName
: String,
The name of the font to use by default for all chart text (e.g. title, axis labels, legend).
Defaults to"Roboto"
.
Note: If none of the following is specified, the first sheet will be cleared
-
sheetId
: Integer | null
The ID of the sheet to add the chart to.
Defaults tonull
. -
sheetIndex
: Integer | null
The index of the sheet to add the chart to.
Defaults tonull
. -
sheetTitle
: String | null
Title of the sheet to add the chart to.
Defaults tonull
.
-
spreadsheetData
: Array | null
The spreadsheet data, which can be obtained through the getSpreadsheetData() method. Submitting this data will save a request to the API. If this parameter is not specified, the data will be fetched from the spreadsheet when needed.
Defaults tonull
. -
chartType
: ChartTypes
The type of the chart to be added.
Defaults toChartTypes::BASIC
.
-
-
properties
: SheetPropertiessheetId
: Integertitle
: Stringindex
: IntegersheetType
: SheetTypegridProperties
: GridPropertiesrowCount
: IntegercolumnCount
: IntegerfrozenRowCount
: IntegerfrozenColumnCount
: IntegerhideGridlines
: BooleanrowGroupControlAfter
: BooleancolumnGroupControlAfter
: Boolean
hidden
: BooleantabColorStyle
: ColorStylerightToLeft
: BooleandataSourceSheetProperties
: DataSourceSheetPropertiesdataSourceId
: Stringcolumns
: Array
DataSourceColumnreference
: DataSourceColumnReferencecolumnIndex
: IntegersheetId
: Integer
formula
: String
dataExecutionStatus
: DataExecutionStatusstate
: enum: DataExecutionStateerrorCode
: enum: DataExecutionErrorCodeerrorMessage
: StringlastRefreshTime
: String
rows
: Array
RowDatavalues
: Array CellDatauserEnteredValue
: ExtendedValueeffectiveValue
: ExtendedValueformattedValue
: StringuserEnteredFormat
: CellFormatnumberFormat
: NumberFormattype
: enum: NumberFormatTypepattern
: String
backgroundColorStyle
: ColorStyleborders
: Borderspadding
: Paddingtop
: Integerright
: Integerbottom
: Integerleft
: Integer
horizontalAlignment
: enum: HorizontalAlignverticalAlignment
: enum: VerticalAlignwrapStrategy
: enum: WrapStrategytextDirection
: enum: TextDirectiontextFormat
: TextFormathyperlinkDisplayType
: enum: HyperlinkDisplayTypetextRotation
: TextRotationangle
: Integervertical
: Boolean
chartId
: Integerspec
: ChartSpectitle
: StringaltText
: StringtitleTextFormat
: TextFormatsubtitle
: StringsubtitleTextFormat
: TextFormatsubtitlePosition
: TextPositionhorizontalAlignment
: enum: HorizontalAlign
fontName
: Stringmaximized
: BooleanbackgroundColorStyle
: ColorStyledataSourceChartProperties
: DataSourceChartPropertiesdataSourceId
: StringdataExecutionStatus
: DataExecutionStatusstate
: enum: DataExecutionStateerrorCode
: enum: DataExecutionErrorCodeerrorMessage
: StringlastRefreshTime
: String
filterSpecs
: Array
FilterSpecfilterCriteria
: FilterCriteriahiddenValues
: Array Stringcondition
: BooleanConditionvisibleBackgroundColorStyle
: ColorStylevisibleForegroundColorStyle
: ColorStyle
columnIndex
: IntegerdataSourceColumnReference
: DataSourceColumnReferencename
: String
sortSpecs
: Array
SortSpecsortOrder
: enum: SortOrderforegroundColorStyle
: ColorStylebackgroundColorStyle
: ColorStyledimensionIndex
: IntegerdataSourceColumnReference
: DataSourceColumnReferencename
: String
hiddenDimensionStrategy
: enum: ChartHiddenDimensionStrategybasicChart
: BasicChartSpecchartType
: enum: BasicChartTypelegendPosition
: enum: BasicChartLegendPositionaxis
: Array BasicChartAxisposition
: enum: BasicChartAxisPositiontitle
: Stringformat
: TextFormattitleTextPosition
: TextPositionhorizontalAlignment
: enum: HorizontalAlign
viewWindowOptions
: ChartAxisViewWindowOptionsviewWindowMin
: FloatviewWindowMax
: FloatviewWindowMode
: enum: ViewWindowMode
domains
: Array BasicChartDomaindomain
: ChartDatareversed
: Boolean
series
: Array
BasicChartSeriesseries
: ChartDatatargetAxis
: enum: BasicChartAxisPositiontype
: enum: BasicChartTypelineStyle
: LineStylewidth
: Integertype
: enum: LineDashType
dataLabel
: DataLabel
headerCount
: IntegerthreeDimensional
: BooleaninterpolateNulls
: BooleanstackedType
: enum: BasicChartStackedTypelineSmoothing
: BooleancompareMode
: enum: BasicChartCompareModetotalDataLabel
: DataLabel
pieChart
: PieChartSpeclegendPosition
: enum: PieChartLegendPositiondomain
: ChartDataseries
: ChartDatathreeDimensional
: BooleanpieHole
: Float
bublbeChart
: BubbleChartSpeclegendPosition
: enum: BubbleChartLegendPositionbubbleLabels
: ChartDatadomain
: ChartDataseries
: ChartDatagroupIds
: ChartDatabubleOpacity
: FloatbubbleBorderColorStyle
: ColorStylebubleMaxRadiusSize
: IntegerbubbleMinRadiusSize
: IntegerbubbleTextStyle
: TextFormat
candlestickChart
: CandlestickChartSpecdomain
: CandlestickDomaindata
: ChartDatareversed
: Boolean
data
: Array CandlestickDatalowSeries
: CandlestickSeriesdata
: ChartData
openSeries
: CandlestickSeriesdata
: ChartData
closeSeries
: CandlestickSeriesdata
: ChartData
highSeries
: CandlestickSeriesdata
: ChartData
orgChart
: OrgChartSpecnodeSize
: enum: OrgChartNodeSizenodeColorStyle
: ColorStyleselectedNodeColorStyle
: ColorStylelabels
: ChartDataparentLabels
: ChartData
tooltips
: ChartDatahistogramChart
: HistogramChartSpecseries
: Array HistogramSeriesbarColorStyle
: ColorStyledata
: ChartData
legendPosition
: enum: HistogramChartLegendPositionshowItemDividers
: BooleanbucketSize
: FloatoutlierPercentile
: Float
waterfallChart
: WaterfallChartSpecdomain
: WaterfallChartDomainseries
: Array WaterfallChartSeriesdata
: ChartDatapositiveColumnsStyle
: WaterfallChartColumnStylenegativeColumnsStyle
: WaterfallChartColumnStylesubtotalColumnsStyle
: WaterfallChartColumnStylehideTrailingSubtotal
: BooleancustomSubtotals
: Array WaterfallChartCustomSubtotalsubtotalIndex
: Integerlabel
: StringdataIsSubtotal
: Boolean
dataLabel
: DataLabel
treemapChart
: TreemapChartSpeclabels
: ChartDataparentLabels
: ChartDatasizeData
: ChartDatacolorData
: ChartDatatextFormat
: TextFormatlevels
: IntegerhintedLevels
: IntegerminValue
: FloatmaxValue
: FloatheaderColorStyle
: ColorStylecolorScale
: TreemapChartColorScalehideTooltips
: Boolean
scorecardChart
: ScorecardChartSpeckeyValueData
: ChartDatabaselineValueData
: ChartDataaggregateType
: enum: ChartAggregateTypekeyValueFormat
: KeyValueFormattextFormat
: TextFormatposition
: TextPositionhorizontalAlignment
: enum: HorizontalAlignment
baselineValueFormat
: BaselineValueFormatcomparisonType
: enum: ComparisonTypetextFormat
: TextFormatposition
: TextPositionhorizontalAlignment
: enum: HorizontalAlignment
description
: StringpositiveColorStyle
: ColorStylenegativeColorStyle
: ColorStyle
scaleFactor
: FloatnumberFormatSource
: _enum: ChartNumberFormatSourcecustomFormatOptions
: ChartCustomNumberFormatOptionsprefix
: Stringsuffix
: String
position
: EmbeddedObjectPositionsheetId
: IntegeroverlayPosition
: OverlayPositionanchorCell
: GridCoordinatesheetId
: IntegerrowIndex
: IntegercolumnIndex
: Integer
offsetXPixels
: IntegeroffsetYPixels
: IntegerwidthPixels
: IntegerheightPixels
: Integer
newSheet
: Boolean
border
: EmbeddedObjectBordercolorStyle
: ColorStyle
groupRule
: ChartGroupRuledateTimeRule
: ChartDateTimeRuletype
: enum: ChartDateTimeRuleType
histogramRule
: ChartHistogramRule - (Histogram Chart only)minValue
: FloatmaxValue
: FloatintervalSize
: Float
aggregateType
: enum: ChartAggregateTypesourceRange
: ChartSourceRangesources
: Array GridRange
columnReference
: DataSourceColumnReferencename
: String
type
: enum: DataLabelTypetextFormat
: TextFormatplacement
: enum: DataLabelPlacementcustomLabelData
: ChartDatacolorStyle
: ColorStyle - (Basic Chart only)pointStyle
: PointStyle - (Basic Chart only)size
: Floatshape
: enum: PointShape
styleOverrides
: Array - (Basic Chart only)
BasicSeriesDataPointStyleOverrideindex
: IntegercolorStyle
: ColorStylepointStyle
: PointStylesize
: Floatshape
: enum: PointShape
stringValue
: StringnumberValue
: FloatboolValue
: BooleanformulaValue
: StringerrorValue
: ErrorValuetype
: enum: ErrorTypemessage
: String
style
: enum: Stylewidth
: IntegercolorStyle
: ColorStyle
foregroundColorStyle
: ColorStylefontFamily
: StringfontSize
: Integerbold
: Booleanitalic
: Booleanstrikethrough
: Booleanunderline
: Booleanlink
: Linkuri
: String
rgbColor
: Colorred
: Floatgreen
: Floatblue
: Floatalpha
: Float
themeColor
: enum: ThemeColorType
sheetId
: IntegerstartRowIndex
: IntegerendRowIndex
: IntegerstartColumnIndex
: IntegerendColumnIndex
: Integer