Google Sheets API v4点网删除行 [英] Google Sheets API v4 dot Net Deleting a row

查看:85
本文介绍了Google Sheets API v4点网删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个界面来与Google表格配合使用.它的工作方式是将电子表格中的所有记录都拉到界面上的网格视图中.然后,该界面上会有一个按钮,提供诸如编辑",删除"等选项.

I am building an interface to tie in with Google Sheets. The way it works is all of the records from a spreadsheet are pulled into a grid view on my interface. There is then a button on this interface offering options such as Edit, Delete, etc.

我的删除方法遇到麻烦.它的工作方式是将我所有的记录都放入方法中,然后使用for循环遍历结果并将ID字段与结果进行比较,并将其与传递给该方法的ID进行比较.如果存在匹配项,则将其删除.所有这些工作正常,一切顺利,但是由于某种原因,该记录并未从我的Google工作表中删除.以下是我的Google Sheets API v4的点NET包装器的代码.如果有人可以帮助我,将不胜感激.我一直在盯着文档,将其他语言的各个部分拼凑在一起已经有几个小时了,我的大脑并没有想出任何新东西,哈哈.

I am having trouble with my delete method. The way it works is all of my records are pulled in to the method which then uses a for loop to go through the results and compare the ID field from the result to the ID that is passed into the method. When there is a match, that is the one to be deleted. All of this works and everything goes off smoothly, but for some reason, the record is not deleted from my google sheet. Below is my code for the dot NET wrapper of Google Sheets API v4. If anyone can help me it would be greatly appreciated. I've been staring at documentation and piecing together parts of other languages for a couple of hours now and my brain isn't coming up with anything new, lol.

if (ID.ToString() == WHVACRMembers[i][0].ToString()) // IF INCOMING ID MATCHES ID OF CURRENT ROW BEING LOOPED OVER
{
    //DELETE THIS ROW
    Request RequestBody = new Request() { 
        DeleteDimension = new DeleteDimensionRequest() { 
            Range = new DimensionRange() { 
                SheetId = 0, 
                Dimension = "ROWS", 
                StartIndex = Convert.ToInt32(i), 
                EndIndex = Convert.ToInt32(i) 
            } 
        } 
    };

    List<Request> RequestContainer = new List<Request>();
    RequestContainer.Add(RequestBody);

    BatchUpdateSpreadsheetRequest DeleteRequest = new BatchUpdateSpreadsheetRequest();
    DeleteRequest.Requests = RequestContainer;

    service.Spreadsheets.BatchUpdate(DeleteRequest, SpreadsheetID);

}

推荐答案

我刚刚发现了问题所在.代替:

I just figured out the problem. Instead of:

service.Spreadsheets.BatchUpdate(DeleteRequest, SpreadsheetID);

我需要:

SpreadsheetsResource.BatchUpdateRequest Deletion = new SpreadsheetsResource.BatchUpdateRequest(service, DeleteRequest, SpreadsheetID);
Deletion.Execute();

一想到这一切,一切就顺利进行了.我只是在浏览文档和对象资源管理器时没有专注于正确的事情.

As soon as I figured that out, everything went through without a hitch. Was just a matter of me not being focused on the right thing while looking through the documentation and object explorer.

这篇关于Google Sheets API v4点网删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆