Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
869 views
in Technique[技术] by (71.8m points)

google apps script - Paste Special Values

I have a range consisting of 3 columns and 2 (or more) rows. The middle column contains a formula: =TRANSPOSE(SPLIT(A1,","))

The script needs to move (cut) that range onto another sheet as values, not formulas.

Does google-apps-script have a means of doing "PasteSpecial - Values"?

Here is the line I'm currently using:

sheet1.getRange("F1:H3").moveTo(sheet2.getRange("A1")); 

Can anyone tell me how I can lock those values in before they move onto sheet2 ?

(FYI: this requires a code solution only)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just as an alternative, you can use copyTo() with advanced arguments to copy values only. To mimic the effect of moveTo(), you would still need to clear the source range.

Also, if it's easier, getRange() accepts a string reference that includes the sheet name. So:

function moveValuesOnly() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var source = ss.getRange('Sheet1!F1:H3');
  source.copyTo(ss.getRange('Sheet2!A1'), {contentsOnly: true});
  source.clear();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...