Java Question

Find and replace a value in google sheet via Java API V4

I would like to find a value and replace it to another value in google sheet using the Java API.

This is my code, but it only changes the value upon the index and column I refer to it.

requests.add(new Request()
.setCopyPaste(new CopyPasteRequest()
.setSource(new GridRange()
.setSheetId(0)
.setStartRowIndex(0)
.setEndRowIndex(1)
.setStartColumnIndex(0)
.setEndColumnIndex(3))
.setDestination(new GridRange()
.setSheetId(0)
.setStartRowIndex(1)
.setEndRowIndex(6)
.setStartColumnIndex(0)
.setEndColumnIndex(3))
.setPasteType("PASTE_FORMAT")));
BatchUpdateSpreadsheetRequest batchUpdateRequest = new BatchUpdateSpreadsheetRequest()
.setRequests(requests);

Answer

You can create a FindReplaceRequest() to do this

        requests.add(new Request().setFindReplace(new FindReplaceRequest().setFind(entry.getKey())
                .setMatchEntireCell(true)
                .setMatchCase(true)
                .setReplacement(entry.getValue())
                .setRange(new GridRange()
                        .setSheetId(0)
                        .setStartRowIndex(row)
                        .setEndRowIndex(row + 1))));
    }



    String cellReq = (new FindReplaceRequest().setFind("samuel")).getFind();
Comments