Class Spreadsheet

Bảng tính

Truy cập và sửa đổi tệp Google Trang tính. Các thao tác phổ biến là thêm trang tính mới và thêm cộng tác viên.

Phương thức

Phương thứcLoại dữ liệu trả vềMô tả ngắn
addDeveloperMetadata(key)SpreadsheetThêm siêu dữ liệu nhà phát triển bằng khoá đã chỉ định vào bảng tính cấp cao nhất.
addDeveloperMetadata(key, visibility)SpreadsheetThêm siêu dữ liệu nhà phát triển với khoá đã chỉ định và chế độ hiển thị vào bảng tính.
addDeveloperMetadata(key, value)SpreadsheetThêm siêu dữ liệu nhà phát triển với khoá và giá trị được chỉ định vào bảng tính.
addDeveloperMetadata(key, value, visibility)SpreadsheetThêm siêu dữ liệu về nhà phát triển cùng với khoá, giá trị và chế độ hiển thị đã chỉ định vào bảng tính.
addEditor(emailAddress)SpreadsheetThêm người dùng cụ thể vào danh sách người chỉnh sửa cho Spreadsheet.
addEditor(user)SpreadsheetThêm người dùng cụ thể vào danh sách người chỉnh sửa cho Spreadsheet.
addEditors(emailAddresses)SpreadsheetThêm mảng người dùng nhất định vào danh sách người chỉnh sửa cho Spreadsheet.
addMenu(name, subMenus)voidTạo trình đơn mới trong giao diện người dùng Bảng tính.
addViewer(emailAddress)SpreadsheetThêm người dùng cụ thể vào danh sách người xem cho Spreadsheet.
addViewer(user)SpreadsheetThêm người dùng cụ thể vào danh sách người xem cho Spreadsheet.
addViewers(emailAddresses)SpreadsheetThêm mảng người dùng nhất định vào danh sách người xem cho Spreadsheet.
appendRow(rowContents)SheetThêm một hàng vào cuối khu vực lưu trữ dữ liệu hiện tại trong trang tính.
autoResizeColumn(columnPosition)SheetThiết lập chiều rộng của cột đã cho để vừa với nội dung.
copy(name)SpreadsheetSao chép bảng tính và trả lại bảng tính mới.
createDeveloperMetadataFinder()DeveloperMetadataFinderTrả về DeveloperMetadataFinder để tìm siêu dữ liệu nhà phát triển trong phạm vi bảng tính này.
createTextFinder(findText)TextFinderTạo một trình tìm kiếm văn bản cho bảng tính, có thể dùng để tìm và thay thế văn bản trong bảng tính.
deleteActiveSheet()SheetXoá trang tính đang hoạt động.
deleteColumn(columnPosition)SheetXoá cột tại vị trí cột đã cho.
deleteColumns(columnPosition, howMany)voidXoá một số cột bắt đầu tại vị trí cột đã cho.
deleteRow(rowPosition)SheetXoá hàng tại vị trí hàng đã cho.
deleteRows(rowPosition, howMany)voidXoá một số hàng bắt đầu tại vị trí hàng đã cho.
deleteSheet(sheet)voidXoá trang tính đã chỉ định.
duplicateActiveSheet()SheetSao chép trang tính đang hoạt động và đặt trang tính đó làm trang tính đang hoạt động.
getActiveCell()RangeTrả về ô hoạt động trong trang tính này.
getActiveRange()RangeTrả về dải ô đã chọn trong trang tính đang hoạt động hoặc null nếu không có dải ô hoạt động.
getActiveRangeList()RangeListTrả về danh sách dải ô đang hoạt động trong trang tính đang hoạt động hoặc null nếu không có dải ô nào đang hoạt động dải ô.
getActiveSheet()SheetXem trang tính đang hoạt động trong một bảng tính.
getAs(contentType)BlobTrả về dữ liệu bên trong đối tượng này dưới dạng một blob được chuyển đổi sang loại nội dung được chỉ định.
getBandings()Banding[]Trả về tất cả dải trong bảng tính này.
getBlob()BlobTrả về dữ liệu bên trong đối tượng này dưới dạng một blob.
getColumnWidth(columnPosition)IntegerLấy chiều rộng tính bằng pixel của cột đã cho.
getCurrentCell()RangeTrả về ô hiện tại trong trang tính đang hoạt động hoặc null nếu không có ô hiện tại.
getDataRange()RangeTrả về Range tương ứng với các phương diện có chứa dữ liệu.
getDataSourceFormulas()DataSourceFormula[]Lấy tất cả công thức nguồn dữ liệu.
getDataSourcePivotTables()DataSourcePivotTable[]Lấy tất cả bảng tổng hợp nguồn dữ liệu.
getDataSourceRefreshSchedules()DataSourceRefreshSchedule[]Xem lịch làm mới của bảng tính này.
getDataSourceSheets()DataSourceSheet[]Trả về tất cả trang tính nguồn dữ liệu trong bảng tính.
getDataSourceTables()DataSourceTable[]Lấy tất cả bảng nguồn dữ liệu.
getDataSources()DataSource[]Trả về tất cả nguồn dữ liệu trong bảng tính.
getDeveloperMetadata()DeveloperMetadata[]Lấy siêu dữ liệu nhà phát triển liên kết với bảng tính cấp cao nhất.
getEditors()User[]Lấy danh sách người chỉnh sửa cho Spreadsheet này.
getFormUrl()StringTrả về URL của biểu mẫu đã gửi câu trả lời đến bảng tính này hoặc null nếu bảng tính này không có biểu mẫu được liên kết.
getFrozenColumns()IntegerTrả về số lượng cột cố định.
getFrozenRows()IntegerTrả về số lượng hàng cố định.
getId()StringLấy giá trị nhận dạng duy nhất cho bảng tính này.
getImages()OverGridImage[]Trả về tất cả hình ảnh đè lên lưới trên trang tính.
getIterativeCalculationConvergenceThreshold()NumberTrả về giá trị ngưỡng dùng trong quá trình tính toán lặp lại.
getLastColumn()IntegerTrả về vị trí của cột cuối cùng có nội dung.
getLastRow()IntegerTrả về vị trí của hàng cuối cùng có nội dung.
getMaxIterativeCalculationCycles()IntegerTrả về số lần lặp tối đa để sử dụng trong quá trình tính toán lặp lại.
getName()StringXem tên tài liệu.
getNamedRanges()NamedRange[]Lấy tất cả dải ô được đặt tên trong bảng tính này.
getNumSheets()IntegerTrả về số lượng trang tính trong bảng tính này.
getOwner()UserTrả về chủ sở hữu tài liệu hoặc null đối với tài liệu trong bộ nhớ dùng chung.
getPredefinedSpreadsheetThemes()SpreadsheetTheme[]Trả về danh sách giao diện được xác định trước.
getProtections(type)Protection[]Lấy một mảng đối tượng đại diện cho tất cả dải ô hoặc trang tính được bảo vệ trong bảng tính.
getRange(a1Notation)RangeTrả về dải ô như được chỉ định trong ký hiệu A1 hoặc ký hiệu R1C1.
getRangeByName(name)RangeTrả về một dải ô được đặt tên, hoặc null nếu không tìm thấy dải ô có tên cho trước.
getRangeList(a1Notations)RangeListTrả về tập hợp RangeList biểu thị các dải ô trong cùng một trang tính được chỉ định bằng một danh sách không trống gồm các ký hiệu A1 hoặc ký hiệu R1C1.
getRecalculationInterval()RecalculationIntervalTrả về khoảng thời gian tính toán cho bảng tính này.
getRowHeight(rowPosition)IntegerLấy chiều cao tính bằng pixel của hàng đã cho.
getSelection()SelectionTrả về Selection hiện tại trong bảng tính.
getSheetByName(name)SheetTrả về một trang tính có tên cho sẵn.
getSheetId()IntegerTrả về mã nhận dạng của trang tính mà đối tượng này biểu thị.
getSheetName()StringTrả về tên trang tính.
getSheetValues(startRow, startColumn, numRows, numColumns)Object[][]Trả về lưới hình chữ nhật chứa các giá trị của dải ô này, bắt đầu từ toạ độ đã cho.
getSheets()Sheet[]Lấy tất cả trang tính trong bảng tính này.
getSpreadsheetLocale()StringLấy ngôn ngữ bảng tính.
getSpreadsheetTheme()SpreadsheetThemeTrả về giao diện hiện tại của bảng tính hoặc null nếu không áp dụng giao diện nào.
getSpreadsheetTimeZone()StringLấy múi giờ cho bảng tính.
getUrl()StringTrả về URL của một bảng tính cho sẵn.
getViewers()User[]Lấy danh sách người xem và người nhận xét cho Spreadsheet này.
hideColumn(column)voidẨn cột hoặc các cột trong dải ô đã cho.
hideRow(row)voidẨn các hàng trong dải ô đã cho.
insertColumnAfter(afterPosition)SheetChèn một cột sau vị trí đã cho của cột.
insertColumnBefore(beforePosition)SheetChèn một cột trước vị trí đã cho của cột.
insertColumnsAfter(afterPosition, howMany)SheetChèn một số lượng cột cho trước sau vị trí cột đã cho.
insertColumnsBefore(beforePosition, howMany)SheetChèn một số cột trước vị trí cột đã cho.
insertDataSourceSheet(spec)DataSourceSheetChèn một DataSourceSheet mới vào bảng tính và bắt đầu thực thi dữ liệu.
insertImage(blobSource, column, row)OverGridImageChèn Spreadsheet dưới dạng hình ảnh vào tài liệu tại một hàng và cột nhất định.
insertImage(blobSource, column, row, offsetX, offsetY)OverGridImageChèn Spreadsheet dưới dạng hình ảnh vào tài liệu tại một hàng và cột nhất định, với độ lệch pixel.
insertImage(url, column, row)OverGridImageChèn một hình ảnh vào tài liệu tại một hàng và cột cho trước.
insertImage(url, column, row, offsetX, offsetY)OverGridImageChèn hình ảnh vào tài liệu tại một hàng và cột nhất định, với một độ lệch pixel.
insertRowAfter(afterPosition)SheetChèn một hàng sau vị trí hàng đã cho.
insertRowBefore(beforePosition)SheetChèn một hàng trước vị trí hàng đã cho.
insertRowsAfter(afterPosition, howMany)SheetChèn một số hàng sau vị trí hàng đã cho.
insertRowsBefore(beforePosition, howMany)SheetChèn một số hàng trước vị trí hàng đã cho.
insertSheet()SheetChèn một trang tính mới vào bảng tính bằng cách sử dụng tên trang tính mặc định.
insertSheet(sheetIndex)SheetChèn một trang tính mới vào bảng tính tại chỉ mục đã cho.
insertSheet(sheetIndex, options)SheetChèn một trang tính mới vào bảng tính tại chỉ mục đã cho và sử dụng trang tính nâng cao không bắt buộc đối số.
insertSheet(options)SheetChèn một trang tính mới vào bảng tính, sử dụng tên trang tính mặc định và trang tính nâng cao (không bắt buộc) đối số.
insertSheet(sheetName)SheetChèn một trang tính mới có tên đã cho vào bảng tính.
insertSheet(sheetName, sheetIndex)SheetChèn một trang tính mới vào bảng tính có tên đã cho tại chỉ mục đã cho.
insertSheet(sheetName, sheetIndex, options)SheetChèn một trang tính mới vào bảng tính có tên cho sẵn tại chỉ mục đã cho và sử dụng đối số nâng cao không bắt buộc.
insertSheet(sheetName, options)SheetChèn một trang tính mới có tên đã cho vào bảng tính và sử dụng trang tính nâng cao (không bắt buộc) đối số.
insertSheetWithDataSourceTable(spec)SheetChèn một trang tính mới vào bảng tính, tạo một DataSourceTable mở rộng toàn bộ trang tính với thông số nguồn dữ liệu đã cho và bắt đầu thực thi dữ liệu.
isColumnHiddenByUser(columnPosition)BooleanTrả về xem cột đã cho có bị người dùng ẩn hay không.
isIterativeCalculationEnabled()BooleanTrả về xem có kích hoạt tính toán lặp lại trong bảng tính này hay không.
isRowHiddenByFilter(rowPosition)BooleanTrả về liệu hàng đã cho có bị ẩn bởi bộ lọc (không phải chế độ xem bộ lọc) hay không.
isRowHiddenByUser(rowPosition)BooleanTrả về xem hàng đã cho có bị người dùng ẩn hay không.
moveActiveSheet(pos)voidDi chuyển trang tính đang hoạt động đến vị trí đã cho trong danh sách trang tính.
moveChartToObjectSheet(chart)SheetTạo một trang tính SheetType.OBJECT mới và di chuyển biểu đồ đã cho vào trang tính đó.
refreshAllDataSources()voidLàm mới tất cả các nguồn dữ liệu được hỗ trợ và đối tượng nguồn dữ liệu được liên kết của các nguồn dữ liệu đó, bỏ qua các đối tượng không hợp lệ các đối tượng nguồn dữ liệu.
removeEditor(emailAddress)SpreadsheetXoá người dùng cụ thể khỏi danh sách người chỉnh sửa của Spreadsheet.
removeEditor(user)SpreadsheetXoá người dùng cụ thể khỏi danh sách người chỉnh sửa của Spreadsheet.
removeMenu(name)voidXoá trình đơn do addMenu(name, subMenus) thêm vào.
removeNamedRange(name)voidXoá một dải ô được đặt tên có tên đã cho.
removeViewer(emailAddress)SpreadsheetXoá người dùng cụ thể khỏi danh sách người xem và người nhận xét đối với Spreadsheet.
removeViewer(user)SpreadsheetXoá người dùng cụ thể khỏi danh sách người xem và người nhận xét đối với Spreadsheet.
rename(newName)voidĐổi tên tài liệu.
renameActiveSheet(newName)voidĐổi tên trang tính đang hoạt động hiện tại thành tên mới đã đặt.
resetSpreadsheetTheme()SpreadsheetThemeXoá giao diện đã áp dụng và đặt giao diện mặc định trên bảng tính.
setActiveRange(range)RangeĐặt dải ô được chỉ định làm active range trong trang tính đang hoạt động, với ô trên cùng bên trái trong dải ô dưới dạng current cell.
setActiveRangeList(rangeList)RangeListThiết lập danh sách các dải ô được chỉ định thành active ranges trong trang tính đang hoạt động.
setActiveSelection(range)RangeĐặt vùng lựa chọn đang hoạt động cho trang tính này.
setActiveSelection(a1Notation)RangeĐặt lựa chọn đang hoạt động, như được chỉ định trong ký hiệu A1 hoặc ký hiệu R1C1.
setActiveSheet(sheet)SheetĐặt trang tính đã cho thành trang tính đang hoạt động trong bảng tính.
setActiveSheet(sheet, restoreSelection)SheetĐặt trang tính đã cho thành trang tính đang hoạt động trong bảng tính với tùy chọn khôi phục chọn gần đây nhất trong trang tính đó.
setColumnWidth(columnPosition, width)SheetĐặt chiều rộng của cột đã cho theo pixel.
setCurrentCell(cell)RangeĐặt ô được chỉ định làm current cell.
setFrozenColumns(columns)voidCố định số lượng cột đã cho.
setFrozenRows(rows)voidCố định số hàng đã cho.
setIterativeCalculationConvergenceThreshold(minThreshold)SpreadsheetĐặt giá trị ngưỡng tối thiểu để tính toán lặp lại.
setIterativeCalculationEnabled(isEnabled)SpreadsheetĐặt xem có kích hoạt tính toán lặp lại trong bảng tính này hay không.
setMaxIterativeCalculationCycles(maxIterations)SpreadsheetĐặt số lần lặp lại tính toán tối đa cần được thực hiện trong lặp lại tính toán.
setNamedRange(name, range)voidĐặt tên cho một dải ô.
setRecalculationInterval(recalculationInterval)SpreadsheetĐặt tần suất tính toán lại của bảng tính này.
setRowHeight(rowPosition, height)SheetĐặt chiều cao hàng của hàng đã cho theo pixel.
setSpreadsheetLocale(locale)voidĐặt ngôn ngữ cho bảng tính.
setSpreadsheetTheme(theme)SpreadsheetThemeĐặt giao diện trên bảng tính.
setSpreadsheetTimeZone(timezone)voidĐặt múi giờ cho bảng tính.
show(userInterface)voidHiển thị thành phần giao diện người dùng tuỳ chỉnh trong hộp thoại được căn giữa trong màn hình trình duyệt của người dùng khung nhìn.
sort(columnPosition)SheetSắp xếp một trang tính theo cột, tăng dần.
sort(columnPosition, ascending)SheetSắp xếp trang tính theo cột.
toast(msg)voidHiển thị cửa sổ bật lên ở góc dưới bên phải của bảng tính có thông báo đã cho.
toast(msg, title)voidHiển thị cửa sổ bật lên ở góc dưới bên phải của bảng tính với thông báo đã cho và tiêu đề.
toast(msg, title, timeoutSeconds)voidHiển thị cửa sổ bật lên ở góc dưới bên phải của bảng tính có tiêu đề đã cho và tin nhắn, hiển thị trong một khoảng thời gian nhất định.
unhideColumn(column)voidHiện cột trong dải ô đã cho.
unhideRow(row)voidHiện hàng trong dải ô đã cho.
updateMenu(name, subMenus)voidCập nhật một thực đơn do addMenu(name, subMenus) thêm vào.
waitForAllDataExecutionsCompletion(timeoutInSeconds)voidChờ cho đến khi tất cả các lần thực thi hiện tại trong bảng tính hoàn tất, hết thời gian chờ sau số giây đã cung cấp.

Tài liệu chi tiết

addDeveloperMetadata(key)

Thêm siêu dữ liệu nhà phát triển bằng khoá đã chỉ định vào bảng tính cấp cao nhất.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Adds the key 'NAME' in the developer metadata for the spreadsheet.
ss.addDeveloperMetadata('NAME')

// Gets the first developer metadata object and logs its key.
const developerMetaData = ss.getDeveloperMetadata()[0]
console.log(developerMetaData.getKey())

Tham số

TênLoạiMô tả
keyStringKhoá cho siêu dữ liệu mới dành cho nhà phát triển.

Cầu thủ trả bóng

Spreadsheet — Bảng tính này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addDeveloperMetadata(key, visibility)

Thêm siêu dữ liệu nhà phát triển với khoá đã chỉ định và chế độ hiển thị vào bảng tính.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Adds the key 'NAME' in the developer metadata for the spreadsheet and sets the visibility
// to the developer project that created the metadata.
ss.addDeveloperMetadata('NAME', SpreadsheetApp.DeveloperMetadataVisibility.PROJECT);

// Gets the first developer metadata object and logs its key and visibility setting.
const developerMetaData = ss.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());
console.log(`Key: ${developerMetaData.getKey()},
.             Visibility: ${developerMetaData.getVisibility()}`);

Tham số

TênLoạiMô tả
keyStringKhoá cho siêu dữ liệu mới dành cho nhà phát triển.
visibilityDeveloperMetadataVisibilityChế độ hiển thị của siêu dữ liệu nhà phát triển mới.

Cầu thủ trả bóng

Spreadsheet — Bảng tính này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addDeveloperMetadata(key, value)

Thêm siêu dữ liệu nhà phát triển với khoá và giá trị được chỉ định vào bảng tính.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Adds the key 'NAME' and sets the value to 'GOOGLE' in the developer metadata for the
// spreadsheet.
ss.addDeveloperMetadata('NAME', 'GOOGLE');

// Gets the first developer metadata object and logs its key and value.
const developerMetaData = ss.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());
console.log(`Key: ${developerMetaData.getKey()}, Value: ${developerMetaData.getValue()}`);

Tham số

TênLoạiMô tả
keyStringKhoá cho siêu dữ liệu mới dành cho nhà phát triển.
valueStringGiá trị cho siêu dữ liệu nhà phát triển mới.

Cầu thủ trả bóng

Spreadsheet — Bảng tính này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addDeveloperMetadata(key, value, visibility)

Thêm siêu dữ liệu về nhà phát triển cùng với khoá, giá trị và chế độ hiển thị đã chỉ định vào bảng tính.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Adds the key 'NAME', sets the value to 'GOOGLE', and sets the visibility
// to any developer project with document access.
ss.addDeveloperMetadata('NAME', 'GOOGLE', SpreadsheetApp.DeveloperMetadataVisibility.DOCUMENT);

// Gets the first developer metadata object and logs its key, value, and visibility setting.
const developerMetaData = ss.getDeveloperMetadata()[0];
console.log(`Key: ${developerMetaData.getKey()},
             Value: ${developerMetaData.getValue()},
             Visibility: ${developerMetaData.getVisibility()}`);

Tham số

TênLoạiMô tả
keyStringKhoá cho siêu dữ liệu mới dành cho nhà phát triển.
valueStringGiá trị cho siêu dữ liệu nhà phát triển mới.
visibilityDeveloperMetadataVisibilityChế độ hiển thị của siêu dữ liệu nhà phát triển mới.

Cầu thủ trả bóng

Spreadsheet — Bảng tính này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addEditor(emailAddress)

Thêm người dùng cụ thể vào danh sách người chỉnh sửa cho Spreadsheet. Nếu người dùng đã trên danh sách người xem, thì phương pháp này sẽ đưa người dùng ra khỏi danh sách người xem.

Tham số

TênLoạiMô tả
emailAddressStringĐịa chỉ email của người dùng cần thêm.

Cầu thủ trả bóng

SpreadsheetSpreadsheet này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addEditor(user)

Thêm người dùng cụ thể vào danh sách người chỉnh sửa cho Spreadsheet. Nếu người dùng đã trên danh sách người xem, thì phương pháp này sẽ đưa người dùng ra khỏi danh sách người xem.

Tham số

TênLoạiMô tả
userUserĐại diện cho người dùng cần thêm.

Cầu thủ trả bóng

SpreadsheetSpreadsheet này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addEditors(emailAddresses)

Thêm mảng người dùng nhất định vào danh sách người chỉnh sửa cho Spreadsheet. Nếu bất kỳ người dùng đã có trong danh sách người xem, thì phương pháp này sẽ đẩy họ ra khỏi danh sách người xem.

Tham số

TênLoạiMô tả
emailAddressesString[]Một mảng địa chỉ email của những người dùng cần thêm.

Cầu thủ trả bóng

SpreadsheetSpreadsheet này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addMenu(name, subMenus)

Tạo trình đơn mới trong giao diện người dùng Bảng tính.

Mỗi mục trong trình đơn chạy một hàm do người dùng xác định. Thông thường, bạn sẽ muốn gọi hàm này từ hàm onOpen() để trình đơn được tạo tự động khi bảng tính được tải.

// The onOpen function is executed automatically every time a Spreadsheet is loaded
function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [];
  // When the user clicks on "addMenuExample" then "Menu Entry 1", the function function1 is
  // executed.
  menuEntries.push({name: "Menu Entry 1", functionName: "function1"});
  menuEntries.push(null); // line separator
  menuEntries.push({name: "Menu Entry 2", functionName: "function2"});

  ss.addMenu("addMenuExample", menuEntries);
}

Tham số

TênLoạiMô tả
nameStringTên của trình đơn sẽ được tạo.
subMenusObject[]Một mảng JavaScript sẽ ánh xạ với các tham số namefunctionName . Bạn có thể dùng các hàm trong các thư viện đi kèm, chẳng hạn như Library.libFunction1.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addViewer(emailAddress)

Thêm người dùng cụ thể vào danh sách người xem cho Spreadsheet. Nếu người dùng đã trên danh sách người chỉnh sửa, thì phương thức này không có hiệu lực.

Tham số

TênLoạiMô tả
emailAddressStringĐịa chỉ email của người dùng cần thêm.

Cầu thủ trả bóng

SpreadsheetSpreadsheet này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addViewer(user)

Thêm người dùng cụ thể vào danh sách người xem cho Spreadsheet. Nếu người dùng đã trên danh sách người chỉnh sửa, thì phương thức này không có hiệu lực.

Tham số

TênLoạiMô tả
userUserĐại diện cho người dùng cần thêm.

Cầu thủ trả bóng

SpreadsheetSpreadsheet này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addViewers(emailAddresses)

Thêm mảng người dùng nhất định vào danh sách người xem cho Spreadsheet. Nếu bất kỳ người dùng đã có trong danh sách người chỉnh sửa, nên phương pháp này không có ảnh hưởng gì đối với họ.

Tham số

TênLoạiMô tả
emailAddressesString[]Một mảng địa chỉ email của những người dùng cần thêm.

Cầu thủ trả bóng

SpreadsheetSpreadsheet này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

appendRow(rowContents)

Thêm một hàng vào cuối khu vực lưu trữ dữ liệu hiện tại trong trang tính. Nếu nội dung của ô bắt đầu với =, thì biến này được hiểu là một công thức.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Appends a new row with 3 columns to the bottom of the current
// data region in the sheet containing the values in the array.
sheet.appendRow(["a man", "a plan", "panama"]);

Tham số

TênLoạiMô tả
rowContentsObject[]Một mảng giá trị cần chèn vào sau hàng cuối cùng trong trang tính.

Cầu thủ trả bóng

Sheet – Trang tính này hữu ích cho việc tạo chuỗi phương thức.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

autoResizeColumn(columnPosition)

Thiết lập chiều rộng của cột đã cho để vừa với nội dung.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

sheet.getRange('a1').setValue('Whenever it is a damp, drizzly November in my soul...');

// Sets the first column to a width which fits the text
sheet.autoResizeColumn(1);

Tham số

TênLoạiMô tả
columnPositionIntegerVị trí của cột đã cho cần đổi kích thước.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

copy(name)

Sao chép bảng tính và trả lại bảng tính mới.

// This code makes a copy of the current spreadsheet and names it appropriately
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.copy("Copy of " + ss.getName());

Tham số

TênLoạiMô tả
nameStringTên của bản sao.

Cầu thủ trả bóng

Spreadsheet — Bảng tính này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

createDeveloperMetadataFinder()

Trả về DeveloperMetadataFinder để tìm siêu dữ liệu nhà phát triển trong phạm vi bảng tính này. Theo mặc định, thao tác này sẽ xem xét tất cả siêu dữ liệu được liên kết với bảng tính, trang tính, hàng và cột.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Adds developer metadata to the spreadsheet.
ss.addDeveloperMetadata('NAME', 'CHARLIE');
ss.addDeveloperMetadata('COMPANY', 'EXAMPLE ORGANIZATION');
ss.addDeveloperMetadata('TECHNOLOGY', 'JAVASCRIPT');

// Creates a developer metadata finder.
const developerMetadataFinder = ss.createDeveloperMetadataFinder();

// Finds the developer metadata objects with 'COMPANY' as the key.
const googleMetadataFromSpreadsheet = developerMetadataFinder.withKey('COMPANY').find();

// Gets the first result of developer metadata that has the key 'COMPANY' and logs its value.
console.log(googleMetadataFromSpreadsheet[0].getValue());

Cầu thủ trả bóng

DeveloperMetadataFinder — Một công cụ tìm siêu dữ liệu dành cho nhà phát triển để tìm siêu dữ liệu thuộc phạm vi của bảng tính này.


createTextFinder(findText)

Tạo một trình tìm kiếm văn bản cho bảng tính, có thể dùng để tìm và thay thế văn bản trong bảng tính. Quá trình tìm kiếm bắt đầu từ trang tính đầu tiên của bảng tính.

var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();

// Creates  a text finder.
var textFinder = spreadsheet.createTextFinder('dog');

// Returns the first occurrence of 'dog' in the spreadsheet.
var firstOccurrence = textFinder.findNext();

// Replaces the last found occurrence of 'dog' with 'cat' and returns the number
// of occurrences replaced.
var numOccurrencesReplaced = findOccurrence.replaceWith('cat');

Tham số

TênLoạiMô tả
findTextStringVăn bản cần tìm kiếm.

Cầu thủ trả bóng

TextFinderTextFinder cho bảng tính.


deleteActiveSheet()

Xoá trang tính đang hoạt động.

// The code below deletes the currently active sheet and stores the new active sheet in a
// variable
var newSheet = SpreadsheetApp.getActiveSpreadsheet().deleteActiveSheet();

Cầu thủ trả bóng

Sheet — Trang tính đang hoạt động mới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

deleteColumn(columnPosition)

Xoá cột tại vị trí cột đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Columns start at "1" - this deletes the first column
sheet.deleteColumn(1);

Tham số

TênLoạiMô tả
columnPositionIntegerVị trí của cột, bắt đầu từ 1 của cột đầu tiên.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

deleteColumns(columnPosition, howMany)

Xoá một số cột bắt đầu tại vị trí cột đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Columns start at "1" - this deletes the first two columns
sheet.deleteColumns(1, 2);

Tham số

TênLoạiMô tả
columnPositionIntegerVị trí của cột đầu tiên cần xoá.
howManyIntegerSố lượng cột cần xoá.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

deleteRow(rowPosition)

Xoá hàng tại vị trí hàng đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Rows start at "1" - this deletes the first row
sheet.deleteRow(1);

Tham số

TênLoạiMô tả
rowPositionIntegerVị trí của hàng, bắt đầu từ 1 cho hàng đầu tiên.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

deleteRows(rowPosition, howMany)

Xoá một số hàng bắt đầu tại vị trí hàng đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Rows start at "1" - this deletes the first two rows
sheet.deleteRows(1, 2);

Tham số

TênLoạiMô tả
rowPositionIntegerVị trí của hàng đầu tiên cần xoá.
howManyIntegerSố hàng cần xoá.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

deleteSheet(sheet)

Xoá trang tính đã chỉ định.

// The code below deletes the specified sheet.
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName('My Sheet');
ss.deleteSheet(sheet);

Tham số

TênLoạiMô tả
sheetSheetTrang tính cần xoá.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

duplicateActiveSheet()

Sao chép trang tính đang hoạt động và đặt trang tính đó làm trang tính đang hoạt động.

// The code below makes a duplicate of the active sheet
SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet();

Cầu thủ trả bóng

Sheet — Trang tính mới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getActiveCell()

Trả về ô hoạt động trong trang tính này.

Lưu ý: Bạn nên sử dụng getCurrentCell() để trả về giá trị hiện tại ô được đánh dấu.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Returns the active cell
var cell = sheet.getActiveCell();

Cầu thủ trả bóng

Range — ô hiện đang hoạt động

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getActiveRange()

Trả về dải ô đã chọn trong trang tính đang hoạt động hoặc null nếu không có dải ô hoạt động. Nếu nhiều dải ô đã được chọn, phương thức này chỉ trả về dải ô được chọn gần đây nhất.

Từ khoá "phạm vi hoạt động" đề cập đến dải ô mà người dùng đã chọn trong trang tính hiện hoạt, nhưng ở hàm tuỳ chỉnh, hàm này tham chiếu đến ô đang được tính toán lại chủ động.

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var activeRange = sheet.getActiveRange();

Cầu thủ trả bóng

Range — phạm vi hoạt động

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

Xem thêm


getActiveRangeList()

Trả về danh sách dải ô đang hoạt động trong trang tính đang hoạt động hoặc null nếu không có dải ô nào đang hoạt động dải ô.

Nếu bạn chọn một dải ô, thì mục này sẽ hoạt động như một lệnh gọi getActiveRange().

var sheet = SpreadsheetApp.getActiveSheet();
// Returns the list of active ranges.
var activeRangeList = sheet.getActiveRangeList();

Cầu thủ trả bóng

RangeList — danh sách các dải ô đang hoạt động

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

Xem thêm


getActiveSheet()

Xem trang tính đang hoạt động trong một bảng tính.

Trang tính đang hoạt động trong bảng tính là trang tính đang hiển thị trong bảng tính Giao diện người dùng.

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

Cầu thủ trả bóng

Sheet — Trang tính đang hoạt động trong bảng tính.


getAs(contentType)

Trả về dữ liệu bên trong đối tượng này dưới dạng một blob được chuyển đổi sang loại nội dung được chỉ định. Chiến dịch này sẽ thêm đuôi tệp thích hợp vào tên tệp (ví dụ: "myfile.pdf"). Tuy nhiên, việc này giả định rằng phần tên tệp tiếp sau dấu chấm cuối cùng (nếu có) là phần tên tệp hiện có tiện ích mở rộng cần được thay thế. Do đó, "ShoppingList.12.25.2014" trở thành "ShoppingList.12.25.pdf".

Để xem hạn mức hằng ngày cho lượt chuyển đổi, hãy xem bài viết Hạn mức cho Google Dịch vụ. Các miền Google Workspace mới tạo có thể tạm thời bị áp dụng quy định nghiêm ngặt hơn hạn mức.

Tham số

TênLoạiMô tả
contentTypeStringLoại MIME cần chuyển đổi. Đối với hầu hết các blob, 'application/pdf' là lựa chọn hợp lệ duy nhất. Đối với hình ảnh ở định dạng BMP, GIF, JPEG hoặc PNG, bất kỳ hình ảnh nào có định dạng 'image/bmp', 'image/gif', 'image/jpeg' hoặc 'image/png' cũng hợp lệ. Đối với tài liệu trên Google Tài liệu, 'text/markdown' cũng hợp lệ.

Cầu thủ trả bóng

Blob – Dữ liệu dưới dạng một blob.


getBandings()

Trả về tất cả dải trong bảng tính này.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Gets an array of the bandings in the spreadsheet.
const bandings = ss.getBandings();

// Logs the range of the first banding in the spreadsheet to the console.
console.log(bandings[0].getRange().getA1Notation());

Cầu thủ trả bóng

Banding[] — Các dải trong bảng tính này.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getBlob()

Trả về dữ liệu bên trong đối tượng này dưới dạng một blob.

Cầu thủ trả bóng

Blob – Dữ liệu dưới dạng một blob.


getColumnWidth(columnPosition)

Lấy chiều rộng tính bằng pixel của cột đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Columns start at 1
Logger.log(sheet.getColumnWidth(1));

Tham số

TênLoạiMô tả
columnPositionIntegerVị trí của cột cần kiểm tra.

Cầu thủ trả bóng

Integer – chiều rộng của cột tính bằng pixel

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getCurrentCell()

Trả về ô hiện tại trong trang tính đang hoạt động hoặc null nếu không có ô hiện tại. Chiến lược phát hành đĩa đơn ô hiện tại là ô được lấy tiêu điểm trong giao diện người dùng Google Trang tính và được đánh dấu bằng màu tối đường viền. Không bao giờ có nhiều hơn một ô hiện tại. Khi người dùng chọn một hoặc nhiều dải ô, một trong các ô trong phần lựa chọn là ô hiện tại.

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// Returns the current highlighted cell in the one of the active ranges.
var currentCell = sheet.getCurrentCell();

Cầu thủ trả bóng

Range — ô hiện tại

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getDataRange()

Trả về Range tương ứng với các phương diện có chứa dữ liệu.

Chức năng này tương đương với việc tạo một Dải ô được giới hạn bởi A1 và (Sheet.getLastColumn(), Sheet.getLastRow()).

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This represents ALL the data
var range = sheet.getDataRange();
var values = range.getValues();

// This logs the spreadsheet in CSV format with a trailing comma
for (var i = 0; i < values.length; i++) {
  var row = "";
  for (var j = 0; j < values[i].length; j++) {
    if (values[i][j]) {
      row = row + values[i][j];
    }
    row = row + ",";
  }
  Logger.log(row);
}

Cầu thủ trả bóng

Range – một dải ô bao gồm tất cả dữ liệu trong bảng tính

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getDataSourceFormulas()

Lấy tất cả công thức nguồn dữ liệu.

// Opens the spreadsheet by its ID. If you created your script from within a Google Sheets
// file, use SpreadsheetApp.getActiveSpreadsheet().
// TODO(developer): Replace the ID with your own.
const ss = SpreadsheetApp.openById('abc123456');

// Gets Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets an array of the data source formulas on Sheet1.
// To get an array of data source formulas for the entire spreadsheet,
// replace 'sheet' with 'ss'.
const dataSourceFormulas = sheet.getDataSourceFormulas();

// Logs the first data source formula in the array.
console.log(dataSourceFormulas[0].getFormula());

Cầu thủ trả bóng

DataSourceFormula[] – Danh sách các công thức nguồn dữ liệu.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getDataSourcePivotTables()

Lấy tất cả bảng tổng hợp nguồn dữ liệu.

// Opens the spreadsheet file by its ID. If you created your script from a Google Sheets file,
// use SpreadsheetApp.getActiveSpreadsheet().
// TODO(developer): Replace the ID with your own.
const ss = SpreadsheetApp.openById('abc123456');

// Gets Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets an array of the data source pivot tables on Sheet1.
// To get an array of data source pivot tables for the entire
// spreadsheet, replace 'sheet' with 'ss'.
const dataSourcePivotTables = sheet.getDataSourcePivotTables();

// Logs the last time that the first pivot table in the array was refreshed.
console.log(dataSourcePivotTables[0].getStatus().getLastRefreshedTime());

Cầu thủ trả bóng

DataSourcePivotTable[] – Danh sách các bảng tổng hợp nguồn dữ liệu.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getDataSourceRefreshSchedules()

Xem lịch làm mới của bảng tính này.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Activates BigQuery operations for the connected spreadsheet.
SpreadsheetApp.enableBigQueryExecution();

// Gets the frequency type of the first referesh schedule in the array.
const frequencyType = ss.getDataSourceRefreshSchedules()[0]
                        .getFrequency()
                        .getFrequencyType()
                        .toString();

// Logs the frequency type to the console.
console.log(frequencyType);

Cầu thủ trả bóng

DataSourceRefreshSchedule[] — Lịch làm mới của bảng tính này.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getDataSourceSheets()

Trả về tất cả trang tính nguồn dữ liệu trong bảng tính.

// Turns data execution on for BigQuery data sources.
SpreadsheetApp.enableBigQueryExecution();

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Gets the first data source sheet in the spreadsheet.
const dataSource = ss.getDataSourceSheets()[0];

// Gets the name of the data source sheet.
console.log(dataSource.asSheet().getName());

Cầu thủ trả bóng

DataSourceSheet[] – Một mảng gồm tất cả các trang tính nguồn dữ liệu.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getDataSourceTables()

Lấy tất cả bảng nguồn dữ liệu.

// Opens the spreadsheet file by its ID. If you created your script from a Google Sheets file,
// use SpreadsheetApp.getActiveSpreadsheet().
// TODO(developer): Replace the ID with your own.
const ss = SpreadsheetApp.openById('abc123456');

// Gets Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets an array of data source tables on Sheet1.
// To get an array of data source tables for the entire spreadsheet,
// replace 'sheet' with 'ss'.
const dataSourceTables = sheet.getDataSourceTables();

// Logs the last completed data execution time on the first data source table.
console.log(dataSourceTables[0].getStatus().getLastExecutionTime());

Cầu thủ trả bóng

DataSourceTable[] – Danh sách các bảng nguồn dữ liệu.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getDataSources()

Trả về tất cả nguồn dữ liệu trong bảng tính.

// Turns data execution on for BigQuery data sources.
SpreadsheetApp.enableBigQueryExecution();

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Gets the data sources on the spreadsheet.
const dataSources = ss.getDataSources();

// Logs the name of the first column on the first data source.
console.log(dataSources[0].getColumns()[0].getName());

Cầu thủ trả bóng

DataSource[] – Một mảng chứa tất cả các nguồn dữ liệu.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getDeveloperMetadata()

Lấy siêu dữ liệu nhà phát triển liên kết với bảng tính cấp cao nhất.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Adds 'Google' as a key to the spreadsheet metadata.
ss.addDeveloperMetadata('Google');

// Gets the spreadsheet's metadata.
const ssMetadata = ss.getDeveloperMetadata();

// Gets the first set of the spreadsheet's metadata and logs the key to the console.
console.log(ssMetadata[0].getKey());

Cầu thủ trả bóng

DeveloperMetadata[] — Siêu dữ liệu nhà phát triển được liên kết với dải ô này.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getEditors()

Lấy danh sách người chỉnh sửa cho Spreadsheet này.

Cầu thủ trả bóng

User[] — Một mảng người dùng có quyền chỉnh sửa.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getFormUrl()

Trả về URL của biểu mẫu đã gửi câu trả lời đến bảng tính này hoặc null nếu bảng tính này không có biểu mẫu được liên kết. Nếu nhiều biểu mẫu gửi câu trả lời tới bảng tính này, URL biểu mẫu được trả về là không xác định. Thay vào đó, theo mỗi liên kết URL của biểu mẫu trang tính sẽ được truy xuất thông qua phương thức Sheet.getFormUrl().

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Gets the form URL from the spreadsheet.
const formUrl = ss.getFormUrl();

// Logs the form URL to the console.
console.log(formUrl);

Cầu thủ trả bóng

String — URL cho biểu mẫu để đặt câu trả lời trong bảng tính này hoặc null nếu bảng tính này không có biểu mẫu được liên kết.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getFrozenColumns()

Trả về số lượng cột cố định.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

Logger.log("Number of frozen columns: %s", sheet.getFrozenColumns());

Cầu thủ trả bóng

Integer — số lượng cột cố định

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getFrozenRows()

Trả về số lượng hàng cố định.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

Logger.log("Number of frozen rows: %s", sheet.getFrozenRows());

Cầu thủ trả bóng

Integer – số lượng hàng cố định

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getId()

Lấy giá trị nhận dạng duy nhất cho bảng tính này. Bạn có thể trích xuất mã bảng tính từ URL của bảng tính. Ví dụ: mã nhận dạng bảng tính trong URL https://docs.google.com/Tiếm trong/d/abc1234567/

// The code below logs the ID for the active spreadsheet.
Logger.log(SpreadsheetApp.getActiveSpreadsheet().getId());

Cầu thủ trả bóng

String – Mã nhận dạng (hoặc khoá) duy nhất của bảng tính.


getImages()

Trả về tất cả hình ảnh đè lên lưới trên trang tính.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Gets Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets the over-the-grid images from Sheet1.
// To get the over-the-grid images from the entire spreadsheet, use ss.getImages() instead.
const images = sheet.getImages();

// For each image, logs the anchor cell in A1 notation.
for (const image of images) {
 console.log(image.getAnchorCell().getA1Notation());
}

Cầu thủ trả bóng

OverGridImage[] – Một mảng hình ảnh trên lưới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getIterativeCalculationConvergenceThreshold()

Trả về giá trị ngưỡng dùng trong quá trình tính toán lặp lại. Khi kết quả của lần kế tiếp phép tính khác nhau ít hơn giá trị này, thì việc tính toán lặp lại sẽ dừng.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Sets the iterative calculation convergence threshold for the spreadsheet.
ss.setIterativeCalculationConvergenceThreshold(2);

// Logs the threshold to the console.
console.log(ss.getIterativeCalculationConvergenceThreshold());

Cầu thủ trả bóng

Number — Ngưỡng hội tụ.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getLastColumn()

Trả về vị trí của cột cuối cùng có nội dung.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This logs the value in the very last cell of this sheet
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var lastCell = sheet.getRange(lastRow, lastColumn);
Logger.log(lastCell.getValue());

Cầu thủ trả bóng

Integer – cột cuối cùng của trang tính chứa nội dung

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getLastRow()

Trả về vị trí của hàng cuối cùng có nội dung.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This logs the value in the very last cell of this sheet
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var lastCell = sheet.getRange(lastRow, lastColumn);
Logger.log(lastCell.getValue());

Cầu thủ trả bóng

Integer – hàng cuối cùng của trang tính có chứa nội dung

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getMaxIterativeCalculationCycles()

Trả về số lần lặp tối đa để sử dụng trong quá trình tính toán lặp lại.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Sets the max iterative calculation cycles for the spreadsheet.
ss.setMaxIterativeCalculationCycles(10);

// Logs the max iterative calculation cycles to the console.
console.log(ss.getMaxIterativeCalculationCycles());

Cầu thủ trả bóng

Integer – Số lần lặp tính toán tối đa.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getName()

Xem tên tài liệu.

var ss = SpreadsheetApp.getActiveSpreadsheet();
Logger.log(ss.getName());

Cầu thủ trả bóng

String — Tên của bảng tính.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getNamedRanges()

Lấy tất cả dải ô được đặt tên trong bảng tính này.

// The code below logs the name of the first named range.
var namedRanges = SpreadsheetApp.getActiveSpreadsheet().getNamedRanges();
for (var i = 0; i < namedRanges.length; i++) {
  Logger.log(namedRanges[i].getName());
}

Cầu thủ trả bóng

NamedRange[] – Một mảng gồm tất cả dải ô được đặt tên trong bảng tính.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getNumSheets()

Trả về số lượng trang tính trong bảng tính này.

// The code below logs the number of sheets in the active spreadsheet.
Logger.log(SpreadsheetApp.getActiveSpreadsheet().getNumSheets());

Cầu thủ trả bóng

Integer — Số trang tính trong bảng tính.


getOwner()

Trả về chủ sở hữu tài liệu hoặc null đối với tài liệu trong bộ nhớ dùng chung.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var owner = ss.getOwner();
Logger.log(owner.getEmail());

Cầu thủ trả bóng

User – Chủ sở hữu tài liệu hoặc null nếu tài liệu nằm trong bộ nhớ dùng chung.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getPredefinedSpreadsheetThemes()

Trả về danh sách giao diện được xác định trước.

// The code below returns the list of predefined themes.
var predefinedThemesList = SpreadsheetApp.getActiveSpreadsheet()
                               .getPredefinedSpreadsheetThemes();

Cầu thủ trả bóng

SpreadsheetTheme[] — Danh sách các giao diện được xác định trước.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getProtections(type)

Lấy một mảng đối tượng đại diện cho tất cả dải ô hoặc trang tính được bảo vệ trong bảng tính.

// Remove all range protections in the spreadsheet that the user has permission to edit.
var ss = SpreadsheetApp.getActive();
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protections.length; i++) {
  var protection = protections[i];
  if (protection.canEdit()) {
    protection.remove();
  }
}
// Remove all sheet protections in the spreadsheet that the user has permission to edit.
var ss = SpreadsheetApp.getActive();
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET);
for (var i = 0; i < protections.length; i++) {
  var protection = protections[i];
  if (protection.canEdit()) {
    protection.remove();
  }
}

Tham số

TênLoạiMô tả
typeProtectionTypeLoại khu vực được bảo vệ, SpreadsheetApp.ProtectionType.RANGE hoặc SpreadsheetApp.ProtectionType.SHEET.

Cầu thủ trả bóng

Protection[] – Một mảng đối tượng đại diện cho tất cả dải ô hoặc trang tính được bảo vệ trong bảng tính.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getRange(a1Notation)

Trả về dải ô như được chỉ định trong ký hiệu A1 hoặc ký hiệu R1C1.

// Get a range A1:D4 on sheet titled "Invoices"
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getRange("Invoices!A1:D4");

// Get cell A1 on the first sheet
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("A1");

Tham số

TênLoạiMô tả
a1NotationStringDải ô cần trả về, như được chỉ định trong ký hiệu A1 hoặc ký hiệu R1C1.

Cầu thủ trả bóng

Range — phạm vi tại vị trí đã chỉ định

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getRangeByName(name)

Trả về một dải ô được đặt tên, hoặc null nếu không tìm thấy dải ô có tên cho trước. Nếu có nhiều các trang tính của bảng tính sử dụng cùng một tên dải ô, hãy chỉ định tên trang tính mà không cần thêm dấu ngoặc kép – ví dụ: getRangeByName('TaxRates') hoặc getRangeByName('Sheet Name!TaxRates'), nhưng không phải getRangeByName('"Sheet Name"!TaxRates').

// Log the number of columns for the range named 'TaxRates' in the active spreadsheet.
var range = SpreadsheetApp.getActiveSpreadsheet().getRangeByName('TaxRates');
if (range != null) {
  Logger.log(range.getNumColumns());
}

Tham số

TênLoạiMô tả
nameStringTên của dải ô cần tải.

Cầu thủ trả bóng

Range — Dải ô có tên được đặt.


getRangeList(a1Notations)

Trả về tập hợp RangeList biểu thị các dải ô trong cùng một trang tính được chỉ định bằng một danh sách không trống gồm các ký hiệu A1 hoặc ký hiệu R1C1.

// Get a list of ranges A1:D4, F1:H4.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var rangeList  = sheet.getRangeList(['A1:D4', 'F1:H4']);

Tham số

TênLoạiMô tả
a1NotationsString[]Danh sách các dải ô cần trả về, như được chỉ định trong ký hiệu A1 hoặc ký hiệu R1C1.

Cầu thủ trả bóng

RangeList – danh sách dải ô tại vị trí đã chỉ định

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getRecalculationInterval()

Trả về khoảng thời gian tính toán cho bảng tính này.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Logs the calculation interval for the spreadsheet to the console.
console.log(ss.getRecalculationInterval().toString());

Cầu thủ trả bóng

RecalculationInterval — Khoảng thời gian tính toán cho bảng tính này.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getRowHeight(rowPosition)

Lấy chiều cao tính bằng pixel của hàng đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Rows start at 1
Logger.log(sheet.getRowHeight(1));

Tham số

TênLoạiMô tả
rowPositionIntegerVị trí của hàng cần kiểm tra.

Cầu thủ trả bóng

Integer – chiều cao của hàng tính bằng pixel

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getSelection()

Trả về Selection hiện tại trong bảng tính.

var selection = SpreadsheetApp.getActiveSpreadsheet().getSelection();
var currentCell = selection.getCurrentCell();

Cầu thủ trả bóng

Selection — lựa chọn hiện tại

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getSheetByName(name)

Trả về một trang tính có tên cho sẵn.

Nếu nhiều trang tính có cùng tên, thì trang tính ngoài cùng bên trái sẽ được trả về. Trả về null nếu không có trang tính nào có tên được chỉ định.

// The code below logs the index of a sheet named "Expenses"
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Expenses");
if (sheet != null) {
  Logger.log(sheet.getIndex());
}

Tham số

TênLoạiMô tả
nameStringTên của trang tính cần tải.

Cầu thủ trả bóng

Sheet — Trang tính có tên đã cho.


getSheetId()

Trả về mã nhận dạng của trang tính mà đối tượng này biểu thị.

Đây là mã nhận dạng trang tính dành riêng cho bảng tính. Mã nhận dạng là đơn điệu số nguyên tăng dần được chỉ định tại thời điểm tạo trang tính độc lập với vị trí trang tính. Chiến dịch này rất hữu ích cùng với các phương thức như Range.copyFormatToRange(gridId, column, columnEnd, row, rowEnd). Phương thức này lấy tham số gridId thay vì thực thể Sheet.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

Logger.log(sheet.getSheetId());

Cầu thủ trả bóng

Integer — mã nhận dạng trang tính dành riêng cho bảng tính

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getSheetName()

Trả về tên trang tính.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

Logger.log(sheet.getSheetName());

Cầu thủ trả bóng

String – tên của trang tính

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getSheetValues(startRow, startColumn, numRows, numColumns)

Trả về lưới hình chữ nhật chứa các giá trị của dải ô này, bắt đầu từ toạ độ đã cho. A – 1 giá trị được cung cấp dưới dạng vị trí hàng hoặc cột tương đương với việc lấy hàng hoặc cột cuối cùng có dữ liệu trong trang tính.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// The two samples below produce the same output
var values = sheet.getSheetValues(1, 1, 3, 3);
Logger.log(values);

var range = sheet.getRange(1, 1, 3, 3);
values = range.getValues();
Logger.log(values);

Tham số

TênLoạiMô tả
startRowIntegerVị trí của hàng bắt đầu.
startColumnIntegerVị trí của cột bắt đầu.
numRowsIntegerSố hàng cần trả về giá trị.
numColumnsIntegerSố lượng cột cần trả về giá trị.

Cầu thủ trả bóng

Object[][] – một mảng giá trị hai chiều

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getSheets()

Lấy tất cả trang tính trong bảng tính này.

// The code below logs the name of the second sheet
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
if (sheets.length > 1) {
  Logger.log(sheets[1].getName());
}

Cầu thủ trả bóng

Sheet[] — Một mảng bao gồm tất cả các trang tính trong bảng tính.


getSpreadsheetLocale()

Lấy ngôn ngữ bảng tính.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Gets the spreadsheet locale.
const ssLocale = ss.getSpreadsheetLocale();

// Logs the locale to the console.
console.log(ssLocale);

Cầu thủ trả bóng

String — Ngôn ngữ của bảng tính.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getSpreadsheetTheme()

Trả về giao diện hiện tại của bảng tính hoặc null nếu không áp dụng giao diện nào.

// The code below returns the current theme of the spreadsheet.
var currentTheme = SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTheme();

Cầu thủ trả bóng

SpreadsheetTheme — Giao diện được áp dụng hiện tại.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getSpreadsheetTimeZone()

Lấy múi giờ cho bảng tính.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Sets the time zone of the spreadsheet.
ss.setSpreadsheetTimeZone('America/New_York');

// Gets the time zone of the spreadsheet.
const ssTimeZone = ss.getSpreadsheetTimeZone();

// Logs the time zone to the console.
console.log(ssTimeZone);

Cầu thủ trả bóng

String — Múi giờ, được chỉ định bằng "long" định dạng (ví dụ: "Mỹ/New_ Được" như liệt kê của Joda.org).

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getUrl()

Trả về URL của một bảng tính cho sẵn.

var ss = SpreadsheetApp.getActiveSpreadsheet();
Logger.log(ss.getUrl());

Cầu thủ trả bóng

String — URL của bảng tính đã cho.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getViewers()

Lấy danh sách người xem và người nhận xét cho Spreadsheet này.

Cầu thủ trả bóng

User[] — Một loạt người dùng có quyền xem hoặc nhận xét.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

hideColumn(column)

Ẩn cột hoặc các cột trong dải ô đã cho.

let ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheets()[0];

// This hides the first column
let range = sheet.getRange("A1");
sheet.hideColumn(range);

// This hides the first 3 columns
let range = sheet.getRange("A:C");
sheet.hideColumn(range);

Tham số

TênLoạiMô tả
columnRangeDải ô cột cần ẩn.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

hideRow(row)

Ẩn các hàng trong dải ô đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This hides the first row
var range = sheet.getRange("A1");
sheet.hideRow(range);

Tham số

TênLoạiMô tả
rowRangeDải ô hàng cần ẩn.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertColumnAfter(afterPosition)

Chèn một cột sau vị trí đã cho của cột.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This inserts a column after the first column position
sheet.insertColumnAfter(1);

Tham số

TênLoạiMô tả
afterPositionIntegerCột mà sau đó cột mới sẽ được thêm.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertColumnBefore(beforePosition)

Chèn một cột trước vị trí đã cho của cột.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This inserts a column in the first column position
sheet.insertColumnBefore(1);

Tham số

TênLoạiMô tả
beforePositionIntegerCột mà trước đó cột mới sẽ được thêm.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertColumnsAfter(afterPosition, howMany)

Chèn một số lượng cột cho trước sau vị trí cột đã cho.

let ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheets()[0];

// Inserts two columns after the first column on the first sheet of the spreadsheet.
sheet.insertColumnsAfter(1,2);

Tham số

TênLoạiMô tả
afterPositionIntegerCột mà sau đó cột mới sẽ được thêm.
howManyIntegerSố cột cần chèn.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertColumnsBefore(beforePosition, howMany)

Chèn một số cột trước vị trí cột đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This inserts five columns before the first column
sheet.insertColumnsBefore(1, 5);

Tham số

TênLoạiMô tả
beforePositionIntegerCột mà trước đó cột mới sẽ được thêm.
howManyIntegerSố cột cần chèn.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertDataSourceSheet(spec)

Chèn một DataSourceSheet mới vào bảng tính và bắt đầu thực thi dữ liệu. Là một thì hiệu ứng phụ này cũng khiến trang tính mới trở thành trang tính hiện hoạt.

Gửi một trường hợp ngoại lệ nếu loại nguồn dữ liệu không được bật. Sử dụng các phương thức SpreadsheetApp#enable...Execution() để cho phép thực thi dữ liệu đối với nguồn dữ liệu cụ thể loại.

// Activates BigQuery operations.
SpreadsheetApp.enableBigQueryExecution();

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Builds a data source specification.
// TODO (developer): Update the project ID to your own Google Cloud project ID.
const dataSourceSpec = SpreadsheetApp.newDataSourceSpec()
 .asBigQuery()
 .setProjectId('project-id-1')
 .setTableProjectId('bigquery-public-data')
 .setDatasetId('ncaa_basketball')
 .setTableId('mbb_historical_teams_games')
 .build();

// Adds the data source and its data to the spreadsheet.
ss.insertDataSourceSheet(dataSourceSpec);

Tham số

TênLoạiMô tả
specDataSourceSpecThông số kỹ thuật của nguồn dữ liệu cần chèn.

Cầu thủ trả bóng

DataSourceSheet — Trang tính nguồn dữ liệu mới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertImage(blobSource, column, row)

Chèn Spreadsheet dưới dạng hình ảnh vào tài liệu tại một hàng và cột nhất định. Hình ảnh kích thước được truy xuất từ nội dung của blob. Kích thước tối đa được hỗ trợ của blob là 2 MB.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

var blob = Utilities.newBlob(binaryData, 'image/png', 'MyImageName');
sheet.insertImage(blob, 1, 1);

Tham số

TênLoạiMô tả
blobSourceBlobSourceBlob chứa nội dung hình ảnh, loại MIME và tên (không bắt buộc).
columnIntegerVị trí cột.
rowIntegerVị trí hàng.

Cầu thủ trả bóng

OverGridImage — Hình ảnh đã chèn.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertImage(blobSource, column, row, offsetX, offsetY)

Chèn Spreadsheet dưới dạng hình ảnh vào tài liệu tại một hàng và cột nhất định, với độ lệch pixel. Kích thước hình ảnh được truy xuất từ nội dung của blob. Blob tối đa được hỗ trợ có kích thước 2MB.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

var blob = Utilities.newBlob(binaryData, 'image/png', 'MyImageName');
sheet.insertImage(blob, 1, 1, 10, 10);

Tham số

TênLoạiMô tả
blobSourceBlobSourceBlob chứa nội dung hình ảnh, loại MIME và tên (không bắt buộc).
columnIntegerVị trí cột.
rowIntegerVị trí hàng.
offsetXIntegerĐộ lệch ngang từ góc ô tính bằng pixel.
offsetYIntegerĐộ lệch dọc tính từ góc của ô tính bằng pixel.

Cầu thủ trả bóng

OverGridImage — Hình ảnh đã chèn.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertImage(url, column, row)

Chèn một hình ảnh vào tài liệu tại một hàng và cột cho trước.

URL đã cung cấp phải truy cập được công khai.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

sheet.insertImage("https://www.google.com/images/srpr/logo3w.png", 1, 1);

Tham số

TênLoạiMô tả
urlStringURL của hình ảnh.
columnIntegerVị trí cột lưới.
rowIntegerVị trí hàng lưới.

Cầu thủ trả bóng

OverGridImage — Hình ảnh đã chèn.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertImage(url, column, row, offsetX, offsetY)

Chèn hình ảnh vào tài liệu tại một hàng và cột nhất định, với một độ lệch pixel.

URL đã cung cấp phải truy cập được công khai.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

sheet.insertImage("https://www.google.com/images/srpr/logo3w.png", 1, 1, 10, 10);

Tham số

TênLoạiMô tả
urlStringURL của hình ảnh.
columnIntegerVị trí cột.
rowIntegerVị trí hàng.
offsetXIntegerĐộ lệch ngang từ góc ô tính bằng pixel.
offsetYIntegerĐộ lệch dọc tính từ góc của ô tính bằng pixel.

Cầu thủ trả bóng

OverGridImage — Hình ảnh đã chèn.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertRowAfter(afterPosition)

Chèn một hàng sau vị trí hàng đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This inserts a row after the first row position
sheet.insertRowAfter(1);

Tham số

TênLoạiMô tả
afterPositionIntegerHàng mà sau đó hàng mới sẽ được thêm.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertRowBefore(beforePosition)

Chèn một hàng trước vị trí hàng đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This inserts a row before the first row position
sheet.insertRowBefore(1);

Tham số

TênLoạiMô tả
beforePositionIntegerHàng mà trước đó hàng mới sẽ được thêm vào.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertRowsAfter(afterPosition, howMany)

Chèn một số hàng sau vị trí hàng đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This inserts five rows after the first row
sheet.insertRowsAfter(1, 5);

Tham số

TênLoạiMô tả
afterPositionIntegerHàng mà sau đó các hàng mới sẽ được thêm.
howManyIntegerSố hàng cần chèn.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertRowsBefore(beforePosition, howMany)

Chèn một số hàng trước vị trí hàng đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This inserts five rows before the first row
sheet.insertRowsBefore(1, 5);

Tham số

TênLoạiMô tả
beforePositionIntegerHàng mà trước đó các hàng mới sẽ được thêm vào.
howManyIntegerSố hàng cần chèn.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertSheet()

Chèn một trang tính mới vào bảng tính bằng cách sử dụng tên trang tính mặc định. Trang tính mới sẽ trở thành trang tính đang hoạt động.

var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.insertSheet();

Cầu thủ trả bóng

Sheet — Trang tính mới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertSheet(sheetIndex)

Chèn một trang tính mới vào bảng tính tại chỉ mục đã cho. Trang tính mới sẽ trở thành trang tính.

var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.insertSheet(1);

Tham số

TênLoạiMô tả
sheetIndexIntegerChỉ mục của trang tính mới tạo. Để chèn một trang tính làm trang tính đầu tiên trong bảng tính, đặt thành 0.

Cầu thủ trả bóng

Sheet — Trang tính mới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertSheet(sheetIndex, options)

Chèn một trang tính mới vào bảng tính tại chỉ mục đã cho và sử dụng trang tính nâng cao không bắt buộc đối số. Trang tính mới sẽ trở thành trang tính hiện hoạt.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var templateSheet = ss.getSheetByName('Sales');
ss.insertSheet(1, {template: templateSheet});

Tham số

TênLoạiMô tả
sheetIndexIntegerChỉ mục của trang tính mới tạo. Để chèn một trang tính làm trang tính đầu tiên trong bảng tính, đặt thành 0.
optionsObjectĐối số nâng cao không bắt buộc của JavaScript.

Thông số nâng cao

TênLoạiMô tả
templateSheetTất cả dữ liệu từ đối tượng trang tính mẫu đều được sao chép vào trang tính mới. Mẫu trang tính phải là một trong các trang tính của đối tượng Bảng tính.

Cầu thủ trả bóng

Sheet — Trang tính mới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertSheet(options)

Chèn một trang tính mới vào bảng tính, sử dụng tên trang tính mặc định và trang tính nâng cao (không bắt buộc) đối số. Trang tính mới sẽ trở thành trang tính hiện hoạt.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var templateSheet = ss.getSheetByName('Sales');
ss.insertSheet({template: templateSheet});

Tham số

TênLoạiMô tả
optionsObjectCác đối số nâng cao không bắt buộc của JavaScript, được liệt kê bên dưới.

Thông số nâng cao

TênLoạiMô tả
templateSheetTất cả dữ liệu từ đối tượng trang tính mẫu đều được sao chép vào trang tính mới. Mẫu trang tính phải là một trong các trang tính của đối tượng Bảng tính này.

Cầu thủ trả bóng

Sheet — Trang tính mới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertSheet(sheetName)

Chèn một trang tính mới có tên đã cho vào bảng tính. Trang tính mới sẽ trở thành trang tính.

var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.insertSheet('My New Sheet');

Tham số

TênLoạiMô tả
sheetNameStringTên của trang tính mới.

Cầu thủ trả bóng

Sheet — Trang tính mới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertSheet(sheetName, sheetIndex)

Chèn một trang tính mới vào bảng tính có tên đã cho tại chỉ mục đã cho. Trang tính mới sẽ trở thành trang tính đang hoạt động.

var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.insertSheet('My New Sheet', 1);

Tham số

TênLoạiMô tả
sheetNameStringTên của trang tính mới.
sheetIndexIntegerChỉ mục của trang tính mới tạo. Để chèn một trang tính làm trang tính đầu tiên trong bảng tính, đặt thành 0.

Cầu thủ trả bóng

Sheet — Trang tính mới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertSheet(sheetName, sheetIndex, options)

Chèn một trang tính mới vào bảng tính có tên cho sẵn tại chỉ mục đã cho và sử dụng đối số nâng cao không bắt buộc. Trang tính mới sẽ trở thành trang tính hiện hoạt.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var templateSheet = ss.getSheetByName('Sales');
ss.insertSheet('My New Sheet', 1, {template: templateSheet});

Tham số

TênLoạiMô tả
sheetNameStringTên của trang tính mới.
sheetIndexIntegerChỉ mục của trang tính mới được chèn. Để chèn một trang tính làm trang tính đầu tiên trong một bảng tính, hãy đặt thành 0.
optionsObjectĐối số nâng cao không bắt buộc của JavaScript.

Thông số nâng cao

TênLoạiMô tả
templateSheetTất cả dữ liệu từ đối tượng trang tính mẫu đều được sao chép vào trang tính mới. Mẫu trang tính phải là một trong các trang tính của đối tượng Bảng tính.

Cầu thủ trả bóng

Sheet — Trang tính mới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertSheet(sheetName, options)

Chèn một trang tính mới có tên đã cho vào bảng tính và sử dụng trang tính nâng cao (không bắt buộc) đối số. Trang tính mới sẽ trở thành trang tính hiện hoạt.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var templateSheet = ss.getSheetByName('Sales');
ss.insertSheet('My New Sheet', {template: templateSheet});

Tham số

TênLoạiMô tả
sheetNameStringTên của trang tính mới.
optionsObjectĐối số nâng cao không bắt buộc của JavaScript.

Thông số nâng cao

TênLoạiMô tả
templateSheetTất cả dữ liệu từ đối tượng trang tính mẫu đều được sao chép vào trang tính mới. Mẫu trang tính phải là một trong các trang tính của đối tượng Bảng tính.

Cầu thủ trả bóng

Sheet — Trang tính mới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

insertSheetWithDataSourceTable(spec)

Chèn một trang tính mới vào bảng tính, tạo một DataSourceTable mở rộng toàn bộ trang tính với thông số nguồn dữ liệu đã cho và bắt đầu thực thi dữ liệu. Ở một bên sẽ đặt trang tính mới làm trang tính hiện hoạt.

Gửi một trường hợp ngoại lệ nếu loại nguồn dữ liệu không được bật. Sử dụng các phương thức SpreadsheetApp#enable...Execution() để cho phép thực thi dữ liệu đối với nguồn dữ liệu cụ thể loại.

// Activates BigQuery operations.
SpreadsheetApp.enableBigQueryExecution();

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Adds a sheet and sets cell A1 as the parameter cell.
const parameterCell = ss.insertSheet('parameterSheet').getRange('A1');

// Sets the value of the parameter cell to 'Duke'.
parameterCell.setValue('Duke');

const query = 'select * from `bigquery-public-data`.`ncaa_basketball`.' +
  '`mbb_historical_tournament_games` WHERE win_school_ncaa = @SCHOOL';

// Adds a data source with a query parameter.
// TODO(developer): Update the project ID to your own Google Cloud project ID.
const dataSourceSpec = SpreadsheetApp.newDataSourceSpec()
 .asBigQuery()
 .setProjectId('project-id-1')
 .setRawQuery(query)
 .setParameterFromCell('SCHOOL', 'parameterSheet!A1')
 .build();

// Adds sheets for the data source and data source table to the spreadsheet.
ss.insertSheetWithDataSourceTable(dataSourceSpec);

Tham số

TênLoạiMô tả
specDataSourceSpecThông số kỹ thuật của nguồn dữ liệu cần chèn.

Cầu thủ trả bóng

Sheet — Trang tính mới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

isColumnHiddenByUser(columnPosition)

Trả về xem cột đã cho có bị người dùng ẩn hay không.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Columns start at 1
Logger.log(sheet.isColumnHiddenByUser(1));

Tham số

TênLoạiMô tả
columnPositionIntegerVị trí của cột cần kiểm tra.

Cầu thủ trả bóng

Booleantrue nếu cột bị ẩn, nếu không thì false.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

isIterativeCalculationEnabled()

Trả về xem có kích hoạt tính toán lặp lại trong bảng tính này hay không.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Activates iterative calculation on the spreadsheet.
ss.setIterativeCalculationEnabled(true);

// Logs whether iterative calculation is activated for the spreadsheet.
console.log(ss.isIterativeCalculationEnabled());

Cầu thủ trả bóng

Booleantrue nếu kích hoạt tính toán lặp lại, nếu không thì là false.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

isRowHiddenByFilter(rowPosition)

Trả về liệu hàng đã cho có bị ẩn bởi bộ lọc (không phải chế độ xem bộ lọc) hay không.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Rows start at 1
Logger.log(sheet.isRowHiddenByFilter(1));

Tham số

TênLoạiMô tả
rowPositionIntegerVị trí của hàng cần kiểm tra.

Cầu thủ trả bóng

Booleantrue nếu hàng bị ẩn, nếu không thì false.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

isRowHiddenByUser(rowPosition)

Trả về xem hàng đã cho có bị người dùng ẩn hay không.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Rows start at 1
Logger.log(sheet.isRowHiddenByUser(1));

Tham số

TênLoạiMô tả
rowPositionIntegerVị trí của hàng cần kiểm tra.

Cầu thủ trả bóng

Booleantrue nếu hàng bị ẩn, nếu không thì false.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

moveActiveSheet(pos)

Di chuyển trang tính đang hoạt động đến vị trí đã cho trong danh sách trang tính. Gửi một ngoại lệ nếu có giá trị âm hoặc lớn hơn số trang tính.

// This example assumes that there are 2 sheets in the current
// active spreadsheet: one named "first" in position 1 and another named "second"
// in position 2.
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// Gets the "first" sheet and activates it.
var sheet = spreadsheet.getSheetByName("first").activate();

// Logs 'Current index of sheet: 1'
console.log("Current index of sheet: %s", sheet.getIndex());

spreadsheet.moveActiveSheet(2);

// Logs 'New index of sheet: 2'
console.log("New index of sheet: %s", sheet.getIndex());

Tham số

TênLoạiMô tả
posIntegerVị trí chỉ mục 1 để di chuyển trang tính đang hoạt động vào danh sách trang tính.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

moveChartToObjectSheet(chart)

Tạo một trang tính SheetType.OBJECT mới và di chuyển biểu đồ đã cho vào trang tính đó. Nếu biểu đồ đã nằm trên trang tính riêng, thì trang tính đó sẽ được trả về mà không cần tạo trang tính mới.

var sheet = SpreadsheetApp.getActiveSheet();
var chart = sheet.newChart().setPosition(1, 1, 0, 0).build();
sheet.insertChart(chart);
var objectSheet = SpreadsheetApp.getActive().moveChartToObjectSheet(chart);

Tham số

TênLoạiMô tả
chartEmbeddedChartBiểu đồ cần di chuyển.

Cầu thủ trả bóng

Sheet — Trang tính mà biểu đồ đang hiển thị.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

refreshAllDataSources()

Làm mới tất cả các nguồn dữ liệu được hỗ trợ và đối tượng nguồn dữ liệu được liên kết của các nguồn dữ liệu đó, bỏ qua các đối tượng không hợp lệ các đối tượng nguồn dữ liệu.

Sử dụng các phương thức SpreadsheetApp#enable...Execution() để cho phép thực thi dữ liệu cho nguồn dữ liệu cụ thể.

// Activates BigQuery operations.
SpreadsheetApp.enableBigQueryExecution();

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Gets the first data source sheet on the spreadsheet.
const dataSheet = ss.getDataSourceSheets()[0];

// Refreshes all data sources on the spreadsheet.
ss.refreshAllDataSources();

// Logs the last refreshed time of the first data source sheet.
console.log(`Last refresh time: ${dataSheet.getStatus().getLastRefreshedTime()}`);

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

removeEditor(emailAddress)

Xoá người dùng cụ thể khỏi danh sách người chỉnh sửa của Spreadsheet. Phương thức này không sẽ chặn người dùng truy cập vào Spreadsheet nếu họ thuộc một nhóm người dùng đã quyền truy cập chung. Ví dụ: nếu Spreadsheet được chia sẻ với toàn bộ hoặc nếu Spreadsheet nằm trong bộ nhớ dùng chung mà người dùng có thể truy cập.

Đối với các tệp trên Drive, thao tác này cũng sẽ xoá người dùng khỏi danh sách người xem.

Tham số

TênLoạiMô tả
emailAddressStringĐịa chỉ email của người dùng cần xoá.

Cầu thủ trả bóng

SpreadsheetSpreadsheet này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

removeEditor(user)

Xoá người dùng cụ thể khỏi danh sách người chỉnh sửa của Spreadsheet. Phương thức này không sẽ chặn người dùng truy cập vào Spreadsheet nếu họ thuộc một nhóm người dùng đã quyền truy cập chung. Ví dụ: nếu Spreadsheet được chia sẻ với toàn bộ hoặc nếu Spreadsheet nằm trong bộ nhớ dùng chung mà người dùng có thể truy cập.

Đối với các tệp trên Drive, thao tác này cũng sẽ xoá người dùng khỏi danh sách người xem.

Tham số

TênLoạiMô tả
userUserHình ảnh đại diện cho người dùng cần xoá.

Cầu thủ trả bóng

SpreadsheetSpreadsheet này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

removeMenu(name)

Xoá trình đơn do addMenu(name, subMenus) thêm vào. Đối số name phải có cùng giá trị với lệnh gọi tương ứng đến addMenu(name, subMenus).

// The onOpen function is executed automatically every time a Spreadsheet is loaded
function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  ss.addMenu("badMenu", [{name: "remove bad menu", functionName: "removeBadMenu"},
                                       {name: "foo", functionName: "foo"}]);
}
function removeBadMenu() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  ss.removeMenu("badMenu");  // name must match the name used when added the menu
}
function foo(){
// Do nothing
}

Tham số

TênLoạiMô tả
nameStringTên của trình đơn cần xoá.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

removeNamedRange(name)

Xoá một dải ô được đặt tên có tên đã cho. Gửi một trường hợp ngoại lệ nếu không có dải ô nào có tên đã cho có trong bảng tính.

// The code below creates a new named range "foo", and then remove it.
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setNamedRange("foo", ss.getActiveRange());
ss.removeNamedRange("foo");

Tham số

TênLoạiMô tả
nameStringTên dải ô.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

removeViewer(emailAddress)

Xoá người dùng cụ thể khỏi danh sách người xem và người nhận xét đối với Spreadsheet. Chiến dịch này sẽ không có hiệu lực nếu người dùng là người chỉnh sửa, không phải là người xem hoặc người nhận xét. Phương pháp này cũng không chặn người dùng truy cập vào Spreadsheet nếu họ thuộc một lớp người dùng có quyền truy cập chung, ví dụ: nếu Spreadsheet được chia sẻ với toàn bộ miền hoặc nếu Spreadsheet nằm trong bộ nhớ dùng chung mà người dùng có thể truy cập.

Đối với các tệp trên Drive, thao tác này cũng sẽ xoá người dùng khỏi danh sách người chỉnh sửa.

Tham số

TênLoạiMô tả
emailAddressStringĐịa chỉ email của người dùng cần xoá.

Cầu thủ trả bóng

SpreadsheetSpreadsheet này để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

removeViewer(user)

Xoá người dùng cụ thể khỏi danh sách người xem và người nhận xét đối với Spreadsheet. Chiến dịch này sẽ không có hiệu lực nếu người dùng là người chỉnh sửa chứ không phải người xem. Phương thức này cũng không chặn người dùng truy cập Spreadsheet nếu họ thuộc một nhóm người dùng có quyền truy cập chung quyền truy cập – ví dụ: nếu Spreadsheet được chia sẻ với toàn bộ miền của người dùng, hoặc nếu Spreadsheet nằm trong bộ nhớ dùng chung mà người dùng có thể truy cập.

Đối với các tệp trên Drive, thao tác này cũng sẽ xoá người dùng khỏi danh sách người chỉnh sửa.

Tham số

TênLoạiMô tả
userUserHình ảnh đại diện cho người dùng cần xoá.

Cầu thủ trả bóng

SpreadsheetSpreadsheet này để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

rename(newName)

Đổi tên tài liệu.

var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.rename("This is the new name");

Tham số

TênLoạiMô tả
newNameStringTên mới cho tài liệu.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

renameActiveSheet(newName)

Đổi tên trang tính đang hoạt động hiện tại thành tên mới đã đặt.

// The code below renames the active sheet to "Hello world"
SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet("Hello world");

Tham số

TênLoạiMô tả
newNameStringTên mới cho trang tính hiện đang hoạt động.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

resetSpreadsheetTheme()

Xoá giao diện đã áp dụng và đặt giao diện mặc định trên bảng tính.

// The code below applies default theme on the spreadsheet.
SpreadsheetApp.getActiveSpreadsheet().resetSpreadsheetTheme();

Cầu thủ trả bóng

SpreadsheetTheme – Giao diện mặc định.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setActiveRange(range)

Đặt dải ô được chỉ định làm active range trong trang tính đang hoạt động, với ô trên cùng bên trái trong dải ô dưới dạng current cell.

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getRange('A1:D4');
sheet.setActiveRange(range);

var selection = sheet.getSelection();
// Current cell: A1
var currentCell = selection.getCurrentCell();
// Active Range: A1:D4
var activeRange = selection.getActiveRange();

Tham số

TênLoạiMô tả
rangeRangeDải ô để đặt làm dải ô hoạt động.

Cầu thủ trả bóng

Range — phạm vi mới hoạt động

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setActiveRangeList(rangeList)

Thiết lập danh sách các dải ô được chỉ định thành active ranges trong trang tính đang hoạt động. Dải ô cuối cùng trong danh sách được đặt thành active range.

var sheet = SpreadsheetApp.getActiveSheet();
var rangeList = sheet.getRangeList(['D4', 'B2:C4']);
sheet.setActiveRangeList(rangeList);

var selection = sheet.getSelection();
// Current cell: B2
var currentCell = selection.getCurrentCell();
// Active range: B2:C4
var activeRange = selection.getActiveRange();
// Active range list: [D4, B2:C4]
var activeRangeList = selection.getActiveRangeList();

Tham số

TênLoạiMô tả
rangeListRangeListDanh sách các dải ô để chọn.

Cầu thủ trả bóng

RangeList — danh sách các dải ô mới được chọn

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setActiveSelection(range)

Đặt vùng lựa chọn đang hoạt động cho trang tính này.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

var range = sheet.getRange("A1:D4");
sheet.setActiveSelection(range);

Tham số

TênLoạiMô tả
rangeRangeDải ô để đặt làm lựa chọn đang hoạt động.

Cầu thủ trả bóng

Range — phạm vi mới hoạt động

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setActiveSelection(a1Notation)

Đặt lựa chọn đang hoạt động, như được chỉ định trong ký hiệu A1 hoặc ký hiệu R1C1.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

sheet.setActiveSelection("A1:D4");

Tham số

TênLoạiMô tả
a1NotationStringDải ô cần đặt thành hoạt động, như được chỉ định trong ký hiệu A1 hoặc ký hiệu R1C1.

Cầu thủ trả bóng

Range — phạm vi mới hoạt động

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setActiveSheet(sheet)

Đặt trang tính đã cho thành trang tính đang hoạt động trong bảng tính. Giao diện người dùng của Google Trang tính hiển thị trang tính đã chọn trừ phi trang tính đó thuộc về một bảng tính khác.

// The code below makes the first sheet active in the active spreadsheet.
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.setActiveSheet(spreadsheet.getSheets()[0]);

Tham số

TênLoạiMô tả
sheetSheetTrang tính cần đặt làm trang tính hoạt động.

Cầu thủ trả bóng

Sheet — Trang tính đang hoạt động.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setActiveSheet(sheet, restoreSelection)

Đặt trang tính đã cho thành trang tính đang hoạt động trong bảng tính với tùy chọn khôi phục chọn gần đây nhất trong trang tính đó. Giao diện người dùng của Google Trang tính hiển thị trang tính đã chọn trừ phi trang tính thuộc về một bảng tính khác.

var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var firstSheet = spreadsheet.getSheets()[0];
var secondSheet = spreadsheet.getSheets()[1];
// Set the first sheet as the active sheet and select the range D4:F4.
spreadsheet.setActiveSheet(firstSheet).getRange('D4:F4').activate();

// Switch to the second sheet to do some work.
spreadsheet.setActiveSheet(secondSheet);
// Switch back to first sheet, and restore its selection.
spreadsheet.setActiveSheet(firstSheet, true);

// The selection of first sheet is restored, and it logs D4:F4
var range = spreadsheet.getActiveSheet().getSelection().getActiveRange();
Logger.log(range.getA1Notation());

Tham số

TênLoạiMô tả
sheetSheetTrang tính đang hoạt động mới.
restoreSelectionBooleanTf true, lựa chọn gần đây nhất của trang tính đang hoạt động mới được chọn lại khi trang tính mới hoạt động; nếu là false, trang tính mới sẽ hoạt động mà không thay đổi lựa chọn hiện tại.

Cầu thủ trả bóng

Sheet — Trang tính đang hoạt động mới.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setColumnWidth(columnPosition, width)

Đặt chiều rộng của cột đã cho theo pixel.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Sets the first column to a width of 200 pixels
sheet.setColumnWidth(1, 200);

Tham số

TênLoạiMô tả
columnPositionIntegerVị trí của cột đã cho cần đặt.
widthIntegerChiều rộng tính bằng pixel cần đặt.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setCurrentCell(cell)

Đặt ô được chỉ định làm current cell.

Nếu ô được chỉ định có mặt trong một dải ô đã chọn thì dải ô đó sẽ trở thành dải ô đang hoạt động, trong đó ô là ô hiện tại.

Nếu ô được chỉ định không có trong bất kỳ dải ô nào đã chọn, thì mọi vùng chọn hiện có bị xoá và ô trở thành ô hiện tại và dải ô đang hoạt động.

Lưu ý:Range được chỉ định phải bao gồm một ô, nếu không thì hành động này sẽ gửi ra lỗi ngoại lệ.

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var cell = sheet.getRange('B5');
sheet.setCurrentCell(cell);

var selection = sheet.getSelection();
// Current cell: B5
var currentCell = selection.getCurrentCell();

Tham số

TênLoạiMô tả
cellRangeÔ cần đặt làm ô hiện tại.

Cầu thủ trả bóng

Range — ô hiện tại mới đặt

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setFrozenColumns(columns)

Cố định số lượng cột đã cho. Nếu 0, không có cột nào bị cố định.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Freezes the first column
sheet.setFrozenColumns(1);

Tham số

TênLoạiMô tả
columnsIntegerSố lượng cột cần cố định.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setFrozenRows(rows)

Cố định số hàng đã cho. Nếu bằng 0, sẽ không có hàng nào bị cố định.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Freezes the first row
sheet.setFrozenRows(1);

Tham số

TênLoạiMô tả
rowsIntegerSố hàng cần cố định.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setIterativeCalculationConvergenceThreshold(minThreshold)

Đặt giá trị ngưỡng tối thiểu để tính toán lặp lại. Khi kết quả của lần kế tiếp phép tính khác nhau ít hơn giá trị này, thì việc tính toán lặp lại sẽ dừng. Giá trị này phải là không âm và mặc định là 0, 05.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Sets the iterative calculation convergence threshold for the spreadsheet.
ss.setIterativeCalculationConvergenceThreshold(2);

// Logs the threshold to the console.
console.log(ss.getIterativeCalculationConvergenceThreshold());

Tham số

TênLoạiMô tả
minThresholdNumberNgưỡng hội tụ tối thiểu (không được là số âm).

Cầu thủ trả bóng

Spreadsheet — Bảng tính này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setIterativeCalculationEnabled(isEnabled)

Đặt xem có kích hoạt tính toán lặp lại trong bảng tính này hay không. Nếu số lượng tối đa chu kỳ tính toán và ngưỡng hội tụ chưa được đặt trước đây khi tính toán được kích hoạt, chúng mặc định lần lượt là 50 và 0,05. Nếu một trong hai tiêu chí đó đã được đặt trước đó, giữ lại các giá trị trước đó của chúng.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Activates iterative calculation on the spreadsheet.
ss.setIterativeCalculationEnabled(true);

// Logs whether iterative calculation is activated for the spreadsheet.
console.log(ss.isIterativeCalculationEnabled());

Tham số

TênLoạiMô tả
isEnabledBooleantrue nếu phải bật tính toán lặp lại; false nếu không.

Cầu thủ trả bóng

Spreadsheet — Bảng tính này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setMaxIterativeCalculationCycles(maxIterations)

Đặt số lần lặp lại tính toán tối đa cần được thực hiện trong lặp lại tính toán. Giá trị này phải nằm trong khoảng từ 1 đến 10.000 (bao gồm) và mặc định là 50.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Sets the max iterative calculation cycles for the spreadsheet.
ss.setMaxIterativeCalculationCycles(10);

// Logs the max iterative calculation cycles to the console.
console.log(ss.getMaxIterativeCalculationCycles());

Tham số

TênLoạiMô tả
maxIterationsIntegerSố lần lặp tính toán tối đa (từ 1 đến 10.000).

Cầu thủ trả bóng

Spreadsheet — Bảng tính này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setNamedRange(name, range)

Đặt tên cho một dải ô.

// The code below creates a new named range "TaxRates" in the active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setNamedRange("TaxRates", SpreadsheetApp.getActiveRange());

Tham số

TênLoạiMô tả
nameStringTên cần đặt cho dải ô.
rangeRangeThông số kỹ thuật của dải ô.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setRecalculationInterval(recalculationInterval)

Đặt tần suất tính toán lại của bảng tính này.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Sets the  calculation interval for the spreadsheet to 'ON_CHANGE'.
const interval = ss.setRecalculationInterval(SpreadsheetApp.RecalculationInterval.ON_CHANGE);

// Logs the calculation interval to the console.
console.log(interval);

Tham số

TênLoạiMô tả
recalculationIntervalRecalculationIntervalKhoảng thời gian tính toán lại mới.

Cầu thủ trả bóng

Spreadsheet — Bảng tính này, để tạo chuỗi.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setRowHeight(rowPosition, height)

Đặt chiều cao hàng của hàng đã cho theo pixel. Theo mặc định, các hàng sẽ mở rộng để vừa với nội dung của ô. Nếu bạn muốn buộc các hàng theo một chiều cao cụ thể, hãy sử dụng Sheet.setRowHeightsForced(startRow, numRows, height).

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Sets the first row to a height of 200 pixels
sheet.setRowHeight(1, 200);

Tham số

TênLoạiMô tả
rowPositionIntegerVị trí hàng cần thay đổi.
heightIntegerChiều cao tính bằng pixel để đặt giá trị.

Cầu thủ trả bóng

Sheet – Trang tính này hữu ích cho việc tạo chuỗi phương thức.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setSpreadsheetLocale(locale)

Đặt ngôn ngữ cho bảng tính.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Sets the spreadsheet locale.
ss.setSpreadsheetLocale('fr');

// Gets the spreadsheet locale.
const ssLocale = ss.getSpreadsheetLocale();

// Logs the locale to the console.
console.log(ssLocale);

Tham số

TênLoạiMô tả
localeStringMã ngôn ngữ để sử dụng (ví dụ: "en", "fr" hoặc "en_US").

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setSpreadsheetTheme(theme)

Đặt giao diện trên bảng tính.

var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// The code below sets the second predefined theme as the current theme of the spreadsheet.
var predefinedThemesList = spreadsheet.getPredefinedSpreadsheetThemes();
spreadsheet.setSpreadsheetTheme(predefinedThemesList[1]);

Tham số

TênLoạiMô tả
themeSpreadsheetThemeGiao diện sẽ áp dụng.

Cầu thủ trả bóng

SpreadsheetTheme — Giao diện mới hiện tại.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setSpreadsheetTimeZone(timezone)

Đặt múi giờ cho bảng tính.

// Opens the spreadsheet file by its URL. If you created your script from within a
// Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Sets the time zone of the spreadsheet.
ss.setSpreadsheetTimeZone('America/New_York');

// Gets the time zone of the spreadsheet.
const ssTimeZone = ss.getSpreadsheetTimeZone();

// Logs the time zone to the console.
console.log(ssTimeZone);

Tham số

TênLoạiMô tả
timezoneStringMúi giờ, được chỉ định bằng "long" (ví dụ: "Mỹ/New_ Được" là do Joda.org liệt kê).

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

show(userInterface)

Hiển thị thành phần giao diện người dùng tuỳ chỉnh trong hộp thoại được căn giữa trong màn hình trình duyệt của người dùng khung nhìn. Quá trình thực thi của tập lệnh phía máy chủ không bị tạm ngưng. Để giao tiếp với phía máy chủ, thành phần giao diện người dùng phải thực hiện lệnh gọi lại không đồng bộ đến phía máy chủ tập lệnh.

Nếu tập lệnh phía máy chủ trước đó hiển thị hộp thoại chưa bị đóng, thì hộp thoại hiện có sẽ được thay thế bằng giao diện người dùng của hộp thoại mới được yêu cầu.

Đoạn mã sau đây hiển thị một ứng dụng HtmlService đơn giản trong hộp thoại có tiêu đề, chiều cao và chiều rộng được chỉ định:

var htmlApp = HtmlService
    .createHtmlOutput('<p>A change of speed, a change of style...</p>')
    .setTitle('My HtmlService Application')
    .setWidth(250)
    .setHeight(300);

SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);

// The script resumes execution immediately after showing the dialog.

Tham số

TênLoạiMô tả
userInterfaceObjectHtmlOutput.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/script.container.ui

sort(columnPosition)

Sắp xếp một trang tính theo cột, tăng dần.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Sorts the sheet by the first column, ascending
sheet.sort(1);

Tham số

TênLoạiMô tả
columnPositionIntegerCột cần sắp xếp theo.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

sort(columnPosition, ascending)

Sắp xếp trang tính theo cột. Lấy một tham số để chỉ định tăng dần hoặc giảm dần.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Sorts the sheet by the first column, descending
sheet.sort(1, false);

Tham số

TênLoạiMô tả
columnPositionIntegerCột cần sắp xếp theo.
ascendingBooleantrue để sắp xếp tăng dần, false để giảm dần.

Cầu thủ trả bóng

Sheet – trang tính, hữu ích cho việc tạo chuỗi phương thức

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

toast(msg)

Hiển thị cửa sổ bật lên ở góc dưới bên phải của bảng tính có thông báo đã cho.

// Show a popup with the message "Task started".
SpreadsheetApp.getActiveSpreadsheet().toast('Task started');

Tham số

TênLoạiMô tả
msgStringTin nhắn sẽ xuất hiện trong thông báo ngắn.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

toast(msg, title)

Hiển thị cửa sổ bật lên ở góc dưới bên phải của bảng tính với thông báo đã cho và tiêu đề.

// Show a popup with the title "Status" and the message "Task started".
SpreadsheetApp.getActiveSpreadsheet().toast('Task started', 'Status');

Tham số

TênLoạiMô tả
msgStringTin nhắn sẽ xuất hiện trong thông báo ngắn.
titleStringTiêu đề không bắt buộc của thông báo ngắn.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

toast(msg, title, timeoutSeconds)

Hiển thị cửa sổ bật lên ở góc dưới bên phải của bảng tính có tiêu đề đã cho và tin nhắn, hiển thị trong một khoảng thời gian nhất định.

// Show a 3-second popup with the title "Status" and the message "Task started".
SpreadsheetApp.getActiveSpreadsheet().toast('Task started', 'Status', 3);

Tham số

TênLoạiMô tả
msgStringTin nhắn sẽ xuất hiện trong thông báo ngắn.
titleStringTiêu đề không bắt buộc của thông báo ngắn.
timeoutSecondsNumberThời gian chờ tính bằng giây; nếu là null, thông báo ngắn sẽ mặc định là 5 giây; nếu có giá trị âm, một thông báo ngắn vẫn sẽ xuất hiện cho đến khi bị loại bỏ.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

unhideColumn(column)

Hiện cột trong dải ô đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This unhides the first column if it was previously hidden
var range = sheet.getRange("A1");
sheet.unhideColumn(range);

Tham số

TênLoạiMô tả
columnRangeDải ô sẽ hiện, nếu bị ẩn.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

unhideRow(row)

Hiện hàng trong dải ô đã cho.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This unhides the first row if it was previously hidden
var range = sheet.getRange("A1");
sheet.unhideRow(range);

Tham số

TênLoạiMô tả
rowRangeDải ô sẽ hiện, nếu bị ẩn.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

updateMenu(name, subMenus)

Cập nhật một thực đơn do addMenu(name, subMenus) thêm vào. Hoạt động giống hệt như addMenu(name, subMenus).

var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [];
menuEntries.push({name: "Lone Menu Entry", functionName: "function1"});
ss.updateMenu("addMenuExample", menuEntries);

Tham số

TênLoạiMô tả
nameStringTên của trình đơn cần cập nhật.
subMenusObject[]Một mảng JavaScript sẽ ánh xạ với các tham số namefunctionName . Bạn có thể dùng các hàm trong các thư viện đi kèm, chẳng hạn như Library.libFunction1.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

waitForAllDataExecutionsCompletion(timeoutInSeconds)

Chờ cho đến khi tất cả các lần thực thi hiện tại trong bảng tính hoàn tất, hết thời gian chờ sau số giây đã cung cấp. Gửi một ngoại lệ nếu quá trình thực thi không hoàn tất vào đúng thời gian nhưng không huỷ các lần thực thi dữ liệu.

Tham số

TênLoạiMô tả
timeoutInSecondsIntegerThời gian để chờ thực thi dữ liệu, tính bằng giây. Tối đa là 300 giây.

Ủy quyền

Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

Các phương thức ngừng hoạt động