[英]How to transform all data in sheet to values - google spreadsheets
I was trying to find a solution for the following: 我正在尝试寻找以下解决方案:
There are several sheets where the formulas are used. 在几页中使用了公式。 The data from these sheets is copied manually into a single "Archive" sheet at the end of the day.
这些工作表中的数据将在一天结束时手动复制到单个“存档”工作表中。 The data in "Archive" should be pasted as values only.
“归档”中的数据应仅粘贴为值。 Instead of copy paste as values every time, I was trying to automatize this procedure.
我没有每次都将粘贴复制为值,而是尝试自动执行此过程。
What is the script for transforming automatically the data pasted into "Archive" in values? 用于自动转换粘贴到“归档”值中的数据的脚本是什么? It would also be great to have a button to trigger this script.
如果有一个按钮来触发该脚本,那也很好。
Can anyone help? 有人可以帮忙吗?
Thank you very much 非常感谢你
To give a global logic. 给出全局逻辑。 You should probably look these methods.
您可能应该看一下这些方法。
SpreadsheetApp.Spreadsheet.Sheet.Range.getValues();
and 和
SpreadsheetApp.Spreadsheet.Sheet.Range.setValues();
If my I'm not mistaken, this functions should get your datas in 2D Array. 如果我没记错的话,此函数应将您的数据保存在2D数组中。 Then paste Them as String in your spreadsheet.
然后将它们作为String粘贴到电子表格中。
Cheers 干杯
I'm pretty sure this has been answered already but since I didn't find it rapidly, I wrote a small example of one of the possible ways to achieve that result : (see comments in code) 我很确定这已经得到了回答,但是由于我没有迅速找到它,所以我写了一个小例子来说明实现该结果的一种可能方法:(请参见代码中的注释)
function createArchive(){
var currentSheet = SpreadsheetApp.getActive().getActiveSheet();// get current sheet object
var archive = SpreadsheetApp.getActive().copy('archive of '+currentSheet.getName()).getSheets()[0]; // create a copy and get its first sheet
var content = currentSheet.getDataRange().getValues();// get the values of the whole current sheet
archive.getRange(1,1,content.length,content[0].length).setValues(content);// and "paste" it in the copy while preserving initial format (font, colors, borders etc.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.