I am using a solution given here to copy sheets while maintaining the protection. I have added the Google Sheets API - V4 with name Sheets.
However, it throws error -
GoogleJsonResponseException: API call to sheets.spreadsheets.batchUpdate failed with error: Invalid requests[0].addProtectedRange: The range you're trying to exclude must be within "A".
After Some trial and error I found that because my protection is whole sheet except some ranges, it gives error. When I protect only few ranges, the code works fine.
Now the solution here does duplicate sheet with the whole sheet protection. However, it's for single sheet. I need to combine these two but I am struggling.
The sheet object returned by copyTo() and Sheets.Spreadsheets.get(id) are different, the second one does not have protect() method. So I do not have a specific error here, but need solution directed towards combining two solutions. I need to duplicate multiple sheets while maintaining whole sheet protection without some ranges.