我正在使用高级驱动器服务来设置“表格”列元数据。正在设置列ID,我可以检索它,但是sheetId
属性未设置。
function setShColumnMetadata() {
var request,response,ss,sh;
ss = SpreadsheetApp.getActiveSpreadsheet();
sh = ss.getSheetByName('Employees');
request = [
{
createDeveloperMetadata:{
developerMetadata:{
metadataKey:"employeeSh_DeptIdCol",
metadataValue:JSON.stringify({
writtenBy:Session.getEffectiveUser().getEmail(),
createdAt:new Date().getTime()
}),
location:{
//See https://developers.google.com/sheets/api/reference/rest/v4/DimensionRange
dimensionRange: {
"sheetId":sh.getSheetId(),
dimension:"COLUMNS",
startIndex:9,//column number + 1 is the real column being watched
endIndex:10
//Even though the end index is one more than the start index its only one column
}
},
visibility:"DOCUMENT"
}
}
}
];
response = Sheets.Spreadsheets.batchUpdate({requests:request}, ss.getId());
Logger.log('response: ' + response)
}
验证响应:
{
"replies":[
{"createDeveloperMetadata":
{"developerMetadata":
{"metadataKey":"employeeSh_DeptIdCol",
"visibility":"DOCUMENT",
"metadataValue":"{
\"writtenBy\":\"example@gmail.com\",
\"createdAt\":1530996621771
}",
"metadataId":1988973086,
"location":{
"dimensionRange":{
"startIndex":9,
"endIndex":10,
"dimension":"COLUMNS"
},
"locationType":"COLUMN"
}
}
}
}],
"spreadsheetId":"ID Removed"
}
问题出在dimensionRange
这是它的指定方式:
dimensionRange: {
//See https://developers.google.com/sheets/api/reference/rest/v4/DimensionRange
"sheetId":sh.getSheetId(),
dimension:"COLUMNS",
startIndex:9, //column number
endIndex:10
//Even though the end index is one more than the
//开始索引仅其一列 }
这就是回来了:
"dimensionRange":{
"startIndex":9,
"endIndex":10,
"dimension":"COLUMNS"
},
没有sheetId
如果我使用以下代码来获取保存的元数据:
function getTheSettingsBack() {
var metaDataClass,ssID,stateFound;
ssID = SpreadsheetApp.getActiveSpreadsheet().getId();
metaDataClass = Sheets.Spreadsheets.DeveloperMetadata;
stateFound = metaDataClass.search({
dataFilters:[{
developerMetadataLookup: {
metadataKey: 'employeeSh_DeptIdCol'
}}]
}, ssID);
Logger.log('stateFound: ' + stateFound)
}
它返回:
{"matchedDeveloperMetadata":
[{"dataFilters":[{"developerMetadataLookup":
{"metadataKey":"employeeSh_DeptIdCol"}}],"developerMetadata":
{"metadataKey":"employeeSh_DeptIdCol","visibility":"DOCUMENT",
"metadataValue":"{\"writtenBy\":\"account name here\",\"createdAt\":1530997558830}",
"metadataId":459573349,
"location":{
"dimensionRange":{"startIndex":9,"endIndex":10,"dimension":"COLUMNS"},
"locationType":"COLUMN"}}}]}
仍然没有sheetId
我不知道我做错了什么,还是Advanced Sheets Service是否有问题。
Sheets Advanced API已启用,并且已在我的云控制台中打开,并且版本为版本4。
答案 0 :(得分:1)
我可以确认,当 1 1 1 -> 1 1 1 : Good
1 1 2 -> 2 1 1 : Good
1 1 3 -> 3 1 1 : Good
1 2 1 -> 2 1 1 : Good
1 2 2 -> 2 2 1 : Good
1 2 3 -> 3 2 1 : Good
1 3 1 -> 3 1 1 : Good
1 3 2 -> 3 2 1 : Good
1 3 3 -> 3 3 1 : Good
2 1 1 -> 2 1 1 : Good
2 1 2 -> 2 2 1 : Good
2 1 3 -> 3 2 1 : Good
2 2 1 -> 2 2 1 : Good
2 2 2 -> 2 2 2 : Good
2 2 3 -> 3 2 2 : Good
2 3 1 -> 3 2 1 : Good
2 3 2 -> 3 2 2 : Good
2 3 3 -> 3 3 2 : Good
3 1 1 -> 3 1 1 : Good
3 1 2 -> 3 2 1 : Good
3 1 3 -> 3 3 1 : Good
3 2 1 -> 3 2 1 : Good
3 2 2 -> 3 2 2 : Good
3 2 3 -> 3 3 2 : Good
3 3 1 -> 3 3 1 : Good
3 3 2 -> 3 3 2 : Good
3 3 3 -> 3 3 3 : Good
时,它不包含在维度范围内,
但是在处理任何其他工作表(即 sheetId === 0
)时,sheetId 包含在维度范围内.也许是 GAS 方面的错误错误?
我正在使用 PHP 客户端库与 Google Sheets API 进行交互,并且我已经添加了以下内容来暂时解决这个问题。
where it is not 0
最好让 Google 解决这个问题,以免绊倒其他用户。