甚至可以使用脚本将数据从一张纸复制到另一张纸吗? ImportRange样式?
我已经搜索了2天,似乎找不到答案,或者没有人正在做类似的事情.我试图用脚本将我的员工表移到我的主表"上.我需要在单元格中保留格式和注释.
Ive searched for 2 days, can't seem to find the answer or anyone that is even doing something kinda like this. I am trying to bring my employees sheets over to my "Master sheet" with a script. I need to keep the formatting and the notes in the cells.
我能找到的最好的办法是打开他们的电子表格并将其复制到我的主服务器上,但是对于8名员工来说,如果我需要每天多次执行此操作会很痛苦.我只想构建一个函数,可以从主表"运行脚本并将其覆盖其选项卡中的最后一个数据.但是我希望能够在我的母版表格中执行此操作.我是所有床单的所有者,但这变得很痛苦.
Best I can find is I can open their spread sheets and copy it to my master, but for 8 employees this will be a pain if I need to do this multiple times a day. I would like to just build a function that I can run my script from the "master sheet" and have it write over the last data in their tab. But I want to be able to do this from within my master sheet. I am the owner of all the sheets but this is becoming a pain.
function copyCell() {
var os = SpreadsheetApp.openById('1n4iFXGuC7yG1XC-UIbuT9VrQ7rJWngPkDCv0vsvDed4');
var sheets = os.getSheets();
var existingNote;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var jobnumber = sheets.getRange("C2:C").getValues();
for (var i = 0; i < jobnumber.length; i++)
if (jobnumber[i][0] == sheets){
existingNote = sheets.getRange("C" + (i+2)).getNote();
sheets.getRange("C" + (i+2)).ss.setNote(existingNote);
}
};
请让我知道是否有可能,并可能引用一个我认为能够对其进行修改以适应我的需求的脚本.感谢您的帮助.
Someone please let me know if it is possible and maybe reference a script I can see to be able to modify to fit my needs. Thanks for any help.
这是复制与一系列单元格关联的注释的可能解决方案.并将它们粘贴到大小相似的单元格上.
This is a possible solution for copying the notes associated with a range of cells. And pasting them onto a similar-sized range of cells.
要复制注释,可以使用getNotes()
. 此处的文档.
To copy the notes you can use getNotes()
. Docs here.
要粘贴注释,可以使用setNotes()
. 此处的文档.
To paste the notes you can use setNotes()
. Docs here.
如果您需要将其添加到脚本中,那么本文档中的示例代码非常不错.
Ths sample code in this documentation is pretty good if you need to add it into your script.
如果您有一个脚本,希望与他人分享,以帮助您使其正常工作.
If you have a script you'd like to share am happy to help you make it work properly.
修改
类似这样的东西:
function transferNotes() {
// Get notes (not comments) from the source spreadsheet
var sourceSpreadheet = SpreadsheetApp.openById('ID_of_source_spreadsheet');
var sourceTab = sourceSpreadheet.getSheetByName('Name_source_tab');
var sourceRange = sourceTab.getRange('Source_range_address'); // e.g. "A:D"
var notes = sourceRange.getNotes();
// Post the notes to the target spreadsheet
var targetSpreadheet = SpreadsheetApp.openById('ID_of_target_spreadsheet');
var targetTab = targetSpreadheet.getSheetByName('Name_target_tab');
var targetRange = targetTab.getRange('Target_range_address'); // Should be the same dimensions as sourceRange
targetRange.setNotes(notes);
}