Copy Range content(value,form,validation,...) to another Range by using C# google sheets

Viewed 43

I am looking at how to copy all the content(values,formulas,format,datavalidations,...) of a range to another range inside the same sheet. I am making a C# progamme to access spreadsheet. This is an example of what i want to realise : enter image description here

enter image description here This is an example of code I see somewhere, it approaches my problem the most, I am looking for more explication on how I can resolve my issue with this :

// Create Google Sheets API service.
var service = new SheetsService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = ApplicationName,
});

// Define request parameters.
String spreadsheetId = "<ID>";

SpreadsheetsResource.GetRequest request =
        service.Spreadsheets.Get(spreadsheetId);
request.Ranges = "G16";
request.IncludeGridData = true;

Spreadsheet response = request.Execute();
CellData Cell1 = response.Sheets[0].Data[0].RowData[0].Values;

//get sheet id by sheet name
Spreadsheet spr = service.Spreadsheets.Get(spreadsheetId).Execute();
Sheet sh = spr.Sheets[0];
int sheetId = (int)sh.Properties.SheetId;

BatchUpdateSpreadsheetRequest bussr = new BatchUpdateSpreadsheetRequest();

//create the update request for cells from the first row
var update = new Request()
{
    RepeatCell = new RepeatCellRequest()
    {
        Range = new GridRange()
        {
            SheetId = sheetId,
            StartColumnIndex = 6,
            StartRowIndex = 13,
            EndColumnIndex = 7,
            EndRowIndex = 14
        },
        Cell = Cell1,
        Fields = "UserEnteredFormat"
    }
};
bussr.Requests = new List<Request>();
bussr.Requests.Add(update);
var bur = service.Spreadsheets.BatchUpdate(bussr, spreadsheetId);
bur.Execute();

0 Answers
Related