Xml 如何删除单元格并在Google工作表中重新输入相同的详细信息

Xml 如何删除单元格并在Google工作表中重新输入相同的详细信息,xml,google-apps-script,google-sheets,Xml,Google Apps Script,Google Sheets,我目前正在研究一种自动获取股票价格数据的方法 首先,我认为要更新单元格的值,我只需要刷新单元格中的importxml语句。所以我使用了来自 函数RefreshImports(){ var lock=LockService.getScriptLock(); 如果(!lock.tryLock(5000))返回;//请最多等待5秒,以结束上一次刷新。 //在这一点上,我们持有的锁。 var id=“YOUR-SHEET-id”; var ss=电子表格应用程序openById(id); var she

我目前正在研究一种自动获取股票价格数据的方法

首先,我认为要更新单元格的值,我只需要刷新单元格中的importxml语句。所以我使用了来自

函数RefreshImports(){
var lock=LockService.getScriptLock();
如果(!lock.tryLock(5000))返回;//请最多等待5秒,以结束上一次刷新。
//在这一点上,我们持有的锁。
var id=“YOUR-SHEET-id”;
var ss=电子表格应用程序openById(id);
var sheets=ss.getSheets();

对于(var sheetNum=0;sheetNum,取决于您有多少列,我只需记录一个动作的宏(工具>宏>记录宏),完成后,按照下面问题中给出的答案中的说明自动刷新,不管您希望它多久运行一次


根据您拥有的列数,我只需录制一个动作宏(工具>宏>录制宏),完成后,按照下面问题答案中的说明自动刷新,无论您希望它运行多久


根据您的示例视频,在您的情况下,我认为当单元格“B9”和“B10”的值包含在公式
=IMPORTXML(url,xpath)
url和
xpath
中时,当单元格“B1”的值更改时,公式将刷新。那么,下面的示例脚本如何

示例脚本: 请将以下脚本复制并粘贴到Google电子表格的脚本编辑器中,并运行
myFunction
功能。在此示例脚本中,单元格“B1”的值被
newValue
覆盖

function myFunction() {
  var newValue = "###"; // Please set the new value.
  var sheetName = "Sheet1";  // Please set the sheet name.
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
  sheet.getRange("B1").setValue(newValue);
}
  • 如果上面的脚本没有用,并且当您想在问题中使用脚本时,您可以使用以下脚本。在这种情况下,请根据您的实际情况设置
    var id=“your-SHEET-id”

      function myFunction() {
        var newValue = "###"; // Please set the new value.
        var sheetName = "Sheet1";  // Please set the sheet name.
        var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
        sheet.getRange("B1").setValue(newValue);
        RefreshImports(); // <--- Added
      }
    
参考资料:
  • 相关线程
补充: 在您的回复和共享视频中,下面的示例脚本如何?在本例中,作为一个简单脚本,单元格被清除并再次输入
acen
的值

示例脚本:
根据您的示例视频,在您的情况下,我认为当单元格“B9”和“B10”的值包含在公式
=IMPORTXML(url,xpath)
url
xpath
中时,当单元格“B1”的值更改时,公式将被刷新。那么,下面的示例脚本如何

示例脚本: 请将以下脚本复制并粘贴到Google电子表格的脚本编辑器中,并运行
myFunction
功能。在此示例脚本中,单元格“B1”的值被
newValue
覆盖

function myFunction() {
  var newValue = "###"; // Please set the new value.
  var sheetName = "Sheet1";  // Please set the sheet name.
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
  sheet.getRange("B1").setValue(newValue);
}
  • 如果上面的脚本没有用,并且当您想在问题中使用脚本时,您可以使用以下脚本。在这种情况下,请根据您的实际情况设置
    var id=“your-SHEET-id”

      function myFunction() {
        var newValue = "###"; // Please set the new value.
        var sheetName = "Sheet1";  // Please set the sheet name.
        var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
        sheet.getRange("B1").setValue(newValue);
        RefreshImports(); // <--- Added
      }
    
参考资料:
  • 相关线程
补充: 在您的回复和共享视频中,下面的示例脚本如何?在本例中,作为一个简单脚本,单元格被清除并再次输入
acen
的值

示例脚本:
GetEmCheckEm和BouncEm

top函数允许您选择要跳出的所有单元格。使用control键选择所有单元格,然后运行getThem()

现在可以运行bounceThem(),这些值将消失,然后重新出现

function bounceThem() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const list=sh.getRangeList(JSON.parse(PropertiesService.getScriptProperties().getProperty('mystocks')));
  let data=[];
  list.getRanges().forEach(r=>{data.push(r.getValue());r.setValue('');});
  SpreadsheetApp.flush();
  Utilities.sleep(5000);
  list.getRanges().forEach((r,i)=>{r.setValue(data[i]);});
  SpreadsheetApp.flush();
  ss.toast("Process Complete");
}

我发现这相当于运行,所以我今天早上回来,将它设置为使用setValues()而不是setValue(),现在进行反弹要快得多

function getThem1() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getSheetByName('Sheet1');
  const rgl=sh.getActiveRangeList();
  console.log(sh.getName());
  let rlA=rgl.getRanges().map(function(rg){return rg.getA1Notation();});
  PropertiesService.getScriptProperties().setProperty('mystocks1',JSON.stringify(rlA));//Stored as JSON in property service
  ss.toast("Process Complete");  
}

function checkThem1() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const rangeList=sh.getRangeList(JSON.parse(PropertiesService.getScriptProperties().getProperty('mystocks1')));
  sh.setActiveRangeList(rangeList);
  ss.toast('Process Complete');
}

function bounceThem1() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const list=sh.getRangeList(JSON.parse(PropertiesService.getScriptProperties().getProperty('mystocks1')));
  let data=[];
  list.getRanges().forEach(function(rg){
    let sA=rg.getValues();//the stored array
    data.push(sA);
    let nA=[];//this is the null array to remove data
    sA.forEach(function(r,i){
      nA[i]=[];
      r.forEach(function(c,j){
        nA[i][j]='';
      });
    });
    rg.setValues(nA);//removing data
  });
  SpreadsheetApp.flush();//insure all data is visible on the sheet
  Utilities.sleep(5000);//5 second bounce delay
  list.getRanges().forEach(function(r,i){r.setValues(data[i]);});//Replacing all data as 2d arrays
  SpreadsheetApp.flush();//Making sure data is complete and visible
  ss.toast("Process Complete");
}

获取检查和弹跳

top函数允许您选择要跳出的所有单元格。使用control键选择所有单元格,然后运行getThem()

现在可以运行bounceThem(),这些值将消失,然后重新出现

function bounceThem() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const list=sh.getRangeList(JSON.parse(PropertiesService.getScriptProperties().getProperty('mystocks')));
  let data=[];
  list.getRanges().forEach(r=>{data.push(r.getValue());r.setValue('');});
  SpreadsheetApp.flush();
  Utilities.sleep(5000);
  list.getRanges().forEach((r,i)=>{r.setValue(data[i]);});
  SpreadsheetApp.flush();
  ss.toast("Process Complete");
}

我发现这相当于运行,所以我今天早上回来,将它设置为使用setValues()而不是setValue(),现在进行反弹要快得多

function getThem1() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getSheetByName('Sheet1');
  const rgl=sh.getActiveRangeList();
  console.log(sh.getName());
  let rlA=rgl.getRanges().map(function(rg){return rg.getA1Notation();});
  PropertiesService.getScriptProperties().setProperty('mystocks1',JSON.stringify(rlA));//Stored as JSON in property service
  ss.toast("Process Complete");  
}

function checkThem1() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const rangeList=sh.getRangeList(JSON.parse(PropertiesService.getScriptProperties().getProperty('mystocks1')));
  sh.setActiveRangeList(rangeList);
  ss.toast('Process Complete');
}

function bounceThem1() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const list=sh.getRangeList(JSON.parse(PropertiesService.getScriptProperties().getProperty('mystocks1')));
  let data=[];
  list.getRanges().forEach(function(rg){
    let sA=rg.getValues();//the stored array
    data.push(sA);
    let nA=[];//this is the null array to remove data
    sA.forEach(function(r,i){
      nA[i]=[];
      r.forEach(function(c,j){
        nA[i][j]='';
      });
    });
    rg.setValues(nA);//removing data
  });
  SpreadsheetApp.flush();//insure all data is visible on the sheet
  Utilities.sleep(5000);//5 second bounce delay
  list.getRanges().forEach(function(r,i){r.setValues(data[i]);});//Replacing all data as 2d arrays
  SpreadsheetApp.flush();//Making sure data is complete and visible
  ss.toast("Process Complete");
}

您想删除和替换哪些单元格?您想删除和替换哪些单元格?我已经尝试了您的方法,刷新公式不起作用。对于仅要刷新的importxml,它需要刷新我想刷新的库存的参考单元格get@kalimdor18谢谢您的回复。对于给您带来的不便,我深表歉意回复,我又添加了一个示例脚本。你能确认一下吗?如果这对你的情况没有用,我再次道歉。嘿!!别担心..这对我和将来会看到这个的每个人来说都是一个很好的资源..哦,哇!你给我的新示例脚本非常有魅力!!谢谢你much@kalimdor18感谢谢谢你回复并再次测试。我很高兴你的问题得到了解决。也谢谢你。我已经尝试了你的方法,刷新公式不起作用。对于仅刷新importxml的importxml,它需要刷新我想要刷新的股票的参考单元格get@kalimdor18谢谢你的回复。给你带来的不便我深表歉意。从你的回复中,我又添加了一个示例脚本。你能确认一下吗?如果这对你的情况没有用,我再次道歉。嘿!!别担心..这对我和将来看到这一点的每个人来说都是一个很好的资源..哦,哇!你给我的新示例脚本非常有魅力!!谢谢你much@kalimdor18谢谢你的支持撒谎并再次测试。我很高兴你的问题得到了解决。也谢谢你。heyyy!谢谢@Cooper..你的这种方法奏效了!!!太好了。我喜欢玩弄它。Heyy!谢谢@Cooper..你的这种方法奏效了!!!太好了。我喜欢玩弄它
function getThem1() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getSheetByName('Sheet1');
  const rgl=sh.getActiveRangeList();
  console.log(sh.getName());
  let rlA=rgl.getRanges().map(function(rg){return rg.getA1Notation();});
  PropertiesService.getScriptProperties().setProperty('mystocks1',JSON.stringify(rlA));//Stored as JSON in property service
  ss.toast("Process Complete");  
}

function checkThem1() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const rangeList=sh.getRangeList(JSON.parse(PropertiesService.getScriptProperties().getProperty('mystocks1')));
  sh.setActiveRangeList(rangeList);
  ss.toast('Process Complete');
}

function bounceThem1() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const list=sh.getRangeList(JSON.parse(PropertiesService.getScriptProperties().getProperty('mystocks1')));
  let data=[];
  list.getRanges().forEach(function(rg){
    let sA=rg.getValues();//the stored array
    data.push(sA);
    let nA=[];//this is the null array to remove data
    sA.forEach(function(r,i){
      nA[i]=[];
      r.forEach(function(c,j){
        nA[i][j]='';
      });
    });
    rg.setValues(nA);//removing data
  });
  SpreadsheetApp.flush();//insure all data is visible on the sheet
  Utilities.sleep(5000);//5 second bounce delay
  list.getRanges().forEach(function(r,i){r.setValues(data[i]);});//Replacing all data as 2d arrays
  SpreadsheetApp.flush();//Making sure data is complete and visible
  ss.toast("Process Complete");
}