我正在使用google電子表格API使用node.js創建電子表格。我想在創建電子表格時添加一個標題(有三列h1,h2,h3)。我可以創建電子表格,但我無法添加標題。任何選項來做到這一點?使用Google電子表格創建電子表格時將標題添加到電子表格CREATE API
0
A
回答
0
如何跟隨GAS樣本?如果你想運行除了GAS,請告訴我。
要使用此功能,首先請啓用Google高級Google服務和Google API控制檯的Google表格API第4版。
如何使用它如下。
在腳本編輯器,選擇資源>高級谷歌服務
在出現的對話框中,點擊谷歌API表的on/off開關。
在該對話框的底部,單擊Google API控制檯的鏈接。
在控制檯中,單擊過濾器框並鍵入API「Google Sheets API」的部分名稱,然後單擊該名稱即可看到它。
在下一個屏幕上,單擊啓用API。
關閉Developers Console並返回到腳本編輯器。在對話框中單擊確定。您啓用的高級服務現在可用於自動完成。
詳細信息是https://developers.google.com/apps-script/guides/services/advanced。
腳本:
Sheets.Spreadsheets.create({
"properties":
{
"title": "filename" // filename
},
"sheets":
[
{
"data":
[
{
"startRow": 0, // 1st row
"startColumn": 7, // column h
"rowData":
[
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "sample text h1"
}
}
]
},
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "sample text h2"
}
}
]
},
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "sample text h3"
}
}
]
}
]
}
]
}
]
});
結果:
我爲做多JSON數據對不起。請更改示例文本。如果您想爲單元格使用數字,請使用"numberValue"
而不是"stringValue"
。
如果我誤解了你的問題,我很抱歉。
新增1:
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getRange('h1:h3');
var protection = range.protect().setDescription('protected');
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
上面的腳本保護h1:h3
。所有者可以編輯所有單元格,但其他用戶不能編輯h1:h3
。
新增2:
Sheets.Spreadsheets.create({
"properties":
{
"title": "filename"
},
"sheets":
[
{
"protectedRanges":
[
{
"range":
{
"startColumnIndex": 7,
"endColumnIndex": 8,
"startRowIndex": 0,
"endRowIndex": 3,
"sheetId": 0
},
"description": "protected",
"editors":
{
"users":
["your e-mail address"
]
}
}
],
"data":
[
{
"startColumn": 7,
"startRow": 0,
"rowData":
[
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "sample text h1"
}
}
]
},
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "sample text h2"
}
}
]
},
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "sample text h3"
}
}
]
}
]
}
],
"properties":
{
"sheetId": 0
}
}
]
});
該腳本創建新的電子表格。那時,它將數據添加到'h1:h3'並保護它們。請添加您的電子郵件地址作爲編輯器。這用於Google Sheet API v4。
相關問題
- 1. Google電子表格Java API不返回電子表格
- 2. Google電子表格
- 3. Google Apps電子表格中Google電子表格的時間而不是電子表格時區
- 4. Google表格電子表格格式
- 5. 創建電子表格
- 6. 使用google API更新電子表格
- 7. 是否可以使用Google電子表格API製作公開電子表格?
- 8. 將電子表格從電子表格遷移到網站
- 9. 枚舉Google電子表格?
- 10. 基於另一個電子表格的值將值添加到電子表格
- 11. 通過Google電子表格API添加標題
- 12. Google電子表格腳本
- 13. Google電子表格分享
- 14. Google網站電子表格
- 15. 通過Google文檔或電子表格API向Google電子表格添加新工作表
- 16. 電子表格API feed.getEntries()CellEntry
- 17. 僅授權Google電子表格API中的一個電子表格
- 18. Google電子表格API v4 - 隱藏列
- 19. Google Python API電子表格行/列數
- 20. 使用電子表格
- 21. 使用電子表格:: ParseExcel
- 22. 從Google電子表格創建表格:如何操作數據?
- 23. 如何使用Drive API創建空白Google電子表格?
- 24. LINQ表格到Excel電子表格
- 25. 使用Google電子表格的Android
- 26. 使用Android提交到Google電子表格表格
- 27. 用PHP創建Excel電子表格
- 28. 谷歌文檔/應用程序API:電子表格(Google表格)
- 29. 使用gspread創建的列表Google電子表格
- 30. 如何在Google電子表格中添加標題
這真的很有幫助!非常感謝。你能不能讓我知道如何在創建表格時讓這三個值H1,H2,H3不可編輯? –
您可以使用類保護。你可以在這裏看到細節。 https://developers.google.com/apps-script/reference/spreadsheet/protection – Tanaike
我認爲這個參考文獻可以幫助我,但我無法找到這個SpreadsheetApp類的來源以及如何將它集成到上面的代碼中。你能幫我麼? –