对我的列 headers 使用“=TRANSPOSE()”,当我在原始数据中插入新行时如何保持数据链接?
Using "=TRANSPOSE()" for my column headers, how do I keep data linked when I insert a new row in the original data?
我有一个 sheet,这是我的数据,其中列出了我的事件及其日期。然后将它们插入单独的 sheet 中,志愿者可以在其中使用复选框来确定是否有空。现在,如果我在 data-sheet 中重新排序我的事件,那么可用性 sheet 中的 headers 将会移动,但可用性不会随之移动。有任何解决这个问题的方法吗?
这是一个例子sheet:
https://docs.google.com/spreadsheets/d/1tTVMOCKnLT2dRhKDBMV74LNMYOQvxKv3AA8egHCVG78/edit?usp=sharing
这是我的实际问题的简化示例,但我想知道是否有保持此数据链接的好方法?我希望能够 re-order "Events Data" sheet 中的数据,同时在 "Availability sheet" 中的每个事件下保持正确的可用性。目前一动一静
我是如何在类似情况下使用 Google Apps 脚本完成此操作的(在我的例子中,将 "memo" 列与 QUERY
生成的行相关联)。本质上,我们所做的是从静态来源(其他 sheets)合成我们的动态显示(在我的情况下使用 QUERY
,在你的情况下使用 TRANSPOSE
),并使用 Google 应用程序用于将在动态 sheet 上输入的数据移动到适当的静态 sheet 的脚本,我们可以在其中轻松检索它并适当地呈现它。
存储在动态 sheet 上的唯一信息是用于呈现它的信息(TRANSPOSE
、VLOOKUP
,无论您的情况如何)。当用户编辑 sheet 时,我们将获取他们编辑的值并立即使用 onEdit()
将其移动到静态 sheet。来自静态 sheet 的信息随后将呈现到动态 sheet 上,无论其呈现方式如何变化。
首先,创建一个 sheet,您将在其中存储每一行的真实值。
其次,使用 arrayformula
vlookup
(或 hlookup
)根据转置 sheet 中的唯一标识符搜索您的存储 sheet,例如
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, Storage!A2:B, 2, 0), ""))
第三,使用脚本编辑器,将以下内容添加到 Google Apps 脚本中的 onEdit()
函数:
if (/* use e.range here to check that you're in an appropriate location... */) {
//this section should execute on our 'dynamic' sheet, after the user edits it
var unique_id = SpreadsheetApp.getActiveSheet().getRange(e.range.getRow(), 1).getValue();
// the 'getRange' here is looking from where the user edited to a unique identifier
// associated with this record; this could potentially be built on to reference multiple unique identifiers.
// For instance, this would be the cell with the text, e.g., unique_id = 'Event A'
// and the script could be extended to ALSO pick up, e.g. "edited_person", etc.
var storagesheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Storage');
var findid = storagesheet.createTextFinder(unique_id).findNext();
// this will search your storage sheet to see if there is an existing entry associated with the unique ID
if (findid) {
storagesheet.getRange(findid.getRow(), 2, 1, 2).setValues([[e.value, e.user]]);
// if there is, then we update it ON THE STORAGE SHEET with the new contents of the cell
} else {
storagesheet.appendRow([unique_id, e.value, e.user]);
// otherwise, we create one with the contents of the cell.
//This can likewise be expanded; create more cells, update more sheets, create new sheets, whatever else may be needed
}
e.range.clearContent();
if (e.range.getRow() === 2) { //or wherever your array formula is, again we are assuming this part of the onEdit() should only occur for edits of the dynamic sheet
//making sure we don't lose array formula if the user writes in this field
e.range.setFormula("=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, Storage!A2:B, 2, 0), \"\"))")
}
}
这些基于垂直 stored/displayed 信息,并且仅为每个唯一 ID 存储一个字段,但您可以很容易地推断出基于事件和人的值进行匹配,存储多个值对于每个事件等,根据您的需要。
我有一个 sheet,这是我的数据,其中列出了我的事件及其日期。然后将它们插入单独的 sheet 中,志愿者可以在其中使用复选框来确定是否有空。现在,如果我在 data-sheet 中重新排序我的事件,那么可用性 sheet 中的 headers 将会移动,但可用性不会随之移动。有任何解决这个问题的方法吗?
这是一个例子sheet: https://docs.google.com/spreadsheets/d/1tTVMOCKnLT2dRhKDBMV74LNMYOQvxKv3AA8egHCVG78/edit?usp=sharing
这是我的实际问题的简化示例,但我想知道是否有保持此数据链接的好方法?我希望能够 re-order "Events Data" sheet 中的数据,同时在 "Availability sheet" 中的每个事件下保持正确的可用性。目前一动一静
我是如何在类似情况下使用 Google Apps 脚本完成此操作的(在我的例子中,将 "memo" 列与 QUERY
生成的行相关联)。本质上,我们所做的是从静态来源(其他 sheets)合成我们的动态显示(在我的情况下使用 QUERY
,在你的情况下使用 TRANSPOSE
),并使用 Google 应用程序用于将在动态 sheet 上输入的数据移动到适当的静态 sheet 的脚本,我们可以在其中轻松检索它并适当地呈现它。
存储在动态 sheet 上的唯一信息是用于呈现它的信息(TRANSPOSE
、VLOOKUP
,无论您的情况如何)。当用户编辑 sheet 时,我们将获取他们编辑的值并立即使用 onEdit()
将其移动到静态 sheet。来自静态 sheet 的信息随后将呈现到动态 sheet 上,无论其呈现方式如何变化。
首先,创建一个 sheet,您将在其中存储每一行的真实值。
其次,使用 arrayformula
vlookup
(或 hlookup
)根据转置 sheet 中的唯一标识符搜索您的存储 sheet,例如
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, Storage!A2:B, 2, 0), ""))
第三,使用脚本编辑器,将以下内容添加到 Google Apps 脚本中的 onEdit()
函数:
if (/* use e.range here to check that you're in an appropriate location... */) {
//this section should execute on our 'dynamic' sheet, after the user edits it
var unique_id = SpreadsheetApp.getActiveSheet().getRange(e.range.getRow(), 1).getValue();
// the 'getRange' here is looking from where the user edited to a unique identifier
// associated with this record; this could potentially be built on to reference multiple unique identifiers.
// For instance, this would be the cell with the text, e.g., unique_id = 'Event A'
// and the script could be extended to ALSO pick up, e.g. "edited_person", etc.
var storagesheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Storage');
var findid = storagesheet.createTextFinder(unique_id).findNext();
// this will search your storage sheet to see if there is an existing entry associated with the unique ID
if (findid) {
storagesheet.getRange(findid.getRow(), 2, 1, 2).setValues([[e.value, e.user]]);
// if there is, then we update it ON THE STORAGE SHEET with the new contents of the cell
} else {
storagesheet.appendRow([unique_id, e.value, e.user]);
// otherwise, we create one with the contents of the cell.
//This can likewise be expanded; create more cells, update more sheets, create new sheets, whatever else may be needed
}
e.range.clearContent();
if (e.range.getRow() === 2) { //or wherever your array formula is, again we are assuming this part of the onEdit() should only occur for edits of the dynamic sheet
//making sure we don't lose array formula if the user writes in this field
e.range.setFormula("=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, Storage!A2:B, 2, 0), \"\"))")
}
}
这些基于垂直 stored/displayed 信息,并且仅为每个唯一 ID 存储一个字段,但您可以很容易地推断出基于事件和人的值进行匹配,存储多个值对于每个事件等,根据您的需要。