C# Google Sheets API CopyPasteRequest无效
我只是尝试将一系列单元格从电子表格的第一张表复制到第二张表。这段代码运行时没有错误,但在实际工作表上没有发生任何事情 下面我遗漏了什么C# Google Sheets API CopyPasteRequest无效,c#,google-sheets,google-api,C#,Google Sheets,Google Api,我只是尝试将一系列单元格从电子表格的第一张表复制到第二张表。这段代码运行时没有错误,但在实际工作表上没有发生任何事情 下面我遗漏了什么 var spreadSheet = service.Spreadsheets.Get(spreadsheetId).Execute(); int? sourceSheetId = spreadSheet.Sheets[0].Properties.SheetId; int? targetSheetId = spreadSheet.Sheets[1].Prop
var spreadSheet = service.Spreadsheets.Get(spreadsheetId).Execute();
int? sourceSheetId = spreadSheet.Sheets[0].Properties.SheetId;
int? targetSheetId = spreadSheet.Sheets[1].Properties.SheetId;
// Copy in the current data from the "Training Data" tab
CopyPasteRequest copyReq = new CopyPasteRequest()
{
Source = new GridRange() { SheetId = sourceSheetId, StartColumnIndex = 0,
StartRowIndex = 1, EndColumnIndex = 0, EndRowIndex = 3000 },
Destination = new GridRange() { SheetId = targetSheetId,
StartColumnIndex = 0, StartRowIndex = 1, EndColumnIndex = 0, EndRowIndex = 3000 },
PasteType = "PASTE_VALUES",
PasteOrientation = "NORMAL"
};
var copyResource = new BatchUpdateSpreadsheetRequest() { Requests = new List<Request>() };
var reqCopy = new Request() { CopyPaste = copyReq };
copyResource.Requests.Add(reqCopy);
var result = service.Spreadsheets.BatchUpdate(copyResource, spreadsheetId).Execute();
// no errors, and result object is populated -- but nothing appears in the target sheet
var spreadSheet=service.Spreadsheets.Get(spreadsheetId.Execute();
智力?sourceSheetId=电子表格.Sheets[0].Properties.SheetId;
智力?targetSheetId=电子表格.Sheets[1].Properties.SheetId;
//从“培训数据”选项卡复制当前数据
CopyPasteRequest copyReq=新的CopyPasteRequest()
{
Source=new GridRange(){SheetId=sourceSheetId,StartColumnIndex=0,
StartRowIndex=1,EndColumnIndex=0,EndRowIndex=3000},
Destination=new GridRange(){SheetId=targetSheetId,
StartColumnIndex=0,StartRowIndex=1,EndColumnIndex=0,EndRowIndex=3000},
PasteType=“粘贴值”,
PasteOrientation=“正常”
};
var copyrource=new BatchUpdateSpreadsheetRequest(){Requests=new List()};
var reqCopy=new Request(){CopyPaste=copyReq};
copyResource.Requests.Add(reqCopy);
var result=service.Spreadsheets.BatchUpdate(copyResource,spreadsheetId).Execute();
//没有错误,结果对象被填充——但目标工作表中没有显示任何内容
根据我的理解,您正在尝试将源工作表的A列复制到目标工作表的A列
请求无效的原因是,中的EndColumnIndex
不正确,EndColumnIndex
和EndRowIndex
被排除在要复制的范围之外
endRowIndex
范围的结束行(独占),如果没有边界,则不设置
endColumnIndex
范围的结束列(独占),如果没有边界,则不设置
例子: 我想复制
Sheet1!A1:A10
至表2!A1:A10
请求正文:
{
"requests": [
{
"copyPaste": {
"source": {
"sheetId": 0,
"startRowIndex": 0,
"startColumnIndex": 0,
"endColumnIndex": 1,
"endRowIndex": 10
},
"destination": {
"sheetId": 133812xxxx,
"startRowIndex": 0,
"startColumnIndex": 0,
"endColumnIndex": 1,
"endRowIndex": 10
},
"pasteOrientation": "NORMAL",
"pasteType": "PASTE_NORMAL"
}
}
]
}
- 工作表索引是以零为基础的
设置为1(不包括B列)endColumnIndex
设置为10(不包括第11行)endRowIndex
{
"requests": [
{
"copyPaste": {
"source": {
"sheetId": 0,
"startRowIndex": 0,
"startColumnIndex": 0,
"endColumnIndex": 1,
"endRowIndex": 10
},
"destination": {
"sheetId": 133812xxxx,
"startRowIndex": 0,
"startColumnIndex": 0,
"endColumnIndex": 1,
"endRowIndex": 10
},
"pasteOrientation": "NORMAL",
"pasteType": "PASTE_NORMAL"
}
}
]
}
谢谢!是的,你正确地解释了我的问题,并教会了我需要知道的东西。“end column”和“end row”实际上是指“您不希望包含的第一列或第一行”。我看到文档中怎么说“excluded”--我没有按照他们的意思解释它。很高兴我能提供帮助