The solution is going to differ from excel-vba to google-spreadsheets-api but the method will be similar. In VBA, the result can be returned with either the Range.Formula property, Range.FormulaR1C1 property, Range.FormulaLocal property or Range.FormulaR1C1Local property after checking the cell's Range.HasFormula property.
The following is a User Defined Function¹ (aka UDF). See the footnote for implementation.
Function showFormula(rng As Range, _
Optional xlRefStyle As Variant, _
Optional bPFX As Boolean = False, _
Optional bLOC As Boolean = True)
If IsMissing(xlRefStyle) Then
xlRefStyle = Application.ReferenceStyle
ElseIf xlRefStyle <> 1 Then
xlRefStyle = xlR1C1
End If
If rng.Cells(1, 1).HasFormula Then
Select Case xlRefStyle
Case xlA1
If bLOC Then
showFormula = _
Replace(rng.Cells(1, 1).FormulaLocal, Chr(61), IIf(bPFX, Chr(61), vbNullString))
Else
showFormula = _
Replace(rng.Cells(1, 1).Formula, Chr(61), IIf(bPFX, Chr(61), vbNullString))
End If
Case xlR1C1
If bLOC Then
showFormula = _
Replace(rng.Cells(1, 1).FormulaR1C1Local, Chr(61), IIf(bPFX, Chr(61), vbNullString))
Else
showFormula = _
Replace(rng.Cells(1, 1).FormulaR1C1, Chr(61), IIf(bPFX, Chr(61), vbNullString))
End If
End Select
Else
showFormula = vbNullString
End If
End Function
Example of a SUMIFS formula in B4.

showFormula UDF syntax
On a system with German regional settings (and a DE-DE language version of Excel) the above would show as SUMMEWENNS(B1:B3; A1:A3; "a")
.

showFormula UDF syntax in DE-DE system
¹ A User Defined Function (aka UDF) is placed into a standard module code sheet. Tap Alt+F11 and when the VBE opens, immediately use the pull-down menus to Insert ► Module (Alt+I,M). Paste the function code into the new module code sheet titled something like Book1 - Module1 (Code). Tap Alt+Q to return to your worksheet(s).