1

Thank you for reading it :) Im using Blazor server and Google.Apis.Sheets.v4. I am trying to delete columns in a sheet with this code:

serviceSheet = new SheetsService(new Google.Apis.Services.BaseClientService.Initializer()
{
     HttpClientInitializer = credentialSheet,
     ApplicationName = ApplicitionNameSheet
});

 

public void DelteColumns(string ID, int start, int end)
    {
       
        Request RequestBody = new Request()
        {
            DeleteDimension = new DeleteDimensionRequest()
            {
                Range = new DimensionRange()
                {
                    SheetId = 0,
                    Dimension = "COLUMNS",
                    StartIndex = start,
                    EndIndex = end
                }
            }
        };

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

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

        SpreadsheetsResource.BatchUpdateRequest Deletion = new SpreadsheetsResource.BatchUpdateRequest(serviceSheet, DeleteRequest, ID);
        Deletion.Execute();
    }

But for this I need SheetID for DeleteDimensionRequest. I have only 1 sheet in the spreadsheet, but his SheetID isnt 0. And I get error that there is no grid with index 0. I could not find a way to get the SheetId. Could you please help me? Maybe you can give me at least direction in which I can google :)

1 Answers1

1

I'm not familiar with the API, but maybe I can help you.

You first need to get the Spreadsheet object. Probably using SpreadsheetResource.Get(...) method.

Then you can use Spreadsheet.Sheets property to access individual sheets.

Then access the sheet properties: SheetProperties.SheetId

spreadsheet.Sheets[0].Properties.SheetId

If you need to find the spreadsheetId, check this documentation

Ark-kun
  • 6,358
  • 2
  • 34
  • 70