简体   繁体   English

如何将工作表中的所有数据转换为值-Google电子表格

[英]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.

相关问题 如何重命名 Google 电子表格(文件)并使用工作表中的值填充其内容 - How to rename Google spreadsheets (files) and populate their contents with values from a sheet 如何使用新的 Google 电子表格的数据填充特定工作表中的单元格 - How to fill a cell in a specific sheet with data of new Google spreadsheets 如何将数据列表转换为 Google 表格中的表格 - How to transform a list of data into a table on Google Sheet Google电子表格查询语言从许多其他工作表中获取数据 - Google spreadsheets Query Language get data from many other sheet 如何在 Google 表格中获取所有版本的数据? - How to get All versions' data in Google sheet? 检查谷歌电子表格中是否存在工作表 - check for existence of a sheet in google spreadsheets Google Spreadsheets如果源在另一个工作表中,如何插入注释 - Google Spreadsheets How to insert notes if source is in a different sheet 如何在Google Spreadsheets中放置来自其他来源表的笔记 - How to place notes from different source sheet in Google Spreadsheets Google 表格 API V4 - Google Apps 脚本 - Sheets.Spreadsheets.Values.update - append 日期 - Google Sheet API V4 - Google Apps script - Sheets.Spreadsheets.Values.update - append Date Google 电子表格中的数据验证 - Data validation in Google Spreadsheets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM