我想通过 Docs API 发出 InsertTableRow 请求,它需要一个 TableStartLocation。 我用过
var tableName = table[0];
foreach (var element in document.Body.Content)
if (element.Table != null)
{
var checkTable = element.Table.TableRows[0].TableCells[0].Content[0].Paragraph.Elements[0]
.TextRun.Content.TrimEnd('\n'); //Get Text Value in first cell of the table
if (tableName.Equals(checkTable)) // Check if the table is the table that I want to add rows
{
Console.WriteLine("Add Table Row");
TableUpdateRequest(ref requests, table, element.StartIndex); // Using element(StructuralElement) to get StartIndex
break;
}
}
要查找文档中的所有表格并尝试使用 element.StartIndex
作为表格起始位置,但我得到:Google.GoogleApiException : Google.Apis.Requests.RequestError Invalid requests[ 5].insertTableRow:无效的表开始位置。必须指定表的起始索引。 [400]
Table Start Location 的合适索引是什么?
最佳答案
tableStartLocation
是识别正确表所必需的
检索它的方法是例如与 documents.get .要缩小结果范围,您可以指定 fields
,例如正文/内容(startIndex,表格)
。
这将返回给你一个类型的资源
{
"body": {
"content": [
{},
{
"startIndex": 1
},
{
"startIndex": 2,
"table": {
"rows": 4,
"columns": 3,
"tableRows": [
{
...
换句话说:您现在知道您的 tableStartLocation
是 2
- 与表的 startIndex 相同。
示例
var resource = { "requests": [
{
"insertTableRow": {
"tableCellLocation": {
"tableStartLocation": {
"index": 2
}
},
"insertBelow": false
}
}
]
}
Docs.Documents.batchUpdate(resource, documentId);
现在,根据您的文档,您可能有多个表,并且可能想要比较名称等,然后再决定哪个是正确 able 的起始索引。
关于javascript - 使用 Google Docs API 查找表开始位置索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62768028/