从mongodb shell安全写入(Safe write from the mongodb shell)
如何从javascript立即刷新到磁盘的“安全”写入? 我希望能够从shell和存储的javascript“CRUD”程序中执行此操作。 这只是一个问题:
db.foo.insert({stuff: "yes", meta: "physics"}); db.runCommand( "getlasterror" ) ;
维基对此不清楚。
How do I do a "safe" write that flushes to disk immediately from javascript? I'd like to be able to do this from both the shell and a stored javascript "CRUD" procedure. Is it just a matter of:
db.foo.insert({stuff: "yes", meta: "physics"}); db.runCommand( "getlasterror" ) ;
The wiki is unclear on this.
原文:https://stackoverflow.com/questions/3605427
最满意答案
您需要更改if语句。 它应该是“===”而不是“==”。 这背后有一个很好的解释。
这是您可以使用的最终脚本
function onEdit(e) { var sourceSheet = "Raw Data"; var columnNumberToWatch = 17; // column A = 1, B = 2, etc. var valueToWatch = ["Full", "Partial", "Process", "Conditional", "Fail", "Exemption"]; var ss = SpreadsheetApp.getActiveSpreadsheet(); var range = e.range; var activesheet = range.getSheet(); var activesheetname = activesheet.getName(); var row = range.getRow(); var value = ss.getSheetByName(sourceSheet).getRange(row, columnNumberToWatch).getValue(); if (activesheetname === sourceSheet && valueToWatch.indexOf(value) >=0) { var targetSheet = ss.getSheetByName(value + " Certification"); var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1); activesheet.getRange(row, 1, 1, activesheet.getLastColumn()).moveTo(targetRange); activesheet.deleteRow(row); } }
更新如果不手动编辑单元格,则无法在第二个电子表格上运行脚本。 一旦在第二个电子表格中从第一个电子表格推送该行,它将不会在第二个电子表格中触发onEdit函数。 您可以做的是将其设置为从第一个电子表格中将行分配到正确的表格,如下所示
//This is part of a script on the first spreadsheet if (valueToWatch.indexOf(value) >=0) { var targetSheetName = value + " Certification"; } else { var targetSheetName = "Raw Data"; } var targetSheet = SpreadsheetApp.openById("1bjLKWXUwM6UE4SHz2pbhH3F1E-8GKtvV0870YetOpKo").getSheetByName(targetSheetName); var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1,1,activesheet.getLastColumn()); targetRange.setValues(activesheet.getRange(row, 1, 1, activesheet.getLastColumn()).getValues()); activesheet.deleteRow(row); }
You need to change your if statement. It should be "===" instead of "==". Here is a good explanation behind this.
Here is the final script that you can use
function onEdit(e) { var sourceSheet = "Raw Data"; var columnNumberToWatch = 17; // column A = 1, B = 2, etc. var valueToWatch = ["Full", "Partial", "Process", "Conditional", "Fail", "Exemption"]; var ss = SpreadsheetApp.getActiveSpreadsheet(); var range = e.range; var activesheet = range.getSheet(); var activesheetname = activesheet.getName(); var row = range.getRow(); var value = ss.getSheetByName(sourceSheet).getRange(row, columnNumberToWatch).getValue(); if (activesheetname === sourceSheet && valueToWatch.indexOf(value) >=0) { var targetSheet = ss.getSheetByName(value + " Certification"); var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1); activesheet.getRange(row, 1, 1, activesheet.getLastColumn()).moveTo(targetRange); activesheet.deleteRow(row); } }
Update You cannot make a script run on the second spreadsheet without manually editing a cell. Once the row gets pushed from first spreadsheet in two second, it will not trigger the onEdit function in the second spreadsheet. What you could do is set it to allocate the row to correct sheet from the first spreadsheet with something like this
//This is part of a script on the first spreadsheet if (valueToWatch.indexOf(value) >=0) { var targetSheetName = value + " Certification"; } else { var targetSheetName = "Raw Data"; } var targetSheet = SpreadsheetApp.openById("1bjLKWXUwM6UE4SHz2pbhH3F1E-8GKtvV0870YetOpKo").getSheetByName(targetSheetName); var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1,1,activesheet.getLastColumn()); targetRange.setValues(activesheet.getRange(row, 1, 1, activesheet.getLastColumn()).getValues()); activesheet.deleteRow(row); }
相关问答
更多-
您需要使用For Each sh In ActiveWorkbook.Worksheets sh工作表对象限定使用的Range 。 For Each sh In ActiveWorkbook.Worksheets循环中。 请尝试以下代码: Dim sh As Worksheet For Each sh In ThisWorkbook.Worksheets With sh .Range("$F$5") = "toothwidth" ' Key contact .Ran ...
-
Excel 2013 - “移动到另一张表”的微型图表错误?(Excel 2013 - Miniature chart bug on “move to another sheet”?)[2022-02-19]
问题是由于PRINTER DRIVERS(!)未能应对这些“Chartsheets”而产生的。 我没有一个如何发生这种情况的线索,但如果人们遇到这样的问题,唯一能解决问题的是如果你不打印任何东西也要更换打印机。 在这种情况下我的是Microsoft XPS Document Writer,我把它改成了.pdf打印机。 The problem was generated by a failure of PRINTER DRIVERS (!) to cope with those "Chartsheets". ... -
而不是你的: salesData.Copy Destination:=targetRng 尝试使用以下代码: Private Sub CommandButton2_Click() 'here the beginning of of your solution 'after and instead of this line: 'salesData.Copy Destination:=targetRng 'try this... but carefully for the first time :) ta ...
-
使用INDEX(): =INDEX(Sheet2!A:A,H1) Use INDEX(): =INDEX(Sheet2!A:A,H1)
-
您需要更改if语句。 它应该是“===”而不是“==”。 这背后有一个很好的解释。 这是您可以使用的最终脚本 function onEdit(e) { var sourceSheet = "Raw Data"; var columnNumberToWatch = 17; // column A = 1, B = 2, etc. var valueToWatch = ["Full", "Partial", "Process", "Conditional", "Fail", "Exemption"] ...
-
您可以使用一组值来过滤范围,剪切过滤范围并将其移动到另一个工作表。 BUt这种模式更容易实现。 使用Collection来存储要匹配的值 迭代要匹配的行注意:删除/剪切时始终将最后一个元素转到第一个元素 使用Entirerow.Cut目标:=目的地剪切/移动匹配行 Sub MatchValues() Application.Calculation = xlCalculationManual Application.ScreenUpdating = False Dim c As Ran ...
-
也许这可以帮到你。 编辑。 来自JimmyPenna的 IsInArray函数。 链接在这里 。 Sub remDup() Dim LR As Long, LRSheet2 As Long, i As Long, a As Long Dim vAllSheet2Values() As Variant LRSheet2 = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row LR = Worksheets("Sheet1").Cells(Rows. ...
-
尝试下面的代码,但有两个例外: 1.将“ VlookRes ”修改为您的图纸名称 - 您想要的结果。 2.您在A列中有合并单元格 (根据上传的图片),您正在合并第2行,直到A列中的第6行,这意味着单元格A3的值将为0 。 如果您希望从第三行读取值,请从第3行开始合并(并立即为列A中的下一个值)。 Option Explicit Sub test3() 'Vlookuping on Column N Dim ShtPlan As Worksheet Dim ActSht As Work ...
-
你想要INDEX / MATCH / MATCH: =INDEX(Sheet2!$A:$C,MATCH(A2,Sheet2!$A:$A,0),MATCH(B2,Sheet2!$1:$1,0)) Sheet2供参考: You want INDEX/MATCH/MATCH: =INDEX(Sheet2!$A:$C,MATCH(A2,Sheet2!$A:$A,0),MATCH(B2,Sheet2!$1:$1,0)) Sheet2 for reference:
-
如果整行包含指定的单词,则将整行移动到另一张表(Move an entire row to another sheet if it contains a specified word)[2022-01-31]
这有用吗? Sub DoIt() Dim i As Worksheet, e As Worksheet Dim d, j Set i = Sheets("Output 1") Set e = Sheets("Applications") d = 1 j = 2 Do Until IsEmpty(i.Range("B" & j)) If i.Range("B" & j) = "Processing" Then ...