简体   繁体   English

使用 googe 应用程序脚本从电子表格中的所有工作表中提取数据

[英]extract data from all sheets in a spreadsheet with googe apps script

I am trying to extract all the data from different sheets that I have in a spreadsheet, but I am facing errors while trying to do it, I am not very familiar with JS if anyone out there can help me out.我正在尝试从电子表格中的不同工作表中提取所有数据,但是在尝试执行此操作时遇到错误,如果有人可以帮助我,我对 JS 不是很熟悉。

function getData(s){

    const ss = SpreadsheetApp.getActiveSpreadsheet();
    const ws = ss.getSheetByName(s);
    const data = ws.getRange("A1").getDataRegion().getValues();
    const headers = data.shift();
    const jsonArray = data.map(r =>{
      let obj = {};
      headers.forEach((h, i) => {
        obj[h] = r[i]
      });
      return obj
  })
  const res = {'sheets': jsonArray} 
  }

function getDo(){

  var sheetsN = ['check1', 'check2', 'check3', 'check4', 'check5']

  for ( var s=0; s<sheetsN.length; s++) {
    dataAll = getData(console.log(sheetsN[s]))
  }
  return ContentService.createTextOutput(JSON.stringify(dataAll))
  .setMimeType(ContentService.MimeType.JSON)
}

getDo()

Get all data in all sheets in a spreadsheet获取电子表格中所有工作表中的所有数据

function getAllData() {
  const ss = SpreadsheetApp.getActive();
  let obj = {}
  ss.getSheets().forEach(sh => {
    obj[sh.getName()] = sh.getDataRange().getValues();
  })
  //Logger.log(JSON.stringify(obj));
  return obj;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从电子表格更新数据-Apps脚本 - Update data from a Spreadsheet - Apps Script 如何从 object API 响应应用程序脚本 goole 表中提取数据 - How to extract data from an object API response Apps script goole sheets Google Apps 脚本 - 将 gmail 中的数据提取到电子表格中 - Google Apps Scripts - Extract data from gmail into a spreadsheet 如何在电子表格文件中的所有工作表上运行 Google Apps 脚本? - How do I run a Google Apps script on all sheets in my spreadsheet file? 是否可以设置一个范围以从单个电子表格中的所有工作表中获取数据? - Is there a way to set a range to get data from all the sheets in a single spreadsheet? 谷歌应用程序脚本html选择从电子表格数据加载的选项 - google apps script html select options loaded from spreadsheet data 使用Google Apps脚本作为服务从电子表格中检索数据 - Using Google Apps Script as service to retrieve data from spreadsheet 如何使用 Google Apps 脚本访问外部电子表格中的数据 - How to access data from an external spreadsheet with Google Apps Script 使用 Google 表格中的数据在 Google Apps 脚本中自动完成 - Autocomplete in Google Apps Script with data from Google Sheets Google Sheets / Apps Script:在特定文件夹中创建新电子表格的功能 - Google Sheets / Apps Script: Function to create a new spreadsheet in specific folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM